From patchwork Tue Jan 24 21:06:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 719418 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3v7LNz1tzjz9srY for ; Wed, 25 Jan 2017 08:07:47 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=networkplumber-org.20150623.gappssmtp.com header.i=@networkplumber-org.20150623.gappssmtp.com header.b="Aggk4EwX"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751065AbdAXVHm (ORCPT ); Tue, 24 Jan 2017 16:07:42 -0500 Received: from mail-pf0-f179.google.com ([209.85.192.179]:33816 "EHLO mail-pf0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750854AbdAXVG7 (ORCPT ); Tue, 24 Jan 2017 16:06:59 -0500 Received: by mail-pf0-f179.google.com with SMTP id e4so52411857pfg.1 for ; Tue, 24 Jan 2017 13:06:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=TY+Ig+VnotiHLEEanPdioalgReQ10it4MmSHpJfm+AY=; b=Aggk4EwX5MVEGYPzHu8vPxbsHCEeEfpqhrlsyySM52VFKVKlyawISGHULS0FDAZDHQ SMTlofE0yA5yuriJ/ATvFsRQUG6+09Ee0wZDoKaT9ERqrOwMeY/NAClFBNcxkjxJmm0S dLvONi2hLhN1GIFbW4HEdjCC6YPjNB8loiDcXKa7igEZ9n5ZgtJkrq0uQ2HYAf5OgBwt hgQao9o0eSFU7qriDvOFyvB97wq6YDOIYoxLM7LoOVPhzGGyvoYMS/Rze/iFFJPQZJaP EIJ/I0MYH8vO8rbYVLDJ/cb46D4NQCCWWUHCNcF2nKAY4pA9DG7f2C/KPI5g6hmwgFyP Nm5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=TY+Ig+VnotiHLEEanPdioalgReQ10it4MmSHpJfm+AY=; b=V6lLg2wWjFgUcevJ51M6b32mq6OxVqvGm+LOgKKVElZIBTpVNbTfBHED9Z0t4DOJ71 w2cYO+wwT1ORZLF+jbIULfG1W72P9Q3fJDU13kf8ethRaiXiAsGigcveBcKWHSmsWoOW Dgek2bUly3yOgFIK1jTrz3sK/+jEpFyin3Urb7cTVkraW0r/UOOhDQpW7CaMlF1/zmXj I6R0veFZ7SZvQjC5mSWVxOsTip7tdcemxumc/HJxh+WQ3ZHlXa6VQetQex66el+NUVeO DDdSV4OKVvq8Io3OYE8NBbMtsLYxoz0FR38JmKuqbj/VfyBTGAl/H0T4SWOvlduT5vE5 qOFw== X-Gm-Message-State: AIkVDXL8jwV6lPij1DkXZDNtgjpu1NfsiHGqHikTEs/MhaNZeYc3dD5kQz6g2txZNidKdg== X-Received: by 10.99.39.71 with SMTP id n68mr42420702pgn.85.1485291995482; Tue, 24 Jan 2017 13:06:35 -0800 (PST) Received: from xeon-e3.wavecable.com (204-195-18-65.wavecable.com. [204.195.18.65]) by smtp.gmail.com with ESMTPSA id k76sm46850212pfg.42.2017.01.24.13.06.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Jan 2017 13:06:34 -0800 (PST) From: Stephen Hemminger X-Google-Original-From: Stephen Hemminger To: davem@davemloft.net, kys@microsoft.com Cc: netdev@vger.kernel.org, Stephen Hemminger Subject: [PATCH 17/18] netvsc: simplify get next send section Date: Tue, 24 Jan 2017 13:06:14 -0800 Message-Id: <20170124210615.18628-18-sthemmin@microsoft.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170124210615.18628-1-sthemmin@microsoft.com> References: <20170124210615.18628-1-sthemmin@microsoft.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use kernel for_each_clear_bit macro to simplify finding next available send section. Signed-off-by: Stephen Hemminger --- drivers/net/hyperv/netvsc.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c index c70c4ac77b74..5cfdb1a1b4c1 100644 --- a/drivers/net/hyperv/netvsc.c +++ b/drivers/net/hyperv/netvsc.c @@ -680,27 +680,15 @@ static void netvsc_send_completion(struct netvsc_device *net_device, static u32 netvsc_get_next_send_section(struct netvsc_device *net_device) { - unsigned long index; - u32 max_words = net_device->map_words; - unsigned long *map_addr = (unsigned long *)net_device->send_section_map; - u32 section_cnt = net_device->send_section_cnt; - int ret_val = NETVSC_INVALID_INDEX; - int i; - int prev_val; - - for (i = 0; i < max_words; i++) { - if (!~(map_addr[i])) - continue; - index = ffz(map_addr[i]); - prev_val = sync_test_and_set_bit(index, &map_addr[i]); - if (prev_val) - continue; - if ((index + (i * BITS_PER_LONG)) >= section_cnt) - break; - ret_val = (index + (i * BITS_PER_LONG)); - break; + unsigned long *map_addr = net_device->send_section_map; + unsigned int i; + + for_each_clear_bit(i, map_addr, net_device->map_words) { + if (sync_test_and_set_bit(i, map_addr) == 0) + return i; } - return ret_val; + + return NETVSC_INVALID_INDEX; } static u32 netvsc_copy_to_send_buf(struct netvsc_device *net_device,