From patchwork Thu Nov 18 04:53:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linyu Yuan X-Patchwork-Id: 12626011 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22D50C433FE for ; Thu, 18 Nov 2021 04:53:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 068546120E for ; Thu, 18 Nov 2021 04:53:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243057AbhKRE4r (ORCPT ); Wed, 17 Nov 2021 23:56:47 -0500 Received: from alexa-out-sd-02.qualcomm.com ([199.106.114.39]:25996 "EHLO alexa-out-sd-02.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243061AbhKRE4p (ORCPT ); Wed, 17 Nov 2021 23:56:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1637211226; x=1668747226; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=u/f8pUXy9itls9k3grtaYW6p2+4CXjPTwmvirnTmops=; b=P1TBEEf943J2stvqnuBa0Dalhm+PU1o0I9NcPZ6aEVIjfAZt2qDMpq4G 4BqEGXjnBitSVwVbQF0BX8q4AXA0idVcMrfZdRO1NqEMz5ZewPxmBU1Sb SETS0q1kxrWPtZ1mh+jDiNI8+3R5D0N83RiQg8sRLrE6T8XmonuyViUat I=; Received: from unknown (HELO ironmsg03-sd.qualcomm.com) ([10.53.140.143]) by alexa-out-sd-02.qualcomm.com with ESMTP; 17 Nov 2021 20:53:45 -0800 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg03-sd.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2021 20:53:45 -0800 Received: from nalasex01b.na.qualcomm.com (10.47.209.197) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.922.19; Wed, 17 Nov 2021 20:53:45 -0800 Received: from linyyuan-gv.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.922.19; Wed, 17 Nov 2021 20:53:43 -0800 From: Linyu Yuan To: Felipe Balbi , Greg Kroah-Hartman CC: , Jack Pham , "Linyu Yuan" Subject: [PATCH 1/4] usb: gadget: configfs: simplify os_desc_item_to_gadget_info() helper Date: Thu, 18 Nov 2021 12:53:30 +0800 Message-ID: <1637211213-16400-2-git-send-email-quic_linyyuan@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1637211213-16400-1-git-send-email-quic_linyyuan@quicinc.com> References: <1637211213-16400-1-git-send-email-quic_linyyuan@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org since os_desc_group is already a member of struct gadget_info, we can simply just use container_of() to retrieve the latter, without needing to dereference the cg_item's parent pointer. use os_desc_item_to_gadget_info() helper in os_desc (un)link function. Reviewed-by: Jack Pham Signed-off-by: Linyu Yuan --- drivers/usb/gadget/configfs.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index 36c611d..ac35fea 100644 --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c @@ -791,7 +791,8 @@ static inline struct os_desc *to_os_desc(struct config_item *item) static inline struct gadget_info *os_desc_item_to_gadget_info( struct config_item *item) { - return to_gadget_info(to_os_desc(item)->group.cg_item.ci_parent); + return container_of(to_config_group(item), + struct gadget_info, os_desc_group); } static ssize_t os_desc_use_show(struct config_item *item, char *page) @@ -895,8 +896,7 @@ static void os_desc_attr_release(struct config_item *item) static int os_desc_link(struct config_item *os_desc_ci, struct config_item *usb_cfg_ci) { - struct gadget_info *gi = container_of(to_config_group(os_desc_ci), - struct gadget_info, os_desc_group); + struct gadget_info *gi = os_desc_item_to_gadget_info(os_desc_ci); struct usb_composite_dev *cdev = &gi->cdev; struct config_usb_cfg *c_target = container_of(to_config_group(usb_cfg_ci), @@ -930,8 +930,7 @@ static int os_desc_link(struct config_item *os_desc_ci, static void os_desc_unlink(struct config_item *os_desc_ci, struct config_item *usb_cfg_ci) { - struct gadget_info *gi = container_of(to_config_group(os_desc_ci), - struct gadget_info, os_desc_group); + struct gadget_info *gi = os_desc_item_to_gadget_info(os_desc_ci); struct usb_composite_dev *cdev = &gi->cdev; mutex_lock(&gi->lock); From patchwork Thu Nov 18 04:53:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linyu Yuan X-Patchwork-Id: 12626009 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9A94C4332F for ; Thu, 18 Nov 2021 04:53:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C114261A3A for ; Thu, 18 Nov 2021 04:53:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243068AbhKRE4s (ORCPT ); Wed, 17 Nov 2021 23:56:48 -0500 Received: from alexa-out-sd-02.qualcomm.com ([199.106.114.39]:25996 "EHLO alexa-out-sd-02.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243066AbhKRE4q (ORCPT ); Wed, 17 Nov 2021 23:56:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1637211227; x=1668747227; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=giE4jAyHjj3uYZ2r2f8+g8NiIJVHRmm5GoKXuj9DKUs=; b=HzgZebE0rcHT86ofr8/SEc2pTjf+jyoASD9IMzpnimjmdC3wUfHy12Le nqXOMtHVF88TebtWSqwFJDFYVyXaZalUQW0jR1GTu1D8Pqka6kl1CR/xK 5fMdmAGBsqNlnR8EdaKygxf0jFc3xgZZ+91wFxvO044dorMblPWMGJzyH Q=; Received: from unknown (HELO ironmsg-SD-alpha.qualcomm.com) ([10.53.140.30]) by alexa-out-sd-02.qualcomm.com with ESMTP; 17 Nov 2021 20:53:47 -0800 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg-SD-alpha.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2021 20:53:47 -0800 Received: from nalasex01b.na.qualcomm.com (10.47.209.197) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.922.19; Wed, 17 Nov 2021 20:53:47 -0800 Received: from linyyuan-gv.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.922.19; Wed, 17 Nov 2021 20:53:45 -0800 From: Linyu Yuan To: Felipe Balbi , Greg Kroah-Hartman CC: , Jack Pham , "Linyu Yuan" Subject: [PATCH 2/4] usb: gadget: configfs: remove os_desc_attr_release() Date: Thu, 18 Nov 2021 12:53:31 +0800 Message-ID: <1637211213-16400-3-git-send-email-quic_linyyuan@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1637211213-16400-1-git-send-email-quic_linyyuan@quicinc.com> References: <1637211213-16400-1-git-send-email-quic_linyyuan@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org it is not allow to create sub group under os_desc, /sys/kernel/config/usb_gadget/dummy/os_desc # mkdir dummy mkdir: can't create directory 'dummy': Operation not permitted no one will kmalloc() os_desc entry and kfree(os_desc) will never be called. static void os_desc_attr_release(struct config_item *item) { struct os_desc *os_desc = to_os_desc(item); kfree(os_desc); } remove struct os_desc definition, to_os_desc() and os_desc_attr_release(). Reviewed-by: Jack Pham Signed-off-by: Linyu Yuan --- drivers/usb/gadget/configfs.c | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index ac35fea..ae0890a 100644 --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c @@ -89,10 +89,6 @@ struct gadget_strings { struct list_head list; }; -struct os_desc { - struct config_group group; -}; - struct gadget_config_name { struct usb_gadget_strings stringtab_dev; struct usb_string strings; @@ -783,11 +779,6 @@ static void gadget_strings_attr_release(struct config_item *item) USB_CONFIG_STRING_RW_OPS(gadget_strings); USB_CONFIG_STRINGS_LANG(gadget_strings, gadget_info); -static inline struct os_desc *to_os_desc(struct config_item *item) -{ - return container_of(to_config_group(item), struct os_desc, group); -} - static inline struct gadget_info *os_desc_item_to_gadget_info( struct config_item *item) { @@ -887,12 +878,6 @@ static struct configfs_attribute *os_desc_attrs[] = { NULL, }; -static void os_desc_attr_release(struct config_item *item) -{ - struct os_desc *os_desc = to_os_desc(item); - kfree(os_desc); -} - static int os_desc_link(struct config_item *os_desc_ci, struct config_item *usb_cfg_ci) { @@ -942,7 +927,6 @@ static void os_desc_unlink(struct config_item *os_desc_ci, } static struct configfs_item_operations os_desc_ops = { - .release = os_desc_attr_release, .allow_link = os_desc_link, .drop_link = os_desc_unlink, }; From patchwork Thu Nov 18 04:53:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linyu Yuan X-Patchwork-Id: 12626013 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A107C433EF for ; Thu, 18 Nov 2021 04:53:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E1B566120E for ; Thu, 18 Nov 2021 04:53:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243071AbhKRE4u (ORCPT ); Wed, 17 Nov 2021 23:56:50 -0500 Received: from alexa-out.qualcomm.com ([129.46.98.28]:41330 "EHLO alexa-out.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243066AbhKRE4t (ORCPT ); Wed, 17 Nov 2021 23:56:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1637211230; x=1668747230; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZFP5MoPFcjZDqUfIjfPVkKKqptAWVupotSolFT4/6bE=; b=pubHmQlTHzZfCUJHB2P3tBExto2Wy3UXr4NcbUbEQKv7dcQRLeAhx2ZG UNDe1DFztlOCJ6lZRNLJcvsvwrTEOevSf0JQETJvXWV/eikJLI3PUqGqv MJdcfzIS92dris+429ijM6bNFyY6hx/k80uuvvlDIlxY77wFyhV39OuuH w=; Received: from ironmsg09-lv.qualcomm.com ([10.47.202.153]) by alexa-out.qualcomm.com with ESMTP; 17 Nov 2021 20:53:50 -0800 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg09-lv.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2021 20:53:50 -0800 Received: from nalasex01b.na.qualcomm.com (10.47.209.197) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.922.19; Wed, 17 Nov 2021 20:53:48 -0800 Received: from linyyuan-gv.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.922.19; Wed, 17 Nov 2021 20:53:47 -0800 From: Linyu Yuan To: Felipe Balbi , Greg Kroah-Hartman CC: , Jack Pham , "Linyu Yuan" Subject: [PATCH 3/4] usb: gadget: configfs: use to_config_usb_cfg() in os_desc_link() Date: Thu, 18 Nov 2021 12:53:32 +0800 Message-ID: <1637211213-16400-4-git-send-email-quic_linyyuan@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1637211213-16400-1-git-send-email-quic_linyyuan@quicinc.com> References: <1637211213-16400-1-git-send-email-quic_linyyuan@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org replace open-coded container_of() with to_config_usb_cfg() helper. Reviewed-by: Jack Pham Signed-off-by: Linyu Yuan --- drivers/usb/gadget/configfs.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index ae0890a..ff0fb33 100644 --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c @@ -883,9 +883,7 @@ static int os_desc_link(struct config_item *os_desc_ci, { struct gadget_info *gi = os_desc_item_to_gadget_info(os_desc_ci); struct usb_composite_dev *cdev = &gi->cdev; - struct config_usb_cfg *c_target = - container_of(to_config_group(usb_cfg_ci), - struct config_usb_cfg, group); + struct config_usb_cfg *c_target = to_config_usb_cfg(usb_cfg_ci); struct usb_configuration *c; int ret; From patchwork Thu Nov 18 04:53:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linyu Yuan X-Patchwork-Id: 12626015 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BDAA6C433EF for ; Thu, 18 Nov 2021 04:53:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9D04E6120E for ; Thu, 18 Nov 2021 04:53:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243074AbhKRE4w (ORCPT ); Wed, 17 Nov 2021 23:56:52 -0500 Received: from alexa-out-sd-01.qualcomm.com ([199.106.114.38]:52314 "EHLO alexa-out-sd-01.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243066AbhKRE4v (ORCPT ); Wed, 17 Nov 2021 23:56:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1637211232; x=1668747232; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=U7ISu5ZQkjWnxyd6dGHRf46aIdHsQa1dZWGR/bxxe4A=; b=SflP4KYAw1gr7FnEnMAMQNzZ6UNU6YO/Lh3XswQrKz3/oiopU2yTjMcE /uq98sKoMvPfhJq00zj2sVRKvDJo5CMAtNw6obkJUgx2dDRYv1mbgbarL F62ILBMDXHvFiI2OjSILYFNsbi4ayobYGllc/e8pOiUUKj9To8gOprGwG U=; Received: from unknown (HELO ironmsg03-sd.qualcomm.com) ([10.53.140.143]) by alexa-out-sd-01.qualcomm.com with ESMTP; 17 Nov 2021 20:53:52 -0800 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg03-sd.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2021 20:53:51 -0800 Received: from nalasex01b.na.qualcomm.com (10.47.209.197) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.922.19; Wed, 17 Nov 2021 20:53:50 -0800 Received: from linyyuan-gv.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.922.19; Wed, 17 Nov 2021 20:53:48 -0800 From: Linyu Yuan To: Felipe Balbi , Greg Kroah-Hartman CC: , Jack Pham , "Linyu Yuan" Subject: [PATCH 4/4] usb: gadget: configfs: use to_usb_function_instance() in cfg (un)link func Date: Thu, 18 Nov 2021 12:53:33 +0800 Message-ID: <1637211213-16400-5-git-send-email-quic_linyyuan@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1637211213-16400-1-git-send-email-quic_linyyuan@quicinc.com> References: <1637211213-16400-1-git-send-email-quic_linyyuan@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org replace open-coded container_of() with to_usb_function_instance() helper. Reviewed-by: Jack Pham Signed-off-by: Linyu Yuan --- drivers/usb/gadget/configfs.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index ff0fb33..d4a678c 100644 --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c @@ -416,9 +416,8 @@ static int config_usb_cfg_link( struct config_usb_cfg *cfg = to_config_usb_cfg(usb_cfg_ci); struct gadget_info *gi = cfg_to_gadget_info(cfg); - struct config_group *group = to_config_group(usb_func_ci); - struct usb_function_instance *fi = container_of(group, - struct usb_function_instance, group); + struct usb_function_instance *fi = + to_usb_function_instance(usb_func_ci); struct usb_function_instance *a_fi; struct usb_function *f; int ret; @@ -466,9 +465,8 @@ static void config_usb_cfg_unlink( struct config_usb_cfg *cfg = to_config_usb_cfg(usb_cfg_ci); struct gadget_info *gi = cfg_to_gadget_info(cfg); - struct config_group *group = to_config_group(usb_func_ci); - struct usb_function_instance *fi = container_of(group, - struct usb_function_instance, group); + struct usb_function_instance *fi = + to_usb_function_instance(usb_func_ci); struct usb_function *f; /*