From patchwork Mon Nov 14 11:28:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13042163 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16878C433FE for ; Mon, 14 Nov 2022 11:29:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236211AbiKNL3O (ORCPT ); Mon, 14 Nov 2022 06:29:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235709AbiKNL2p (ORCPT ); Mon, 14 Nov 2022 06:28:45 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 099E922F; Mon, 14 Nov 2022 03:28:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668425303; x=1699961303; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=gR6BZJ2tZuQtMsb7/ERq8PsqpuT7Uc3t1sGvFFJF/U0=; b=IU24lA4i6wHniVfKS1NCOlv0T6fw25/avpuwt+CYLSfS6czNFQFTyeIL aQqM1l8dhVGCgZ/LMC9JrHVirIsjs2ZLMSpHT9fGyxGxWqDAX/36wup2X UXP4rLylsR4fpVhh4mDjaEYAJezLPmcDHx8TeN+6OdKFB775AAuQBBZe1 FlgoKAEgciQmU6+lBYcAE7trLi/PxH+vJpP6VKpC3i6cY6kqWtNe8NOH/ 6eS+Jt7LudF60cJqj/cOv1abJuQNYU0S7edSCDc2ufM2KpLYkle82MeK5 FpLU1oZGhyI1n1OgfwqZe+8KDJQulgcW7Xw0S8U3oPSxFwHfoph14v/Cp g==; X-IronPort-AV: E=McAfee;i="6500,9779,10530"; a="292344098" X-IronPort-AV: E=Sophos;i="5.96,161,1665471600"; d="scan'208";a="292344098" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Nov 2022 03:28:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10530"; a="589332578" X-IronPort-AV: E=Sophos;i="5.96,161,1665471600"; d="scan'208";a="589332578" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga003.jf.intel.com with ESMTP; 14 Nov 2022 03:28:19 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 2587D32E; Mon, 14 Nov 2022 13:28:43 +0200 (EET) From: Andy Shevchenko To: Jakob Koschel , Andy Shevchenko , Greg Kroah-Hartman , Mathias Nyman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kevin Cernekee , Mathias Nyman , Andrew Morton Subject: [PATCH v1 1/4] list: Introduce list_count() to count existing nodes Date: Mon, 14 Nov 2022 13:28:39 +0200 Message-Id: <20221114112842.38565-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Some of the existing users, and definitely will be new ones, want to count existing nodes in the list. Provide a generic API for that. Signed-off-by: Andy Shevchenko --- include/linux/list.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/linux/list.h b/include/linux/list.h index 61762054b4be..098eccf8c1b6 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -655,6 +655,19 @@ static inline void list_splice_tail_init(struct list_head *list, !list_is_head(pos, (head)); \ pos = n, n = pos->prev) +/** + * list_count - count nodes in the list + * @head: the head for your list. + */ +#define list_count(head) \ +({ \ + struct list_head *__tmp; \ + size_t __i = 0; \ + list_for_each(__tmp, head) \ + __i++; \ + __i; \ +}) + /** * list_entry_is_head - test if the entry points to the head of the list * @pos: the type * to cursor From patchwork Mon Nov 14 11:28:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13042164 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 073DCC433FE for ; Mon, 14 Nov 2022 11:29:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236216AbiKNL3Q (ORCPT ); Mon, 14 Nov 2022 06:29:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235984AbiKNL2q (ORCPT ); Mon, 14 Nov 2022 06:28:46 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A43420B; Mon, 14 Nov 2022 03:28:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668425303; x=1699961303; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2tt0pXqyf+X16xT+uW1YvPBZjN8jaC7fs9UiviM7Ozw=; b=YrAvqf21nYGAffNIN1j6ibDaOHHeR0tEztOGrAkQBJ/CmfVyy569pbav 44gSXkysv7z5gaULjsQFFZAB+0exrmGmHRkrP9UXpERcXYdFSYeWqUMgF 2CthT4Ac/OKwXwfuA8cU3PK7gfW20oEPV81VtZLv/muYAf5pniUZCugX+ CQUQ7Q3BX1p94Ba4XkB/8MnUWQUy969qQ8Q/nlzXUc86QL7vrTZe/VTyb oEn+TwpSghp8TfF9e1HZNt3+28W8QGti+tPeazCVWBmRbRMlqI4O35sZR ifPuhooedRjPklAfk1+bJPgrX57I5FdyWzy3OM7bCWsjJQjJzF7nlColM A==; X-IronPort-AV: E=McAfee;i="6500,9779,10530"; a="374074728" X-IronPort-AV: E=Sophos;i="5.96,161,1665471600"; d="scan'208";a="374074728" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Nov 2022 03:28:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10530"; a="616278550" X-IronPort-AV: E=Sophos;i="5.96,161,1665471600"; d="scan'208";a="616278550" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 14 Nov 2022 03:28:19 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 3FAC8346; Mon, 14 Nov 2022 13:28:44 +0200 (EET) From: Andy Shevchenko To: Jakob Koschel , Andy Shevchenko , Greg Kroah-Hartman , Mathias Nyman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kevin Cernekee , Mathias Nyman , Andrew Morton Subject: [PATCH v1 2/4] usb: gadget: hid: Convert to use list_count() Date: Mon, 14 Nov 2022 13:28:40 +0200 Message-Id: <20221114112842.38565-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221114112842.38565-1-andriy.shevchenko@linux.intel.com> References: <20221114112842.38565-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The list API now provides the list_count() to help with counting existing nodes in the list. Uilise it. Signed-off-by: Andy Shevchenko --- drivers/usb/gadget/legacy/hid.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/legacy/hid.c b/drivers/usb/gadget/legacy/hid.c index 1187ee4f316a..6196c3456e0b 100644 --- a/drivers/usb/gadget/legacy/hid.c +++ b/drivers/usb/gadget/legacy/hid.c @@ -133,14 +133,11 @@ static struct usb_configuration config_driver = { static int hid_bind(struct usb_composite_dev *cdev) { struct usb_gadget *gadget = cdev->gadget; - struct list_head *tmp; struct hidg_func_node *n = NULL, *m, *iter_n; struct f_hid_opts *hid_opts; - int status, funcs = 0; - - list_for_each(tmp, &hidg_func_list) - funcs++; + int status, funcs; + funcs = list_count(&hidg_func_list); if (!funcs) return -ENODEV; From patchwork Mon Nov 14 11:28:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13042166 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B175C433FE for ; Mon, 14 Nov 2022 11:29:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235879AbiKNL32 (ORCPT ); Mon, 14 Nov 2022 06:29:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236119AbiKNL2v (ORCPT ); Mon, 14 Nov 2022 06:28:51 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA49EB40; Mon, 14 Nov 2022 03:28:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668425305; x=1699961305; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cbHRKiBhBcfb/glMiq5EVCvPmL/FExuknALj1+3+vrE=; b=cYOZiq3GNj6IK/9GV/Slolw47SRvKzDvdwsN2J91Lw7WaIt30QhNgKqT 1u7UslYArshZRUr4dHR1rX2AWNEK2nMC9lq4bqObq7ZSdJtY7UsREkbDB 7hC7+Bi3ftM2a1ftHQj2H+Ag3nQSLwgvwcZHbyWz/9lr/jZLuBm3NXQTC WnY0qcBAKdoZ4SJgoHe7ZCPurbkoOc7QmxbxqaPtD3CQ3WEg/7prEwnyi KYaOz9CHypDSQmeGQ31iYqAu3FM7h98MsGl7VMBcS5PNlCmN69ApZZ4z8 EcRlCvRBUgdZyzkDp98JDrN2657M4/yNRWbwdVK1TsWlrmkawejie2b+O g==; X-IronPort-AV: E=McAfee;i="6500,9779,10530"; a="374074730" X-IronPort-AV: E=Sophos;i="5.96,161,1665471600"; d="scan'208";a="374074730" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Nov 2022 03:28:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10530"; a="616278554" X-IronPort-AV: E=Sophos;i="5.96,161,1665471600"; d="scan'208";a="616278554" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 14 Nov 2022 03:28:19 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 35D382F3; Mon, 14 Nov 2022 13:28:44 +0200 (EET) From: Andy Shevchenko To: Jakob Koschel , Andy Shevchenko , Greg Kroah-Hartman , Mathias Nyman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kevin Cernekee , Mathias Nyman , Andrew Morton Subject: [PATCH v1 3/4] usb: gadget: udc: bcm63xx: Convert to use list_count() Date: Mon, 14 Nov 2022 13:28:41 +0200 Message-Id: <20221114112842.38565-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221114112842.38565-1-andriy.shevchenko@linux.intel.com> References: <20221114112842.38565-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The list API now provides the list_count() to help with counting existing nodes in the list. Uilise it. Signed-off-by: Andy Shevchenko --- drivers/usb/gadget/udc/bcm63xx_udc.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/usb/gadget/udc/bcm63xx_udc.c b/drivers/usb/gadget/udc/bcm63xx_udc.c index 2cdb07905bde..0762e49e85f8 100644 --- a/drivers/usb/gadget/udc/bcm63xx_udc.c +++ b/drivers/usb/gadget/udc/bcm63xx_udc.c @@ -2172,7 +2172,6 @@ static int bcm63xx_iudma_dbg_show(struct seq_file *s, void *p) for (ch_idx = 0; ch_idx < BCM63XX_NUM_IUDMA; ch_idx++) { struct iudma_ch *iudma = &udc->iudma[ch_idx]; - struct list_head *pos; seq_printf(s, "IUDMA channel %d -- ", ch_idx); switch (iudma_defaults[ch_idx].ep_type) { @@ -2205,14 +2204,10 @@ static int bcm63xx_iudma_dbg_show(struct seq_file *s, void *p) seq_printf(s, " desc: %d/%d used", iudma->n_bds_used, iudma->n_bds); - if (iudma->bep) { - i = 0; - list_for_each(pos, &iudma->bep->queue) - i++; - seq_printf(s, "; %d queued\n", i); - } else { + if (iudma->bep) + seq_printf(s, "; %zu queued\n", list_count(&iudma->bep->queue)); + else seq_printf(s, "\n"); - } for (i = 0; i < iudma->n_bds; i++) { struct bcm_enet_desc *d = &iudma->bd_ring[i]; From patchwork Mon Nov 14 11:28:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13042165 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C7B9C43217 for ; Mon, 14 Nov 2022 11:29:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236496AbiKNL3T (ORCPT ); Mon, 14 Nov 2022 06:29:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236479AbiKNL2s (ORCPT ); Mon, 14 Nov 2022 06:28:48 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA43DB20; Mon, 14 Nov 2022 03:28:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668425305; x=1699961305; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CqSmXEq7rTgzGo2eyXNCXdiASe9v+/RyQA11rBsovD0=; b=CdI13GfWjfQQufzb6yMfsxLpUUzBGJfQ/jo5r4Dfy1lBBXAWRezYMoXv bNC4dFZBUPmxU/TVz1WrAizZYa8rwHO4iB69CJO4fTZZYV5gz5GNvK7FC zkbdkDDSappICXhsJ1ojWUeAYz7sniRhTBA3DGaVyA1X8Tja+phml7sGa YYAtb9zVremT12VR1T0RinxZbLcSRrXZmIu29P/f3N8udoJjkqW0SNCnD 5C7aJVafaLUoANmQkEC7ofF3rBDzUFDgrf9JCG3g8nyM2JwL6UXvpJbct fbOUtUOTdgPnWptKuQJ/L+iYWTS/WUl/aHHF4/NwTozoggZ2PSrOaj5SL w==; X-IronPort-AV: E=McAfee;i="6500,9779,10530"; a="374074729" X-IronPort-AV: E=Sophos;i="5.96,161,1665471600"; d="scan'208";a="374074729" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Nov 2022 03:28:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10530"; a="616278552" X-IronPort-AV: E=Sophos;i="5.96,161,1665471600"; d="scan'208";a="616278552" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 14 Nov 2022 03:28:19 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 48FA6339; Mon, 14 Nov 2022 13:28:44 +0200 (EET) From: Andy Shevchenko To: Jakob Koschel , Andy Shevchenko , Greg Kroah-Hartman , Mathias Nyman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kevin Cernekee , Mathias Nyman , Andrew Morton Subject: [PATCH v1 4/4] xhci: Convert to use list_count() Date: Mon, 14 Nov 2022 13:28:42 +0200 Message-Id: <20221114112842.38565-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221114112842.38565-1-andriy.shevchenko@linux.intel.com> References: <20221114112842.38565-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The list API now provides the list_count() to help with counting existing nodes in the list. Uilise it. Signed-off-by: Andy Shevchenko --- drivers/usb/host/xhci-ring.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index ad81e9a508b1..817c31e3b0c8 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2532,7 +2532,6 @@ static int handle_tx_event(struct xhci_hcd *xhci, union xhci_trb *ep_trb; int status = -EINPROGRESS; struct xhci_ep_ctx *ep_ctx; - struct list_head *tmp; u32 trb_comp_code; int td_num = 0; bool handling_skipped_tds = false; @@ -2580,10 +2579,8 @@ static int handle_tx_event(struct xhci_hcd *xhci, } /* Count current td numbers if ep->skip is set */ - if (ep->skip) { - list_for_each(tmp, &ep_ring->td_list) - td_num++; - } + if (ep->skip) + td_num += list_count(&ep_ring->td_list); /* Look for common error cases */ switch (trb_comp_code) {