From patchwork Fri Aug 7 09:41:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 11705317 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CC84D14B7 for ; Fri, 7 Aug 2020 09:42:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B09D02177B for ; Fri, 7 Aug 2020 09:42:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="XgoV4ner" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727120AbgHGJmw (ORCPT ); Fri, 7 Aug 2020 05:42:52 -0400 Received: from mail-eopbgr50089.outbound.protection.outlook.com ([40.107.5.89]:59671 "EHLO EUR03-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726854AbgHGJmt (ORCPT ); Fri, 7 Aug 2020 05:42:49 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kQFI0eVDh19xsfxLY/igEpLSZ3LY6YuzkA3xDEICpDX8323bM/NHdblbOOZXk3aFkBEGo2+W/wCg57xfAptFWN6AhVE1cf0XE4CDH59NsTlWKIwF5UzeQ+/zEIVucN7ry5MohYnrYTHJFFmvfIich1RDJSlH3BBzKf8J+9havnMlxf9qR+nNIEae4o4nFsVxeeHokuUIRAcw/qCwAWBtRNpckcIMP6hZWfOv2f8UWGoqqx2zemLRC86Cjzrvd9ogO2jdELdg2LBBno3RFrVKMB1dpmtK9MkSnDUffLIIE27BlzIcBOBGJFNYqa0IqXWM2ZwEZ08r3XBD687kUi7+Ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4vxPPPntnViZsryI+nEulTcedG4sa2olk/BSe5ZZK2s=; b=MXSfLjwHCZauBPRyZWR72WFfTkEaDN5PzX6JUBSYpl7/risKMars/BWthdJLYGexIqQt2OWwjIstqJraHMR6L0MAYmPGLBiv7CVQmbueTmHrNFrnWQQkCDIg8RynbTCTQBBePX02my5RPY7Efpr2O8bmYfAmK7M9R1HNxjPkuFGeFPKVXhOY7P/kw6r+x/bbuPKrWSFDujNFh7QomQ7f06VZ+I0bADBqFxN5m/JthT5x9yXHFzuVbGfmTDimG9kRlsbbENZHs7EexbHikxAC8WSi3ufHZMRqv3vh97rGoarpEww8uYPGpC6PBKXMnUcqgHvUYg0B2WgpyLwWgR4SIw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4vxPPPntnViZsryI+nEulTcedG4sa2olk/BSe5ZZK2s=; b=XgoV4nerxBaXy6QlTVpajLZ6ME45FP6XBUxQQ+hfUmeMt3DpykJVNZxjQzXUUhq7hB3Q3zXEvBTryXwJoFF0+fpvOU7YIwWGe6bbsITCqco4sHwOf3RH5hzmGauENC1eo68O9s6V36um/kY95lexF6atJqMSDIa82fJ6KvysjwI= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=nxp.com; Received: from AM7PR04MB7157.eurprd04.prod.outlook.com (2603:10a6:20b:118::20) by AM7PR04MB7077.eurprd04.prod.outlook.com (2603:10a6:20b:11c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 09:42:46 +0000 Received: from AM7PR04MB7157.eurprd04.prod.outlook.com ([fe80::ed7f:8755:5994:7fcf]) by AM7PR04MB7157.eurprd04.prod.outlook.com ([fe80::ed7f:8755:5994:7fcf%5]) with mapi id 15.20.3261.020; Fri, 7 Aug 2020 09:42:46 +0000 From: Peter Chen To: balbi@kernel.org Cc: linux-usb@vger.kernel.org, linux-imx@nxp.com, stern@rowland.harvard.edu, gregkh@linuxfoundation.org, Anton Vasilyev , Evgeny Novikov , Benjamin Herrenschmidt Subject: [PATCH 1/6] USB: UDC: Expand device model API interface Date: Fri, 7 Aug 2020 17:41:46 +0800 Message-Id: <20200807094151.13526-2-peter.chen@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200807094151.13526-1-peter.chen@nxp.com> References: <20200807094151.13526-1-peter.chen@nxp.com> X-ClientProxiedBy: SG2PR03CA0113.apcprd03.prod.outlook.com (2603:1096:4:91::17) To AM7PR04MB7157.eurprd04.prod.outlook.com (2603:10a6:20b:118::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from b29397-desktop.ap.freescale.net (119.31.174.67) by SG2PR03CA0113.apcprd03.prod.outlook.com (2603:1096:4:91::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.5 via Frontend Transport; Fri, 7 Aug 2020 09:42:44 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [119.31.174.67] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 1376035e-25bf-4f95-b142-08d83ab63da4 X-MS-TrafficTypeDiagnostic: AM7PR04MB7077: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:392; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gpOHVdO+zLNNDq4uWwsDldDqnQzmhxfkPTBbbM51R3EbknjYfOniDsH7rmAXEUOjhSiY/EzotpGmCI/tgz9L8BpEVnbibMVKot1ViInF7WCyl8lHCip1q69joLlTAR9smjVgR3Xc+arVvEdERF4Ic/QIyUhB2V2Fm/ZQfWBQ7RU0bpQk8EOBKtKUYR5J8OhiC66487bVbZtGeljOa14SidqVXy37+JZsun43gXNeH8ydtIDjrMdoy3NDuig7RSFavD7ukMBDKlWTLz3e8SD38vsEMZ7EcwMtpC+klG9CVl288B03LhtPkksp08FZvKWUEfE30EIH7auqyB6Gq5Fygg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM7PR04MB7157.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(366004)(346002)(136003)(39860400002)(376002)(396003)(956004)(2616005)(5660300002)(86362001)(16526019)(44832011)(6486002)(186003)(66556008)(66946007)(4326008)(6512007)(26005)(52116002)(8676002)(83380400001)(1076003)(54906003)(66476007)(36756003)(8936002)(478600001)(6916009)(316002)(6506007)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 3mqbvOj0egR4K+40TXXTzfb/IZGnfXroSmAoCwdQIAngwsCT2ty54/Uym3Kf/HHgHx63sZ9mMF4U6JtUIrrQ2F4zhQYgft49a/2/HfrUeee8tQ4RtBnNxMrohoCcpKP34HslWBX0hThBVS/agw9v1rBKZOwrmQ868nnsUxrZadB6C0WCeiJ3YqzqZTNqJgrK1U41ygZBBaBF2wKt0ly+UJbUxBd6GWaZjCkSD9Cn5mAfDswrngteVWr0dcUi2xti73jxa16whx92LlUfIx/0QCBUIdd5xcaJSwmZZLNwwhgahphuIHI7B9j5Fdc1CWv/VdKN2B5L786Bc7xEvtgkL+7nfiUHBRRAHaZjpwGIm13mztO4K7B6uCcrAmQulP+Jhr2+10Tm+zcVbpOAPsGyG7V541LCUNl18CwWabU0RCjN1GLf5GAVMT/qQ2TyqGve2Gxj6+/1B+11uJbKz1hk1VmwWF3iCFcjaqHiES+GFR/Cg8M/TtOt5fbam7Ai+0673i4/SGVD15H55HNJTU9bLLZJhMQmH7Oj86qJ2ng7RYlZVmT6l38cG9oJzDQr8FrsLmAAGz3UaEFuPMsqI4Tghm5PcC4Y3W7yotSGmmX5JjBiGUev8ISv9XKSdAwiMZWO6hFIs0G8iytoMc0uF+JDoQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1376035e-25bf-4f95-b142-08d83ab63da4 X-MS-Exchange-CrossTenant-AuthSource: AM7PR04MB7157.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 09:42:46.7678 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /lioqhB8TZSc53ESWE3f8AP73752r2zQsBLqOdAK7U3UuKY0u6nz6j7NSrDE5N7bX+w3MBrW/Zm1ZzVyiSPHpA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR04MB7077 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Alan Stern The routines used by the UDC core to interface with the kernel's device model, namely usb_add_gadget_udc(), usb_add_gadget_udc_release(), and usb_del_gadget_udc(), provide access to only a subset of the device model's full API. They include functionality equivalent to device_register() and device_unregister() for gadgets, but they omit device_initialize(), device_add(), device_del(), get_device(), and put_device(). This patch expands the UDC API by adding usb_initialize_gadget(), usb_add_gadget(), usb_del_gadget(), usb_get_gadget(), and usb_put_gadget() to fill in the gap. It rewrites the existing routines to call the new ones. CC: Anton Vasilyev CC: Evgeny Novikov CC: Benjamin Herrenschmidt Signed-off-by: Alan Stern --- Changes for RFC - %s/intialize/initialize - Delete the net2272 and 2280 description at commit log drivers/usb/gadget/udc/core.c | 78 ++++++++++++++++++++++++++++------- include/linux/usb/gadget.h | 27 +++++++++--- 2 files changed, 84 insertions(+), 21 deletions(-) diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c index ee226ad802a4..473e74088b1f 100644 --- a/drivers/usb/gadget/udc/core.c +++ b/drivers/usb/gadget/udc/core.c @@ -1162,21 +1162,18 @@ static int check_pending_gadget_drivers(struct usb_udc *udc) } /** - * usb_add_gadget_udc_release - adds a new gadget to the udc class driver list + * usb_initialize_gadget - initialize a gadget and its embedded struct device * @parent: the parent device to this udc. Usually the controller driver's * device. - * @gadget: the gadget to be added to the list. + * @gadget: the gadget to be initialized. * @release: a gadget release function. * * Returns zero on success, negative errno otherwise. * Calls the gadget release function in the latter case. */ -int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, +void usb_initialize_gadget(struct device *parent, struct usb_gadget *gadget, void (*release)(struct device *dev)) { - struct usb_udc *udc; - int ret = -ENOMEM; - dev_set_name(&gadget->dev, "gadget"); INIT_WORK(&gadget->work, usb_gadget_state_work); gadget->dev.parent = parent; @@ -1187,17 +1184,32 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, gadget->dev.release = usb_udc_nop_release; device_initialize(&gadget->dev); +} +EXPORT_SYMBOL_GPL(usb_initialize_gadget); + +/** + * usb_add_gadget - adds a new gadget to the udc class driver list + * @gadget: the gadget to be added to the list. + * + * Returns zero on success, negative errno otherwise. + * Does not do a final usb_put_gadget() if an error occurs. + */ +int usb_add_gadget(struct usb_gadget *gadget) +{ + struct usb_udc *udc; + int ret = -ENOMEM; udc = kzalloc(sizeof(*udc), GFP_KERNEL); if (!udc) - goto err_put_gadget; + goto error; device_initialize(&udc->dev); udc->dev.release = usb_udc_release; udc->dev.class = udc_class; udc->dev.groups = usb_udc_attr_groups; - udc->dev.parent = parent; - ret = dev_set_name(&udc->dev, "%s", kobject_name(&parent->kobj)); + udc->dev.parent = gadget->dev.parent; + ret = dev_set_name(&udc->dev, "%s", + kobject_name(&gadget->dev.parent->kobj)); if (ret) goto err_put_udc; @@ -1239,8 +1251,30 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, err_put_udc: put_device(&udc->dev); - err_put_gadget: - put_device(&gadget->dev); + error: + return ret; +} +EXPORT_SYMBOL_GPL(usb_add_gadget); + +/** + * usb_add_gadget_udc_release - adds a new gadget to the udc class driver list + * @parent: the parent device to this udc. Usually the controller driver's + * device. + * @gadget: the gadget to be added to the list. + * @release: a gadget release function. + * + * Returns zero on success, negative errno otherwise. + * Calls the gadget release function in the latter case. + */ +int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, + void (*release)(struct device *dev)) +{ + int ret; + + usb_initialize_gadget(parent, gadget, release); + ret = usb_add_gadget(gadget); + if (ret) + usb_put_gadget(gadget); return ret; } EXPORT_SYMBOL_GPL(usb_add_gadget_udc_release); @@ -1308,13 +1342,14 @@ static void usb_gadget_remove_driver(struct usb_udc *udc) } /** - * usb_del_gadget_udc - deletes @udc from udc_list + * usb_del_gadget - deletes @udc from udc_list * @gadget: the gadget to be removed. * - * This, will call usb_gadget_unregister_driver() if + * This will call usb_gadget_unregister_driver() if * the @udc is still busy. + * It will not do a final usb_put_gadget(). */ -void usb_del_gadget_udc(struct usb_gadget *gadget) +void usb_del_gadget(struct usb_gadget *gadget) { struct usb_udc *udc = gadget->udc; @@ -1337,7 +1372,20 @@ void usb_del_gadget_udc(struct usb_gadget *gadget) kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE); flush_work(&gadget->work); device_unregister(&udc->dev); - device_unregister(&gadget->dev); + device_del(&gadget->dev); +} +EXPORT_SYMBOL_GPL(usb_del_gadget); + +/** + * usb_del_gadget_udc - deletes @udc from udc_list + * @gadget: the gadget to be removed. + * + * Calls usb_del_gadget() and does a final usb_put_gadget(). + */ +void usb_del_gadget_udc(struct usb_gadget *gadget) +{ + usb_del_gadget(gadget); + usb_put_gadget(gadget); memset(&gadget->dev, 0x00, sizeof(gadget->dev)); } EXPORT_SYMBOL_GPL(usb_del_gadget_udc); diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index 298b334e2951..791571f5191e 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -436,6 +436,7 @@ struct usb_gadget { }; #define work_to_gadget(w) (container_of((w), struct usb_gadget, work)) +/* Interface to the device model */ static inline void set_gadget_data(struct usb_gadget *gadget, void *data) { dev_set_drvdata(&gadget->dev, data); } static inline void *get_gadget_data(struct usb_gadget *gadget) @@ -444,6 +445,26 @@ static inline struct usb_gadget *dev_to_usb_gadget(struct device *dev) { return container_of(dev, struct usb_gadget, dev); } +static inline struct usb_gadget *usb_get_gadget(struct usb_gadget *gadget) +{ + get_device(&gadget->dev); + return gadget; +} +static inline void usb_put_gadget(struct usb_gadget *gadget) +{ + put_device(&gadget->dev); +} +extern void usb_initialize_gadget(struct device *parent, + struct usb_gadget *gadget, void (*release)(struct device *dev)); +extern int usb_add_gadget(struct usb_gadget *gadget); +extern void usb_del_gadget(struct usb_gadget *gadget); + +/* Legacy device-model interface */ +extern int usb_add_gadget_udc_release(struct device *parent, + struct usb_gadget *gadget, void (*release)(struct device *dev)); +extern int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget); +extern void usb_del_gadget_udc(struct usb_gadget *gadget); +extern char *usb_get_gadget_udc_name(void); /* iterates the non-control endpoints; 'tmp' is a struct usb_ep pointer */ #define gadget_for_each_ep(tmp, gadget) \ @@ -735,12 +756,6 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver); */ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver); -extern int usb_add_gadget_udc_release(struct device *parent, - struct usb_gadget *gadget, void (*release)(struct device *dev)); -extern int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget); -extern void usb_del_gadget_udc(struct usb_gadget *gadget); -extern char *usb_get_gadget_udc_name(void); - /*-------------------------------------------------------------------------*/ /* utility to simplify dealing with string descriptors */ From patchwork Fri Aug 7 09:41:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 11705319 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5F04713B6 for ; Fri, 7 Aug 2020 09:42:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4362922CAE for ; Fri, 7 Aug 2020 09:42:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="MIXPf8wu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727843AbgHGJm4 (ORCPT ); Fri, 7 Aug 2020 05:42:56 -0400 Received: from mail-eopbgr50089.outbound.protection.outlook.com ([40.107.5.89]:59671 "EHLO EUR03-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727081AbgHGJmx (ORCPT ); Fri, 7 Aug 2020 05:42:53 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mIgZT8oCsIeNxNhdB14g3W+J8K02u6uCs6jbyRSq5cbov27EWPy9b6xMsOMeiHbZXKwjNoPUwMI3y3FC12kIyqbeyEaF5f30wTG+/URtmAMR+SsE0USDT0ab565Vpa04Ne7QT8kSIdRYFQPKNfnctbhfINL1ZaKImnoQT3s+gCz3na2z9zlTRXQ4sCR+/X5elOiIoMrG40zat2lwuLnAkexZN6iWzmfD2dtLsLZMVoJg976VBprE8Jf2n2FydtZoMEv4FCDT1vSVFPgxJ9BrMmFCVPhVoE69nQv4VuGVbPlbPE2iQ0cIHW1Gd0ZsmrJIG5mkPerD+riMs77s6o8wAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/Kb2oQ6FmZWJT3Kyxb0WYbD5576GuZnueYOFhN37au4=; b=DiNzyGqrRtFlIkM6k+F5a8W1ZpeXg/aUSH1hjodJA7+Yo2b786Ir6fR65MnRIETyTMbAEk+BO6l7+r1PbsmMcUWU5Ew4HDhPXl9Zy4xZaMC2kU959yhp/8iRLf8dT3Atcq91/XHQ/KyTV0C4T15waIQTodQZbM1h0tgswTBCIvSHpiR7VEFZ71udCpuSOwhHrb9mYGbusH666h2QZPeImat1sjiD2/qnINjsfmwCx4OJBRgrslGp0Xq+ie9FObmnEwVDcstVEsHY/VH8q6OdOR1DdA4ZVkfSOmeig/voGSO1c2N/y2cuRdu66IqHWnsKYQQD23shRbslOMNRO372pw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/Kb2oQ6FmZWJT3Kyxb0WYbD5576GuZnueYOFhN37au4=; b=MIXPf8wuObbuH9vL28b1dNwpJzzSR5aNdA20FUlPjXIHo0yBGau5TmCZ1LGMbs7pOzHNClbWaqUW66beorN+hKTEfERq89/OpNmLH3ODTajOasI1Kxg5ZlVLttkLEOarZMjqQobmWB6Zx2FyoLWEYkgFJbGbeep6GQ3MgLcNr3w= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=nxp.com; Received: from AM7PR04MB7157.eurprd04.prod.outlook.com (2603:10a6:20b:118::20) by AM7PR04MB7077.eurprd04.prod.outlook.com (2603:10a6:20b:11c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 09:42:49 +0000 Received: from AM7PR04MB7157.eurprd04.prod.outlook.com ([fe80::ed7f:8755:5994:7fcf]) by AM7PR04MB7157.eurprd04.prod.outlook.com ([fe80::ed7f:8755:5994:7fcf%5]) with mapi id 15.20.3261.020; Fri, 7 Aug 2020 09:42:49 +0000 From: Peter Chen To: balbi@kernel.org Cc: linux-usb@vger.kernel.org, linux-imx@nxp.com, stern@rowland.harvard.edu, gregkh@linuxfoundation.org, Benjamin Herrenschmidt Subject: [PATCH 2/6] USB: UDC: net2280: Fix memory leaks Date: Fri, 7 Aug 2020 17:41:47 +0800 Message-Id: <20200807094151.13526-3-peter.chen@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200807094151.13526-1-peter.chen@nxp.com> References: <20200807094151.13526-1-peter.chen@nxp.com> X-ClientProxiedBy: SG2PR03CA0113.apcprd03.prod.outlook.com (2603:1096:4:91::17) To AM7PR04MB7157.eurprd04.prod.outlook.com (2603:10a6:20b:118::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from b29397-desktop.ap.freescale.net (119.31.174.67) by SG2PR03CA0113.apcprd03.prod.outlook.com (2603:1096:4:91::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.5 via Frontend Transport; Fri, 7 Aug 2020 09:42:47 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [119.31.174.67] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 56e1fce7-810e-460a-5703-08d83ab63f08 X-MS-TrafficTypeDiagnostic: AM7PR04MB7077: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4303; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NwlUzydVP8YmMOl91RUdjw8b3RQxgBUsZ9DKn+2IxdAPP+tsJvKLH6Bi3LmtI8ZIF22+8jPEB0xttxZ+pnC7oXFyAdlqQFF+DfvYxy220+y0gB6GXpZsB1q81+zw+r4I/wMVe/fcGyXb8JDaKfRbvJao4FftVFobLpavg+5Fbot8Gq8PWAcjNcL5uW85bmSkCO3wwVABFodfwhXzJ3Y2UI88xESvd7WFhHrLhgrSkvfRDGGov56Sl/GY910xWXwxM3FNwCBaRSKbJ0Jk/alSnnPap/PIQUSON7kqm2I4M8HMr/zoHvlJE15s4TGNwnut+3ZPCgYO5eWFqa0eadgGOg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM7PR04MB7157.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(366004)(346002)(136003)(39860400002)(376002)(396003)(956004)(2616005)(5660300002)(86362001)(16526019)(44832011)(6486002)(186003)(66556008)(66946007)(4326008)(6512007)(26005)(52116002)(8676002)(83380400001)(1076003)(66476007)(36756003)(8936002)(478600001)(6916009)(316002)(6506007)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Fs4FgDvdM5kmkDiRw9XEn3/RupWyXbS9t6EC1pBPqzltluC24o9XS57OS5Sn0Cx7+FvY5Bv3HD8FjuFYpk+yUCIY02xMG4foJ6KsbiERQn9DxNlvzCYR7bhwNIlIg2GQEJ+E/R9lFIOPXtcxkW0ZJSV4zRYdGV4U24/aBbC/We2OLvyDmhaP2FeTA2QAmxrim7R6OzVrsmLiSIwcY4dnIiy/3DuRjxvV4jHUbU7U7OC1G3tWMMQUsYGpIYCzV6/I80VX0bqDyCot83VuFnXHFR6Y+fYpbijQhNOeCHegE56TLqC4xltYzs2QdSm1m1PDkwo5JgHMT7Q0KZM88aoIXzEgHLhOvZaVP+i2nv4bWJOWQQcoSX5dnSfr34k6gyUfhcncuy1asAj9xZrf4LCc3ZN44vZq6IZrXqSbmdcptpfQ2y2xq/422XReuBEUL6iZvNehuPklIKCa49HjBV9nhl/Vgt+Q+AuVmJTkmvam6+ulIV0etb8re1A6PvWzTdTfAq+OIE/acnyN+jG17P+n82yIgUDMe8A9Ug6158a15yswbTJCx7vk8OaG8LEuqpUoVnWksC6UzVYNBfWwpaTb4eAMHNv6CVafOWbUUUDALcPy2b+rvYrbejDe4BgNjkkrT3hbovnqvW8NkDkLmbviZw== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 56e1fce7-810e-460a-5703-08d83ab63f08 X-MS-Exchange-CrossTenant-AuthSource: AM7PR04MB7157.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 09:42:49.0707 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: RdyLFl1qIPcGh1/79qyVShwoAKtwh+G9djiTZDrEC6qf2KYoABR/zYcCP15yIUaqPhkD6yAjIPi4tmJCPfo3jA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR04MB7077 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Alan Stern As Anton and Evgeny have noted, the net2280 UDC driver has a problem with leaking memory along some of its failure pathways. It also has another problem, not previously noted, in that some of the failure pathways will call usb_del_gadget_udc() without first calling usb_add_gadget_udc_release(). And it leaks memory by calling kfree() when it should call put_device(). Previous attempts to fix the problems have failed because of lack of support in the UDC core for separately initializing and adding gadgets, or for separately deleting and freeing gadgets. The previous patch in this series adds the necessary support, making it possible to fix the outstanding problems properly. This patch adds an "added" flag to the net2280 structure to indicate whether or not the gadget has been registered (and thus whether or not to call usb_del_gadget()), and it fixes the deallocation issues by calling usb_put_gadget() at the appropriate point. A similar memory leak issue, apparently never before recognized, stems from the fact that the driver never initializes the drvdata field in the gadget's embedded struct device! Evidently this wasn't noticed because the pointer is only ever used as an argument to kfree(), which doesn't mind getting called with a NULL pointer. In fact, the drvdata for gadget device will be written by usb_composite_dev structure if any gadget class is loaded, so it needs to use usb_gadget structure to get net2280 private data. CC: Benjamin Herrenschmidt Reported-by: Anton Vasilyev Reported-by: Evgeny Novikov Signed-off-by: Alan Stern --- Changes from RFC: - Using usb_gadget structure to get net2280 private data, and update commit log accoringly. drivers/usb/gadget/udc/net2280.c | 13 +++++++++---- drivers/usb/gadget/udc/net2280.h | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/udc/net2280.c b/drivers/usb/gadget/udc/net2280.c index 5eff85eeaa5a..0b449f4c2da0 100644 --- a/drivers/usb/gadget/udc/net2280.c +++ b/drivers/usb/gadget/udc/net2280.c @@ -3561,7 +3561,9 @@ static irqreturn_t net2280_irq(int irq, void *_dev) static void gadget_release(struct device *_dev) { - struct net2280 *dev = dev_get_drvdata(_dev); + struct usb_gadget *gadget = container_of(_dev, + struct usb_gadget, dev); + struct net2280 *dev = container_of(gadget, struct net2280, gadget); kfree(dev); } @@ -3572,7 +3574,8 @@ static void net2280_remove(struct pci_dev *pdev) { struct net2280 *dev = pci_get_drvdata(pdev); - usb_del_gadget_udc(&dev->gadget); + if (dev->added) + usb_del_gadget(&dev->gadget); BUG_ON(dev->driver); @@ -3603,6 +3606,7 @@ static void net2280_remove(struct pci_dev *pdev) device_remove_file(&pdev->dev, &dev_attr_registers); ep_info(dev, "unbind\n"); + usb_put_gadget(&dev->gadget); } /* wrap this driver around the specified device, but @@ -3624,6 +3628,7 @@ static int net2280_probe(struct pci_dev *pdev, const struct pci_device_id *id) } pci_set_drvdata(pdev, dev); + usb_initialize_gadget(&pdev->dev, &dev->gadget, gadget_release); spin_lock_init(&dev->lock); dev->quirks = id->driver_data; dev->pdev = pdev; @@ -3774,10 +3779,10 @@ static int net2280_probe(struct pci_dev *pdev, const struct pci_device_id *id) if (retval) goto done; - retval = usb_add_gadget_udc_release(&pdev->dev, &dev->gadget, - gadget_release); + retval = usb_add_gadget(&dev->gadget); if (retval) goto done; + dev->added = 1; return 0; done: diff --git a/drivers/usb/gadget/udc/net2280.h b/drivers/usb/gadget/udc/net2280.h index 85d3ca1698ba..7da3dc1e9729 100644 --- a/drivers/usb/gadget/udc/net2280.h +++ b/drivers/usb/gadget/udc/net2280.h @@ -156,6 +156,7 @@ struct net2280 { softconnect : 1, got_irq : 1, region:1, + added:1, u1_enable:1, u2_enable:1, ltm_enable:1, From patchwork Fri Aug 7 09:41:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 11705321 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D102C13B6 for ; Fri, 7 Aug 2020 09:43:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B67E52177B for ; Fri, 7 Aug 2020 09:43:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="hrp/c8bL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727848AbgHGJnA (ORCPT ); Fri, 7 Aug 2020 05:43:00 -0400 Received: from mail-eopbgr50089.outbound.protection.outlook.com ([40.107.5.89]:59671 "EHLO EUR03-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727053AbgHGJm7 (ORCPT ); Fri, 7 Aug 2020 05:42:59 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jafFUnDVOl0ENb5WA6PlkhOM/UIXri6+FIxBntPHOaEF0qrq7+zhS6en5djJw3iMx2oYp4fN6Pj5Ol6nVvyPI+Z/N+xQVMVewIpAQJyo2LtI0AWziwd4FIAx78EfE2yfv3ZUU5pLu3LD7UGfHnBGeMjGuRF1vGUk7Vxe/kfsIXumgyveIfrgd7qRu4mu7fWxTYK4uTx63bplvaLrkNLq+EF3ZKqbSAYiECfN+XtYHegqqgmWOk1n5yKfacRXuEQRdH+YJRHrt202eOEFrfmwN3qJxwTYfDu4o/XkvCM78J9rcsVZyT4PFhRztC5KJ38On/TGkczCxRTrFW1Q6xqnuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=21l/gh3hvYNakCn64n/3nXvrnC6AZI1xTWGT9r3k3nM=; b=PMS6MpUuaNwlJWch44YJayngpkmhdU++kOh+3VDV5uy8q/jYRWMTZl3WTywrvNdH9IRiGYlmfadcusW3LczdLjhzSySQ6XcG7SudUZRQPpcTMzpLhzsZU1js52NjnF4oERPUEhZqB51NGJDAge4Ldj1IJEuFFP1+iGylVpBx9fOfsDsw9pYj1WOnQDrEdM3C99eJE3RS0+rX70Zkbhq+IaBalXLh2i8yGvCyBHkoEnjG0f5ZkYWkCktJFImdZHXPwc3iW7BMR0/CFZMGNXWE/uaquqHtpjJ4Rx0/1qTlwBJibWtCIWLNPASiVGS1qz3htmSEEJz78AjrRktJOuDb/A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=21l/gh3hvYNakCn64n/3nXvrnC6AZI1xTWGT9r3k3nM=; b=hrp/c8bL4LdD3I5zO9yiTWKZJ0HRxYCddyfPD0BJUJgRqpK74u1DpnI9E08Sj4JLiy/vfXAHlAbxzL0ZMjqnG3t2OsymTaQMBs0zGSMFlPMTCnAdtgBMSOE6+Fm/J6kEIpP0hKQHs8PB38IZtMfXjnjBuzLVFuQ6o++rkw26BeM= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=nxp.com; Received: from AM7PR04MB7157.eurprd04.prod.outlook.com (2603:10a6:20b:118::20) by AM7PR04MB7077.eurprd04.prod.outlook.com (2603:10a6:20b:11c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 09:42:52 +0000 Received: from AM7PR04MB7157.eurprd04.prod.outlook.com ([fe80::ed7f:8755:5994:7fcf]) by AM7PR04MB7157.eurprd04.prod.outlook.com ([fe80::ed7f:8755:5994:7fcf%5]) with mapi id 15.20.3261.020; Fri, 7 Aug 2020 09:42:52 +0000 From: Peter Chen To: balbi@kernel.org Cc: linux-usb@vger.kernel.org, linux-imx@nxp.com, stern@rowland.harvard.edu, gregkh@linuxfoundation.org, Anton Vasilyev , Evgeny Novikov , Benjamin Herrenschmidt Subject: [PATCH 3/6] USB: UDC: net2272: Fix memory leaks Date: Fri, 7 Aug 2020 17:41:48 +0800 Message-Id: <20200807094151.13526-4-peter.chen@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200807094151.13526-1-peter.chen@nxp.com> References: <20200807094151.13526-1-peter.chen@nxp.com> X-ClientProxiedBy: SG2PR03CA0113.apcprd03.prod.outlook.com (2603:1096:4:91::17) To AM7PR04MB7157.eurprd04.prod.outlook.com (2603:10a6:20b:118::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from b29397-desktop.ap.freescale.net (119.31.174.67) by SG2PR03CA0113.apcprd03.prod.outlook.com (2603:1096:4:91::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.5 via Frontend Transport; Fri, 7 Aug 2020 09:42:49 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [119.31.174.67] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: e07387b0-a52d-4280-7584-08d83ab640d8 X-MS-TrafficTypeDiagnostic: AM7PR04MB7077: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3631; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fo9zcJSZRmWlm3hqWPs/eBUxfiwE/nDoZOTi4vrUlvgCA4I4ulHJuifxBgT+/3FgXVnuX4QRHeTjqg3akfe/FFYI5Q56L8mY3wi1TpcNh9gXUewloyhK/Vs62XbQLCbGxx3BEZsGmaNBpUUWcUL/P4dchnn08ky6rZJNtQ8Ce2E5D7wDKxCrFQZPLsm9huBU9EEL3FTCuTTYc0pCW+yoCk1Lm9gKmriddefoIyzbluX+sPFaBq6fS+OVwDP0BOHzOlefnhoElamP/qhdXllu6Ml8b/HPuTDFWc8ZZqzmgtv0tv5OeHY+xD1cYJC9sGP+8DmIG0CGE5Wr7eEk0pk5cQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM7PR04MB7157.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(366004)(346002)(136003)(39860400002)(376002)(396003)(956004)(2616005)(5660300002)(86362001)(16526019)(44832011)(6486002)(186003)(66556008)(66946007)(4326008)(6512007)(26005)(52116002)(8676002)(83380400001)(1076003)(54906003)(66476007)(36756003)(8936002)(478600001)(6916009)(316002)(6506007)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: RKKjFvxzlfCpm48M46Bnb9+oIXkoWCtdQKwelgn7Rhnc8gFltx4Uf5+9i6oQlDFedXnJ1EujWn2ZUzbegtoeS3jirNcnB9ucEyK8PW++ybVHIKXVee6aAauLSOsTzycEU5atvOUcoGQBGmpT/nxwy+YeytaS8GZB2QgfzhIlslOCv0XY0XN0rIR744SPm5670tC1E9sz/olW4KBeB0MD98QFWu9E3YyFg0gDSaoLf0tAWwQnX51uQvPCU8ajlM2Ad/bRuHD6JZ5FLjLbM+DYR5rMBkbZCAlKsEuwzBEcDNizdySsGIYGhNOSlJkEZHsYpx4JwJ/mQ36NgC7ISbR7iPCkgFTqA7ZK7pO5su/TbBAiQ5l7ktUouwPyOPgsU/4j/rV5UMIBNcnGlgzwCINS6ZuDc9oGcQAxAjxrBcZfA5BivRQvTnb4j6SP/8dxRXygngpOKrGi3X+5UaWrEgc31JDfpwhbn5kF9pS7xZR8SPOPA6pd/Ij6VoU2/Y1F+8nOXBXFP0Xf17fJ+IQQh9iMfhJr8ZupQ79bjRIYerkt0nuyFmDa8ZaC8+5fq+h+GGOlVLMh0/w6vUI02geDYIhRzvYRnx2mLuPYMG1Xiud6K5CnFVrYjm5u4MmNM5eO3nHRhRStH+s56qAVhHimjh4qWg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: e07387b0-a52d-4280-7584-08d83ab640d8 X-MS-Exchange-CrossTenant-AuthSource: AM7PR04MB7157.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 09:42:52.0954 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 9Pq7p0zqGGCupdWGR5SaRM4NlhYRsO6NrZNl9Y7d8XEwe9aRhcY94qOrRFcODMwqa+WTDnbfmquczhKp4rqfvw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR04MB7077 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Alan Stern Like net2280 (on which it was based), the net2272 UDC driver has a problem with leaking memory along some of its failure pathways. It also has another problem, not previously noted, in that some of the failure pathways will call usb_del_gadget_udc() without first calling usb_add_gadget_udc_release(). And it leaks memory by calling kfree() when it should call put_device(). Until now it has been impossible to handle the memory leaks, because of lack of support in the UDC core for separately initializing and adding gadgets, or for separately deleting and freeing gadgets. An earlier patch in this series adds the necessary support, making it possible to fix the outstanding problems properly. This patch adds an "added" flag to the net2272 structure to indicate whether or not the gadget has been registered (and thus whether or not to call usb_del_gadget()), and it fixes the deallocation issues by calling usb_put_gadget() at the appropriate places. A similar memory leak issue, apparently never before recognized, stems from the fact that the driver never initializes the drvdata field in the gadget's embedded struct device! Evidently this wasn't noticed because the pointer is only ever used as an argument to kfree(), which doesn't mind getting called with a NULL pointer. In fact, the drvdata for gadget device will be written by usb_composite_dev structure if any gadget class is loaded, so it needs to use usb_gadget structure to get net2272 private data. CC: Anton Vasilyev CC: Evgeny Novikov CC: Benjamin Herrenschmidt Signed-off-by: Alan Stern --- Changes from RFC: - Using usb_gadget structure to get net2272 private data, and update commit log accoringly. drivers/usb/gadget/udc/net2272.c | 25 +++++++++++++++---------- drivers/usb/gadget/udc/net2272.h | 1 + 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/drivers/usb/gadget/udc/net2272.c b/drivers/usb/gadget/udc/net2272.c index fbbe62513545..0168d76d75b8 100644 --- a/drivers/usb/gadget/udc/net2272.c +++ b/drivers/usb/gadget/udc/net2272.c @@ -2196,7 +2196,10 @@ static int net2272_present(struct net2272 *dev) static void net2272_gadget_release(struct device *_dev) { - struct net2272 *dev = dev_get_drvdata(_dev); + struct usb_gadget *gadget = container_of(_dev, + struct usb_gadget, dev); + struct net2272 *dev = container_of(gadget, struct net2272, gadget); + kfree(dev); } @@ -2205,7 +2208,8 @@ net2272_gadget_release(struct device *_dev) static void net2272_remove(struct net2272 *dev) { - usb_del_gadget_udc(&dev->gadget); + if (dev->added) + usb_del_gadget(&dev->gadget); free_irq(dev->irq, dev); iounmap(dev->base_addr); device_remove_file(dev->dev, &dev_attr_registers); @@ -2235,6 +2239,7 @@ static struct net2272 *net2272_probe_init(struct device *dev, unsigned int irq) /* the "gadget" abstracts/virtualizes the controller */ ret->gadget.name = driver_name; + usb_initialize_gadget(dev, &ret->gadget, net2272_gadget_release); return ret; } @@ -2273,10 +2278,10 @@ net2272_probe_fin(struct net2272 *dev, unsigned int irqflags) if (ret) goto err_irq; - ret = usb_add_gadget_udc_release(dev->dev, &dev->gadget, - net2272_gadget_release); + ret = usb_add_gadget(&dev->gadget); if (ret) goto err_add_udc; + dev->added = 1; return 0; @@ -2449,7 +2454,7 @@ net2272_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) if (pci_enable_device(pdev) < 0) { ret = -ENODEV; - goto err_free; + goto err_put; } pci_set_master(pdev); @@ -2472,8 +2477,8 @@ net2272_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) err_pci: pci_disable_device(pdev); - err_free: - kfree(dev); + err_put: + usb_put_gadget(&dev->gadget); return ret; } @@ -2534,7 +2539,7 @@ net2272_pci_remove(struct pci_dev *pdev) pci_disable_device(pdev); - kfree(dev); + usb_put_gadget(&dev->gadget); } /* Table of matching PCI IDs */ @@ -2647,7 +2652,7 @@ net2272_plat_probe(struct platform_device *pdev) err_req: release_mem_region(base, len); err: - kfree(dev); + usb_put_gadget(&dev->gadget); return ret; } @@ -2662,7 +2667,7 @@ net2272_plat_remove(struct platform_device *pdev) release_mem_region(pdev->resource[0].start, resource_size(&pdev->resource[0])); - kfree(dev); + usb_put_gadget(&dev->gadget); return 0; } diff --git a/drivers/usb/gadget/udc/net2272.h b/drivers/usb/gadget/udc/net2272.h index 87d0ab9ffeeb..c669308111c2 100644 --- a/drivers/usb/gadget/udc/net2272.h +++ b/drivers/usb/gadget/udc/net2272.h @@ -441,6 +441,7 @@ struct net2272 { unsigned protocol_stall:1, softconnect:1, wakeup:1, + added:1, dma_eot_polarity:1, dma_dack_polarity:1, dma_dreq_polarity:1, From patchwork Fri Aug 7 09:41:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 11705323 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 79F9113B6 for ; Fri, 7 Aug 2020 09:43:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 50522221E5 for ; Fri, 7 Aug 2020 09:43:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="gXAyOBvE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727083AbgHGJnN (ORCPT ); Fri, 7 Aug 2020 05:43:13 -0400 Received: from mail-eopbgr50089.outbound.protection.outlook.com ([40.107.5.89]:59671 "EHLO EUR03-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727081AbgHGJnN (ORCPT ); Fri, 7 Aug 2020 05:43:13 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Dcr97cSC7boA3TcRSuRnbwPwszmWVbbr2gTMBSdixVIoUCbolZ0CdM+XA0q8J2DyRvHx9/7L9/3pn3LEQuyrdAqTLqEYlCjU1Tkj8lBEeW8GViturIIXx8etJz2fpjNf6lhO+jA4g2OrHjzSV692wpfN4NSBtY19fzMx0R0Hh5NNG6pnNm3EoEg+Fqr+KGxmOU2TYTZHBInfwBk+H1LdKrcnVrdjyugLAF6ixAsK32lEJv08sQ9fxY74Dp+ICZLRar6610cMKfrz+RtcK58aP9KNwfWWkw63mi6uEUo1QjGJQeEF1MxAbldDwcBWYk76074yGF5XMSfMWdvgUST/rA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hgK/3fQr8NwvRa75TJlO2+NlrExsY07aedE1ptpH0Ts=; b=HgUz91mGf8jC3WPTgpx20tAcg8FFqaX9cVDBtmq3qNptN4RBUSARsD0AX2cY3CMCsY4TvENMQeW6vaYUsPfXKvryk8K02emU6B3SilT4xDLb4CPpAU7zjg/blX7ArGUjsxy4hc73GoGf1sSPLGDuKolx1HT6ZTarlnk2YdL/Sf5SBlPqfuMKCR+H7HNV7E6tvNATKXfp39LVx5raQaEvGCxTG0+aaucoMw9Tn3J94rQaMm3BxIMcoy9pErrmf+18cebacYGEG4DZf5rVnizpanSpO4wDX863KLc+lFswvaCajnP2V0m/DwqZYPMJZg9R3SJ7MkmE0ZkIDF7KizRIlQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hgK/3fQr8NwvRa75TJlO2+NlrExsY07aedE1ptpH0Ts=; b=gXAyOBvEknf2fRh/t9E6pgRf6+SdmTa9e/pUy1//Draj8adHnUgCZTJlSh3vOCpToSdQj/jBXcbWtvPLZZUTxR4hxe1CYK0m/BhTAvz29OqUhOHZALITkDNdhOUWR++WWp/46FnQspXARBbl+kLmfTikyv1nNUr8Oqzf8Ug9CLw= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=nxp.com; Received: from AM7PR04MB7157.eurprd04.prod.outlook.com (2603:10a6:20b:118::20) by AM7PR04MB7077.eurprd04.prod.outlook.com (2603:10a6:20b:11c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 09:42:54 +0000 Received: from AM7PR04MB7157.eurprd04.prod.outlook.com ([fe80::ed7f:8755:5994:7fcf]) by AM7PR04MB7157.eurprd04.prod.outlook.com ([fe80::ed7f:8755:5994:7fcf%5]) with mapi id 15.20.3261.020; Fri, 7 Aug 2020 09:42:54 +0000 From: Peter Chen To: balbi@kernel.org Cc: linux-usb@vger.kernel.org, linux-imx@nxp.com, stern@rowland.harvard.edu, gregkh@linuxfoundation.org, Peter Chen Subject: [PATCH 4/6] usb: cdns3: gadget: fix possible memory leak Date: Fri, 7 Aug 2020 17:41:49 +0800 Message-Id: <20200807094151.13526-5-peter.chen@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200807094151.13526-1-peter.chen@nxp.com> References: <20200807094151.13526-1-peter.chen@nxp.com> X-ClientProxiedBy: SG2PR03CA0113.apcprd03.prod.outlook.com (2603:1096:4:91::17) To AM7PR04MB7157.eurprd04.prod.outlook.com (2603:10a6:20b:118::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from b29397-desktop.ap.freescale.net (119.31.174.67) by SG2PR03CA0113.apcprd03.prod.outlook.com (2603:1096:4:91::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.5 via Frontend Transport; Fri, 7 Aug 2020 09:42:52 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [119.31.174.67] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: f69c9631-c406-474a-1e38-08d83ab64235 X-MS-TrafficTypeDiagnostic: AM7PR04MB7077: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: t+7sA2cM3JBaQef1zdoaw8axeIbSmRqgzogtoQK4tSrEzPAvJ3s1smpe6utPqnKJkV3FCg1WMuDm1PNfv8u5zwQHNPlG+30gY/L4rxbkX00/47LK9Y+ozO/dIT28aMUXu/PMwCRvaTOacJQWIZgdmklAl/hp6lqbz8s9lmPBX3gTo3hNyLSV0appt8sCyjt9TyISqBFYe3J+6VvC7atMJ+ZUpAXgyymCNyCCWxu0sFaGrppG7vcvSQOV10LLnXsDA+8ioqyj7mA7a0rkeGW5DZg6xsQALon0PaK7SZr7lfwdt2/DnG7O6IZ78F+hnDV7 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM7PR04MB7157.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(366004)(346002)(136003)(39860400002)(376002)(396003)(956004)(2616005)(5660300002)(86362001)(16526019)(44832011)(6486002)(6666004)(186003)(66556008)(66946007)(4326008)(6512007)(26005)(52116002)(8676002)(83380400001)(1076003)(66476007)(36756003)(8936002)(478600001)(6916009)(316002)(6506007)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 0bnolqQbqCqqAH0di6OKlwVO42UMRzsiuLQw+oAMN8zfG3oi+3ytlVxEgxkg9qrisLSJHll6YDEZAI2uL73tR6n9SeS1ulP1iN2NdK9NYMPHm7dNPuKBoTAqiAKFON9VIQLSTaEz5bnq5pQq8M2rPPlGWEgTBZl5yJ5uNV0umrzlPBFIG6Q+ArAEUiaaxAejx5izCi5/emUsX3LQFn81cRAwa8zclvvkj0+58CiM2FlVlFmwKJwuAjJShp3VkmB9z4psZTWMu03vKvFY+J5W+FShI9DpBvOAx0QIaZljz0Y5iTWKAcXTp253iUzjK3fQto0uvARYGGZ3G9rLHpmjX+VEmBrN0zO/10MGJa24EpSnIYgyYKWqz51p5MhCHUnU6GU6PQRBEfTj7oWQC4nwUVLi4un7nxZLZd8sxSM41Tss/j8+AQPGC4w8zaVRzEHuW2br612n3TFp4qRGcLu1bNBNNJOQmXD2euxhcIqU3bexZwEhXOD/zlc5R0UGIcbcCZTqL4MI0ukTBVsvbZVus+FoNrf8gydcmgeZ1Aiff3eNnmu1aZjVsUP2nqEALi6sz0tCoTnV3kLgo4BHRTL/V8K6K3ktYGUfedp39n3DzNSwVwGm5uXKLRoHNlnyig/f+EqlgaNjSWW5gj2w2l4Vfw== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f69c9631-c406-474a-1e38-08d83ab64235 X-MS-Exchange-CrossTenant-AuthSource: AM7PR04MB7157.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 09:42:54.3824 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: JHPZEa+862q7KiTbsBaQYCMqMmkpv1W1L+V0/72LOJGkW0Gulqj7bzsKxBfxdVOYPOOkySSNTL9pKOtwrcssjg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR04MB7077 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org If cdns3_gadget_start is failed, it never frees cdns3_device structure. Meanwhile, there is no release function for gadget device, it causes there is no sync with driver core. To fix this, we add release function for gadget device, and free cdns3_device structure at there. Meanwhile, With the new UDC core APIs, we could work with driver core better to handle memory leak issue. Cc: Greg Kroah-Hartman Cc: Alan Stern Signed-off-by: Peter Chen --- drivers/usb/cdns3/gadget.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c index 814338476a2d..924f2bd3d40c 100644 --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -3043,6 +3043,15 @@ static int cdns3_init_eps(struct cdns3_device *priv_dev) return -ENOMEM; } +static void cdns3_gadget_release(struct device *dev) +{ + struct usb_gadget *gadget = container_of(dev, struct usb_gadget, dev); + struct cdns3_device *priv_dev = container_of(gadget, + struct cdns3_device, gadget); + + kfree(priv_dev); +} + void cdns3_gadget_exit(struct cdns3 *cdns) { struct cdns3_device *priv_dev; @@ -3054,7 +3063,7 @@ void cdns3_gadget_exit(struct cdns3 *cdns) pm_runtime_mark_last_busy(cdns->dev); pm_runtime_put_autosuspend(cdns->dev); - usb_del_gadget_udc(&priv_dev->gadget); + usb_del_gadget(&priv_dev->gadget); cdns3_free_all_eps(priv_dev); @@ -3074,7 +3083,7 @@ void cdns3_gadget_exit(struct cdns3 *cdns) priv_dev->setup_dma); kfree(priv_dev->zlp_buf); - kfree(priv_dev); + usb_put_gadget(&priv_dev->gadget); cdns->gadget_dev = NULL; cdns3_drd_switch_gadget(cdns, 0); } @@ -3089,6 +3098,8 @@ static int cdns3_gadget_start(struct cdns3 *cdns) if (!priv_dev) return -ENOMEM; + usb_initialize_gadget(cdns->dev, &priv_dev->gadget, + cdns3_gadget_release); cdns->gadget_dev = priv_dev; priv_dev->sysdev = cdns->dev; priv_dev->dev = cdns->dev; @@ -3176,10 +3187,9 @@ static int cdns3_gadget_start(struct cdns3 *cdns) } /* add USB gadget device */ - ret = usb_add_gadget_udc(priv_dev->dev, &priv_dev->gadget); + ret = usb_add_gadget(&priv_dev->gadget); if (ret < 0) { - dev_err(priv_dev->dev, - "Failed to register USB device controller\n"); + dev_err(priv_dev->dev, "Failed to add gadget\n"); goto err4; } @@ -3192,6 +3202,7 @@ static int cdns3_gadget_start(struct cdns3 *cdns) err2: cdns3_free_all_eps(priv_dev); err1: + usb_put_gadget(&priv_dev->gadget); cdns->gadget_dev = NULL; return ret; } From patchwork Fri Aug 7 09:41:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 11705325 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2184013B6 for ; Fri, 7 Aug 2020 09:43:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F3406221E5 for ; Fri, 7 Aug 2020 09:43:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="NkeIgScD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727853AbgHGJnU (ORCPT ); Fri, 7 Aug 2020 05:43:20 -0400 Received: from mail-eopbgr50089.outbound.protection.outlook.com ([40.107.5.89]:59671 "EHLO EUR03-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727081AbgHGJnT (ORCPT ); Fri, 7 Aug 2020 05:43:19 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dSWqMGiM4pr602Dm6vGj++hErajhhBFi8MJ2dQ+znAzP8HJ7vRX7PDfaD5B7s77cNkc+s2JYr8fel6DJrX/6liLOtNyAa9DdyqjMy4euOa36hcvK+21YxG7f6QmG2DTjvLkp5ZaXtgjc0+O2b4qEXIRmOfMcetdnkkUqXyH9WutPsfnOIWk1PP+f9SP8w1nMYZfaE2VuhmcJkfEf71Bag5ZzlLbvlVbJC+2YBqdAb+aQ18WPvT4dd8bN8Li6xmAOt/t7pv9NB04U10rADDyS+S4uaxfFhkNFquqp4ApLr4wbq+x6FYhMS9pPPB1xLK6L3TzRDAXy8lI5RLji8BZ0gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CswVPUm2JYS5XY3K2J+WRO9jwFd6TVw61Nxs/gW377g=; b=aUBLECYNcTUy6B9zAFlsgGFkDn859J7HlN8O+B2lqx/Pe1fqyn8b7nSZ4tLEzgxcn8eMJ+lYadiuBF4IZqH4NvuAKeZ4FtmS6BUkaDETAeux3FFa5zw0uV5pP1WPUurMnal8gC1r4BFiTFppp9VEh0wro7QQnFo2Sp4lMLV7NehSXqrgNtMRUoaeSc6NU5dYEAKIzzDDzdk0yr+I19HPyreLu2XxJFJn4iZ3N0rOGkgOiliYlQVG8IYEbxMO+s4Juyqur3cX6owPMIfFQ3X0slZSVinSGqRqgmrIQDkSsBTz6CHR9/1YTfcwLMSxMqHprRXU80+vhWaXKnOowxpPqg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CswVPUm2JYS5XY3K2J+WRO9jwFd6TVw61Nxs/gW377g=; b=NkeIgScDZMKngysinenmrbqOhHkeszz5v+kQBForaScybVRIb9FXkG45YnNtNYCw2eD5DMMBuUymXWNFkrsBdNKsIGkPxc3aAlL+0dhWn1Mgz1rlCFwAynHgQwifyeDrUYunn94o6RBd/Vn00cK+X1iW6bXavMfWAPu8eqg/qYU= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=nxp.com; Received: from AM7PR04MB7157.eurprd04.prod.outlook.com (2603:10a6:20b:118::20) by AM7PR04MB7077.eurprd04.prod.outlook.com (2603:10a6:20b:11c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 09:42:57 +0000 Received: from AM7PR04MB7157.eurprd04.prod.outlook.com ([fe80::ed7f:8755:5994:7fcf]) by AM7PR04MB7157.eurprd04.prod.outlook.com ([fe80::ed7f:8755:5994:7fcf%5]) with mapi id 15.20.3261.020; Fri, 7 Aug 2020 09:42:56 +0000 From: Peter Chen To: balbi@kernel.org Cc: linux-usb@vger.kernel.org, linux-imx@nxp.com, stern@rowland.harvard.edu, gregkh@linuxfoundation.org, Peter Chen Subject: [PATCH 5/6] usb: dwc3: allocate gadget structure dynamically Date: Fri, 7 Aug 2020 17:41:50 +0800 Message-Id: <20200807094151.13526-6-peter.chen@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200807094151.13526-1-peter.chen@nxp.com> References: <20200807094151.13526-1-peter.chen@nxp.com> X-ClientProxiedBy: SG2PR03CA0113.apcprd03.prod.outlook.com (2603:1096:4:91::17) To AM7PR04MB7157.eurprd04.prod.outlook.com (2603:10a6:20b:118::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from b29397-desktop.ap.freescale.net (119.31.174.67) by SG2PR03CA0113.apcprd03.prod.outlook.com (2603:1096:4:91::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.5 via Frontend Transport; Fri, 7 Aug 2020 09:42:54 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [119.31.174.67] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 341416f9-af28-4810-68f5-08d83ab64390 X-MS-TrafficTypeDiagnostic: AM7PR04MB7077: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:352; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RgPCwFFbAlqGOUFPPvhWPPispX6xqskMZsC+057WgFTeRSF/rjljYPCrbWILBPfLOpHshxB0k3tDe+UJgZ+mFTvdhm3rbNbgwMDzvLE9fZQ9dV51VXyZZThjK7SSv56B7qvHeJRPsSRbpTX/I01J23HPsixQSGCNKvXcMq423U9SSmwm+SdWTAHFtTgcyYeD83q91NfYzRc05mmmZFI1U+oE9wQsvqkdPtx++JvWO3U4ZLbqA0ULMuYjQsZdHioRONpV/+zZ4yshkYKA7DypifrXaTq4BSZowalahOxLNaJF41n621WlO9z4H/WGBE8T0WdVzdGSmUlJBiVOvyGRBQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM7PR04MB7157.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(366004)(346002)(136003)(39860400002)(376002)(396003)(956004)(2616005)(5660300002)(86362001)(16526019)(44832011)(6486002)(6666004)(186003)(66556008)(66946007)(4326008)(6512007)(26005)(52116002)(8676002)(83380400001)(1076003)(19627235002)(66476007)(30864003)(36756003)(8936002)(478600001)(6916009)(316002)(6506007)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: z+h1gs/PP9YFyWN+eYmiGnPMQ+SmkYmpqVH87A29SgaDfuYeuWH9HtF5J02+62oNViZ/M6gmDa9jxkWH3ThCqdP4C9Ws9j9gIVpl9iVXX4VPesvZjTfC3uzGtmTm5H/q6rrsg7Yt7QSuiqYl+A4BjczFzPDy4q772NTliqF0cLGA7gzWJoZyJlHeQX8pb7WUH6m+mACET57AL3K1qvVlAl6zqqwCoynok9UViZ5LuGtH8jA0+ZS5UJDxUJdIw2JJ/D/V4pr/QFKQ9qrBiQcESyssMo6ph0I4+fQoqfNUayplH7TDr7lMGQBaOpVVnc15aHsY2o6u7VCFvtujvpbqJNGZn/wyYSOcFyc5z1Qa+Zqv2Mg9DmY1O4ILAKutbwSI9GM2XhsGxzGu3pUA1IhPaNSAEqz2hVPsA+gCnuQe3JAM379W+RPFlopaxcDGRJ4E+mUmZ1wP8svnqzSZVwNB9Nyf032GS3i9s165e3iN//kPl+OpGwkXO+XQgBH69gVj0QcwKzujGgj1LtTXMA+7oet253MmaBXiXbSbwOcjVs7/C38szDVO+Tid/wUuG4p9CnPzwyodgwyLNax6q3HngN4+SAkNlVCTPaxDvsGH+vx5gUKfNSYePNbCyzlFqTJHojCW1mNv70WbLirB6Ubz8A== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 341416f9-af28-4810-68f5-08d83ab64390 X-MS-Exchange-CrossTenant-AuthSource: AM7PR04MB7157.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 09:42:56.9003 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: DUtSiLLjE5/Pd4FSajVrLKY4y25Z76Jo7N7HyBtrLmTMw/WJXyxcbGY8So92WH2CoDvVMTX15W8AlFtsykUHcw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR04MB7077 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The current code uses commit fac323471df6 ("usb: udc: allow adding and removing the same gadget device") as the workaround to let the gadget device is re-used, but it is not allowed from driver core point. In this commit, we allocate gadget structure dynamically, and free it at its release function. Since the gadget device's driver_data has already occupied by usb_composite_dev structure, we have to use gadget device's platform data to store dwc3 structure. Cc: Greg Kroah-Hartman Cc: Alan Stern Signed-off-by: Peter Chen --- drivers/usb/dwc3/core.h | 2 +- drivers/usb/dwc3/ep0.c | 26 +++++----- drivers/usb/dwc3/gadget.c | 106 ++++++++++++++++++++++---------------- drivers/usb/dwc3/gadget.h | 2 +- 4 files changed, 77 insertions(+), 59 deletions(-) diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 18c7a9907679..48301d950068 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -1102,7 +1102,7 @@ struct dwc3 { struct dwc3_event_buffer *ev_buf; struct dwc3_ep *eps[DWC3_ENDPOINTS_NUM]; - struct usb_gadget gadget; + struct usb_gadget *gadget; struct usb_gadget_driver *gadget_driver; struct clk_bulk_data *clks; diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c index 8dd69728add3..1799bd19bf6f 100644 --- a/drivers/usb/dwc3/ep0.c +++ b/drivers/usb/dwc3/ep0.c @@ -131,7 +131,7 @@ static int __dwc3_gadget_ep0_queue(struct dwc3_ep *dep, direction = !dwc->ep0_expect_in; dwc->delayed_status = false; - usb_gadget_set_state(&dwc->gadget, USB_STATE_CONFIGURED); + usb_gadget_set_state(dwc->gadget, USB_STATE_CONFIGURED); if (dwc->ep0state == EP0_STATUS_PHASE) __dwc3_ep0_do_control_status(dwc, dwc->eps[direction]); @@ -325,7 +325,7 @@ static int dwc3_ep0_handle_status(struct dwc3 *dwc, /* * LTM will be set once we know how to set this in HW. */ - usb_status |= dwc->gadget.is_selfpowered; + usb_status |= dwc->gadget->is_selfpowered; if ((dwc->speed == DWC3_DSTS_SUPERSPEED) || (dwc->speed == DWC3_DSTS_SUPERSPEED_PLUS)) { @@ -450,7 +450,7 @@ static int dwc3_ep0_handle_device(struct dwc3 *dwc, wValue = le16_to_cpu(ctrl->wValue); wIndex = le16_to_cpu(ctrl->wIndex); - state = dwc->gadget.state; + state = dwc->gadget->state; switch (wValue) { case USB_DEVICE_REMOTE_WAKEUP: @@ -559,7 +559,7 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc, static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) { - enum usb_device_state state = dwc->gadget.state; + enum usb_device_state state = dwc->gadget->state; u32 addr; u32 reg; @@ -580,9 +580,9 @@ static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) dwc3_writel(dwc->regs, DWC3_DCFG, reg); if (addr) - usb_gadget_set_state(&dwc->gadget, USB_STATE_ADDRESS); + usb_gadget_set_state(dwc->gadget, USB_STATE_ADDRESS); else - usb_gadget_set_state(&dwc->gadget, USB_STATE_DEFAULT); + usb_gadget_set_state(dwc->gadget, USB_STATE_DEFAULT); return 0; } @@ -592,14 +592,14 @@ static int dwc3_ep0_delegate_req(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) int ret; spin_unlock(&dwc->lock); - ret = dwc->gadget_driver->setup(&dwc->gadget, ctrl); + ret = dwc->gadget_driver->setup(dwc->gadget, ctrl); spin_lock(&dwc->lock); return ret; } static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) { - enum usb_device_state state = dwc->gadget.state; + enum usb_device_state state = dwc->gadget->state; u32 cfg; int ret; u32 reg; @@ -622,7 +622,7 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) * to change the state on the next usb_ep_queue() */ if (ret == 0) - usb_gadget_set_state(&dwc->gadget, + usb_gadget_set_state(dwc->gadget, USB_STATE_CONFIGURED); /* @@ -641,7 +641,7 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) case USB_STATE_CONFIGURED: ret = dwc3_ep0_delegate_req(dwc, ctrl); if (!cfg && !ret) - usb_gadget_set_state(&dwc->gadget, + usb_gadget_set_state(dwc->gadget, USB_STATE_ADDRESS); break; default: @@ -697,7 +697,7 @@ static void dwc3_ep0_set_sel_cmpl(struct usb_ep *ep, struct usb_request *req) static int dwc3_ep0_set_sel(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) { struct dwc3_ep *dep; - enum usb_device_state state = dwc->gadget.state; + enum usb_device_state state = dwc->gadget->state; u16 wLength; if (state == USB_STATE_DEFAULT) @@ -741,7 +741,7 @@ static int dwc3_ep0_set_isoch_delay(struct dwc3 *dwc, struct usb_ctrlrequest *ct if (wIndex || wLength) return -EINVAL; - dwc->gadget.isoch_delay = wValue; + dwc->gadget->isoch_delay = wValue; return 0; } @@ -1102,7 +1102,7 @@ static void dwc3_ep0_xfernotready(struct dwc3 *dwc, */ if (!list_empty(&dep->pending_list)) { dwc->delayed_status = false; - usb_gadget_set_state(&dwc->gadget, + usb_gadget_set_state(dwc->gadget, USB_STATE_CONFIGURED); dwc3_ep0_do_control_status(dwc, event); } diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 0b59b2f1cf26..a6d60f53747d 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -290,7 +290,7 @@ int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd, * * DWC_usb3 3.30a and DWC_usb31 1.90a programming guide section 3.2.2 */ - if (dwc->gadget.speed <= USB_SPEED_HIGH) { + if (dwc->gadget->speed <= USB_SPEED_HIGH) { reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); if (unlikely(reg & DWC3_GUSB2PHYCFG_SUSPHY)) { saved_config |= DWC3_GUSB2PHYCFG_SUSPHY; @@ -422,7 +422,7 @@ static int dwc3_send_clear_stall_ep_cmd(struct dwc3_ep *dep) */ if (dep->direction && !DWC3_VER_IS_PRIOR(DWC3, 260A) && - (dwc->gadget.speed >= USB_SPEED_SUPER)) + (dwc->gadget->speed >= USB_SPEED_SUPER)) cmd |= DWC3_DEPCMD_CLEARPENDIN; memset(¶ms, 0, sizeof(params)); @@ -562,7 +562,7 @@ static int dwc3_gadget_set_ep_config(struct dwc3_ep *dep, unsigned int action) | DWC3_DEPCFG_MAX_PACKET_SIZE(usb_endpoint_maxp(desc)); /* Burst size is only needed in SuperSpeed mode */ - if (dwc->gadget.speed >= USB_SPEED_SUPER) { + if (dwc->gadget->speed >= USB_SPEED_SUPER) { u32 burst = dep->endpoint.maxburst; params.param0 |= DWC3_DEPCFG_BURST_SIZE(burst - 1); } @@ -947,7 +947,7 @@ static void __dwc3_prepare_one_trb(struct dwc3_ep *dep, struct dwc3_trb *trb, unsigned no_interrupt, unsigned is_last) { struct dwc3 *dwc = dep->dwc; - struct usb_gadget *gadget = &dwc->gadget; + struct usb_gadget *gadget = dwc->gadget; enum usb_device_speed speed = gadget->speed; trb->size = DWC3_TRB_SIZE_LENGTH(length); @@ -1476,7 +1476,7 @@ static int __dwc3_gadget_start_isoc(struct dwc3_ep *dep) if (!dwc->dis_start_transfer_quirk && (DWC3_VER_IS_PRIOR(DWC31, 170A) || DWC3_VER_TYPE_IS_WITHIN(DWC31, 170A, EA01, EA06))) { - if (dwc->gadget.speed <= USB_SPEED_HIGH && dep->direction) + if (dwc->gadget->speed <= USB_SPEED_HIGH && dep->direction) return dwc3_gadget_start_isoc_quirk(dep); } @@ -2160,7 +2160,7 @@ static int dwc3_gadget_start(struct usb_gadget *g, spin_lock_irqsave(&dwc->lock, flags); if (dwc->gadget_driver) { dev_err(dwc->dev, "%s is already bound to %s\n", - dwc->gadget.name, + dwc->gadget->name, dwc->gadget_driver->driver.name); ret = -EBUSY; goto err1; @@ -2332,7 +2332,7 @@ static int dwc3_gadget_init_control_endpoint(struct dwc3_ep *dep) dep->endpoint.maxburst = 1; dep->endpoint.ops = &dwc3_gadget_ep0_ops; if (!dep->direction) - dwc->gadget.ep0 = &dep->endpoint; + dwc->gadget->ep0 = &dep->endpoint; dep->endpoint.caps.type_control = true; @@ -2378,7 +2378,7 @@ static int dwc3_gadget_init_in_endpoint(struct dwc3_ep *dep) dep->endpoint.max_streams = 15; dep->endpoint.ops = &dwc3_gadget_ep_ops; list_add_tail(&dep->endpoint.ep_list, - &dwc->gadget.ep_list); + &dwc->gadget->ep_list); dep->endpoint.caps.type_iso = true; dep->endpoint.caps.type_bulk = true; dep->endpoint.caps.type_int = true; @@ -2427,7 +2427,7 @@ static int dwc3_gadget_init_out_endpoint(struct dwc3_ep *dep) dep->endpoint.max_streams = 15; dep->endpoint.ops = &dwc3_gadget_ep_ops; list_add_tail(&dep->endpoint.ep_list, - &dwc->gadget.ep_list); + &dwc->gadget->ep_list); dep->endpoint.caps.type_iso = true; dep->endpoint.caps.type_bulk = true; dep->endpoint.caps.type_int = true; @@ -2488,7 +2488,7 @@ static int dwc3_gadget_init_endpoints(struct dwc3 *dwc, u8 total) { u8 epnum; - INIT_LIST_HEAD(&dwc->gadget.ep_list); + INIT_LIST_HEAD(&dwc->gadget->ep_list); for (epnum = 0; epnum < total; epnum++) { int ret; @@ -2924,7 +2924,7 @@ static void dwc3_disconnect_gadget(struct dwc3 *dwc) { if (dwc->gadget_driver && dwc->gadget_driver->disconnect) { spin_unlock(&dwc->lock); - dwc->gadget_driver->disconnect(&dwc->gadget); + dwc->gadget_driver->disconnect(dwc->gadget); spin_lock(&dwc->lock); } } @@ -2933,7 +2933,7 @@ static void dwc3_suspend_gadget(struct dwc3 *dwc) { if (dwc->gadget_driver && dwc->gadget_driver->suspend) { spin_unlock(&dwc->lock); - dwc->gadget_driver->suspend(&dwc->gadget); + dwc->gadget_driver->suspend(dwc->gadget); spin_lock(&dwc->lock); } } @@ -2942,7 +2942,7 @@ static void dwc3_resume_gadget(struct dwc3 *dwc) { if (dwc->gadget_driver && dwc->gadget_driver->resume) { spin_unlock(&dwc->lock); - dwc->gadget_driver->resume(&dwc->gadget); + dwc->gadget_driver->resume(dwc->gadget); spin_lock(&dwc->lock); } } @@ -2952,9 +2952,9 @@ static void dwc3_reset_gadget(struct dwc3 *dwc) if (!dwc->gadget_driver) return; - if (dwc->gadget.speed != USB_SPEED_UNKNOWN) { + if (dwc->gadget->speed != USB_SPEED_UNKNOWN) { spin_unlock(&dwc->lock); - usb_gadget_udc_reset(&dwc->gadget, dwc->gadget_driver); + usb_gadget_udc_reset(dwc->gadget, dwc->gadget_driver); spin_lock(&dwc->lock); } } @@ -3055,9 +3055,9 @@ static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc) dwc3_disconnect_gadget(dwc); - dwc->gadget.speed = USB_SPEED_UNKNOWN; + dwc->gadget->speed = USB_SPEED_UNKNOWN; dwc->setup_packet_pending = false; - usb_gadget_set_state(&dwc->gadget, USB_STATE_NOTATTACHED); + usb_gadget_set_state(dwc->gadget, USB_STATE_NOTATTACHED); dwc->connected = false; } @@ -3136,8 +3136,8 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc) switch (speed) { case DWC3_DSTS_SUPERSPEED_PLUS: dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512); - dwc->gadget.ep0->maxpacket = 512; - dwc->gadget.speed = USB_SPEED_SUPER_PLUS; + dwc->gadget->ep0->maxpacket = 512; + dwc->gadget->speed = USB_SPEED_SUPER_PLUS; break; case DWC3_DSTS_SUPERSPEED: /* @@ -3157,27 +3157,27 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc) dwc3_gadget_reset_interrupt(dwc); dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512); - dwc->gadget.ep0->maxpacket = 512; - dwc->gadget.speed = USB_SPEED_SUPER; + dwc->gadget->ep0->maxpacket = 512; + dwc->gadget->speed = USB_SPEED_SUPER; break; case DWC3_DSTS_HIGHSPEED: dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(64); - dwc->gadget.ep0->maxpacket = 64; - dwc->gadget.speed = USB_SPEED_HIGH; + dwc->gadget->ep0->maxpacket = 64; + dwc->gadget->speed = USB_SPEED_HIGH; break; case DWC3_DSTS_FULLSPEED: dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(64); - dwc->gadget.ep0->maxpacket = 64; - dwc->gadget.speed = USB_SPEED_FULL; + dwc->gadget->ep0->maxpacket = 64; + dwc->gadget->speed = USB_SPEED_FULL; break; case DWC3_DSTS_LOWSPEED: dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(8); - dwc->gadget.ep0->maxpacket = 8; - dwc->gadget.speed = USB_SPEED_LOW; + dwc->gadget->ep0->maxpacket = 8; + dwc->gadget->speed = USB_SPEED_LOW; break; } - dwc->eps[1]->endpoint.maxpacket = dwc->gadget.ep0->maxpacket; + dwc->eps[1]->endpoint.maxpacket = dwc->gadget->ep0->maxpacket; /* Enable USB2 LPM Capability */ @@ -3245,7 +3245,7 @@ static void dwc3_gadget_wakeup_interrupt(struct dwc3 *dwc) if (dwc->gadget_driver && dwc->gadget_driver->resume) { spin_unlock(&dwc->lock); - dwc->gadget_driver->resume(&dwc->gadget); + dwc->gadget_driver->resume(dwc->gadget); spin_lock(&dwc->lock); } } @@ -3416,7 +3416,7 @@ static void dwc3_gadget_interrupt(struct dwc3 *dwc, * Ignore suspend event until the gadget enters into * USB_STATE_CONFIGURED state. */ - if (dwc->gadget.state >= USB_STATE_CONFIGURED) + if (dwc->gadget->state >= USB_STATE_CONFIGURED) dwc3_gadget_suspend_interrupt(dwc, event->event_info); } @@ -3591,6 +3591,13 @@ static int dwc3_gadget_get_irq(struct dwc3 *dwc) return irq; } +static void dwc_gadget_release(struct device *dev) +{ + struct usb_gadget *gadget = container_of(dev, struct usb_gadget, dev); + + kfree(gadget); +} + /** * dwc3_gadget_init - initializes gadget related registers * @dwc: pointer to our controller context structure @@ -3601,6 +3608,7 @@ int dwc3_gadget_init(struct dwc3 *dwc) { int ret; int irq; + struct device *dev; irq = dwc3_gadget_get_irq(dwc); if (irq < 0) { @@ -3633,12 +3641,21 @@ int dwc3_gadget_init(struct dwc3 *dwc) } init_completion(&dwc->ep0_in_setup); + dwc->gadget = kzalloc(sizeof(struct usb_gadget), GFP_KERNEL); + if (!dwc->gadget) { + ret = -ENOMEM; + goto err3; + } - dwc->gadget.ops = &dwc3_gadget_ops; - dwc->gadget.speed = USB_SPEED_UNKNOWN; - dwc->gadget.sg_supported = true; - dwc->gadget.name = "dwc3-gadget"; - dwc->gadget.lpm_capable = true; + + usb_initialize_gadget(dwc->dev, dwc->gadget, dwc_gadget_release); + dev = &dwc->gadget->dev; + dev->platform_data = dwc; + dwc->gadget->ops = &dwc3_gadget_ops; + dwc->gadget->speed = USB_SPEED_UNKNOWN; + dwc->gadget->sg_supported = true; + dwc->gadget->name = "dwc3-gadget"; + dwc->gadget->lpm_capable = true; /* * FIXME We might be setting max_speed to dev, "changing max_speed on rev %08x\n", dwc->revision); - dwc->gadget.max_speed = dwc->maximum_speed; + dwc->gadget->max_speed = dwc->maximum_speed; /* * REVISIT: Here we should clear all pending IRQs to be @@ -3670,21 +3687,22 @@ int dwc3_gadget_init(struct dwc3 *dwc) ret = dwc3_gadget_init_endpoints(dwc, dwc->num_eps); if (ret) - goto err3; + goto err4; - ret = usb_add_gadget_udc(dwc->dev, &dwc->gadget); + ret = usb_add_gadget(dwc->gadget); if (ret) { - dev_err(dwc->dev, "failed to register udc\n"); - goto err4; + dev_err(dwc->dev, "failed to add gadget\n"); + goto err5; } - dwc3_gadget_set_speed(&dwc->gadget, dwc->maximum_speed); + dwc3_gadget_set_speed(dwc->gadget, dwc->maximum_speed); return 0; -err4: +err5: dwc3_gadget_free_endpoints(dwc); - +err4: + usb_put_gadget(dwc->gadget); err3: dma_free_coherent(dwc->sysdev, DWC3_BOUNCE_SIZE, dwc->bounce, dwc->bounce_addr); @@ -3704,7 +3722,7 @@ int dwc3_gadget_init(struct dwc3 *dwc) void dwc3_gadget_exit(struct dwc3 *dwc) { - usb_del_gadget_udc(&dwc->gadget); + usb_del_gadget_udc(dwc->gadget); dwc3_gadget_free_endpoints(dwc); dma_free_coherent(dwc->sysdev, DWC3_BOUNCE_SIZE, dwc->bounce, dwc->bounce_addr); diff --git a/drivers/usb/dwc3/gadget.h b/drivers/usb/dwc3/gadget.h index 24dca3872022..b547db228f1e 100644 --- a/drivers/usb/dwc3/gadget.h +++ b/drivers/usb/dwc3/gadget.h @@ -17,7 +17,7 @@ struct dwc3; #define to_dwc3_ep(ep) (container_of(ep, struct dwc3_ep, endpoint)) -#define gadget_to_dwc(g) (container_of(g, struct dwc3, gadget)) +#define gadget_to_dwc(g) (dev_get_platdata(&g->dev)) /* DEPCFG parameter 1 */ #define DWC3_DEPCFG_INT_NUM(n) (((n) & 0x1f) << 0) From patchwork Fri Aug 7 09:41:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 11705327 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BB76313B6 for ; Fri, 7 Aug 2020 09:43:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A419322C9F for ; Fri, 7 Aug 2020 09:43:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="Q1Ar9mo5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727858AbgHGJnX (ORCPT ); Fri, 7 Aug 2020 05:43:23 -0400 Received: from mail-eopbgr50089.outbound.protection.outlook.com ([40.107.5.89]:59671 "EHLO EUR03-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727816AbgHGJnW (ORCPT ); Fri, 7 Aug 2020 05:43:22 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HY14biX5XbvCpdQwCf5XkJszdNI9/IwtbUAPaRW3ZbrJbVjLQU4gdYezZ3Z9SWKY7gJFBRK1mqUL753BW71e48V25xt86p6paFgWyfW7R0iAVycwXRNdwYFDCQR2P4yPrkNuED+3khrYe8ECqi9cnmOSNQFsdPmKDhq+7FW4NPRmQfUqNWes469ZWs6G1hBvmClE2ApgPMEu+j9H0645eDL+ePzBc0MRPVvuocz5njdYcYkZRwK0PIoqR90jOIbRMSX8dE4gNm+KGeWDm2HIgKDgTf1R8b0ahp5ymgD/rphkg5Zb42/08N7vv26+WyjjafU1pkfsMV3wfPEYmJgT5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yl/iWukT0lrKwuLLCzY7NxE+toQGclgOpMCtHxmD830=; b=XrtxT+f+mzM3PbvKOaqmiyCuKAiXgI6AUqtOOQgh4roFCcJevyi9a9ptWPPBD2VcstXyzdS0yftesejDsdldaUs8B3Jqpzr3Ol0QtSA/nrK34V3+Si2PqSeVg7sTIX+9ReksInhSR0pxXdeMXZ/KJPpITJ1CYIIRRi4ZTysK2+6AFjwsmBXjm9WoVdVfBFrzTCJLOLDvRAd03X0LTnTPtTblOwGj4nZaYNctxBKDxNFQIaPSASzfWKL6zBKkD8Qg2smz8ptH9wX8cGncMmB2VmPGy5Dfo2hCa38WPqGSQsg1GkTgzKNTEAhWUO2wvMWkMLJ+bJLhhW7G4cpDpF9K9Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yl/iWukT0lrKwuLLCzY7NxE+toQGclgOpMCtHxmD830=; b=Q1Ar9mo5xmQZ44yT8w10PR+3d3j5A894CEuOPms4ffRcgv7EnvTOZNrSpkaKxFMzceuNI1yyE5Emdn2Akd6KBL/KZlfIpwz/QfLk5DSNylOoL1SPEK5iWxvtXkWhNf4k04AH0FG9Zh90+FR31NjubU/ps13PWM0S2Qic3kSGxNE= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=nxp.com; Received: from AM7PR04MB7157.eurprd04.prod.outlook.com (2603:10a6:20b:118::20) by AM7PR04MB7077.eurprd04.prod.outlook.com (2603:10a6:20b:11c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 09:42:59 +0000 Received: from AM7PR04MB7157.eurprd04.prod.outlook.com ([fe80::ed7f:8755:5994:7fcf]) by AM7PR04MB7157.eurprd04.prod.outlook.com ([fe80::ed7f:8755:5994:7fcf%5]) with mapi id 15.20.3261.020; Fri, 7 Aug 2020 09:42:59 +0000 From: Peter Chen To: balbi@kernel.org Cc: linux-usb@vger.kernel.org, linux-imx@nxp.com, stern@rowland.harvard.edu, gregkh@linuxfoundation.org, Peter Chen , Roger Quadros Subject: [PATCH 6/6] Revert "usb: udc: allow adding and removing the same gadget device" Date: Fri, 7 Aug 2020 17:41:51 +0800 Message-Id: <20200807094151.13526-7-peter.chen@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200807094151.13526-1-peter.chen@nxp.com> References: <20200807094151.13526-1-peter.chen@nxp.com> X-ClientProxiedBy: SG2PR03CA0113.apcprd03.prod.outlook.com (2603:1096:4:91::17) To AM7PR04MB7157.eurprd04.prod.outlook.com (2603:10a6:20b:118::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from b29397-desktop.ap.freescale.net (119.31.174.67) by SG2PR03CA0113.apcprd03.prod.outlook.com (2603:1096:4:91::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.5 via Frontend Transport; Fri, 7 Aug 2020 09:42:57 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [119.31.174.67] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: e482c232-7a1c-4987-2b11-08d83ab64534 X-MS-TrafficTypeDiagnostic: AM7PR04MB7077: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:196; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pSgON/DcAscYP2oSXoakGjTf8OTGN67OIn/Zbih31BePpxH8i9rWg9yMU1v0VIeGANs6BI+8l/RNuamM+I72gXGLi5d2pTH7epUflIdk6tV10Zw8cotioPrLxi8rrrHHi7VxNmgJ2bt3DVhnsAZPwg97qOZYtfMHkRlbBMzdKlhTQafFwGY7n/oDRP/Xq2/IPqE2NzmU23wt3LCDNGAm9yrMvDBLWOEoWkDV2WwP0Y+1mxPfs4QbWzhg5VF1+N8hlgpP/lskWzph5nnWd72xuY0anTcM9mfb9iamllOD6Ta2XQWDizFNxaY2P7yxNUVmRO3Llayg4ZWWm8VJHCJGgw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM7PR04MB7157.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(366004)(346002)(136003)(39860400002)(376002)(396003)(956004)(2616005)(5660300002)(86362001)(16526019)(44832011)(6486002)(6666004)(186003)(66556008)(66946007)(4326008)(6512007)(26005)(4744005)(52116002)(8676002)(83380400001)(1076003)(54906003)(66476007)(36756003)(8936002)(478600001)(6916009)(316002)(6506007)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: kDo19jh3l4YFAVW/zHg3UCEt5f6bJm6H51X9RmdVTpJW7RR79SP45TOG61MO1PBDREsSgmwBXjkO6MrwHKPF/oXukZSudGtbmC2lx3U9shLe8mJvuhsSi9GPeHTgm9CmPDv2Nlsjkz/ouzxU6np/GGg7rnl+kRa0qyXKHU+azxQc+ZRv62VVKlVGpuCILthoyVyZWZH6GFpXEFwork2JySw59xzlP9gDm0i1GcLBUay4xRwjrec9UJ8lHERkWNfM8nuOe9A7pV9E+9BPMoA11NXfCDCpuv28aXTqKzZvTRee2baJu9pY5jH5kVw6I6/mXr7BCWl9Ei771amDUkOwFDe3mRum+PBdi3/p3092cEjoNboNsaW8SjxtdPO7SxsjVBdkAtzzuSDepIiKNWHmHZS4njw/0DXJBtVqg5psn8LOlQeV1obHcZ7XJ2HY5rm7WWjSD/hT7S9th/qWhgy4mi7V7ut1e8Xy+Ap1L1vJNuXkDBsEzRgeFFgRuzcenBBsK1k4eQek+Fi+2DE1RcjXPfOH9eKojWHsPDYALk7ILqZNRf4kdZZb7uIGYw1zoJxv3o9Gc3k9Tz48fJdIhEqMOI6CLJxOOR3mFjXgj43mqZo6rmFoOpcKZoJoHIA7OX73w99XkdYCzNmT8giwsFfXaA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: e482c232-7a1c-4987-2b11-08d83ab64534 X-MS-Exchange-CrossTenant-AuthSource: AM7PR04MB7157.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 09:42:59.5616 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: N0Co8QmOtwusUSQKhtEPo75FRxiohrwOT9G1vtEdXLbbhfC2uP9RfxVzLdGg9iiRmUA4aGClSdlUnKoDQkNn2A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR04MB7077 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org We have already allocated gadget structure dynamically at UDC (dwc3) driver, so commit fac323471df6 ("usb: udc: allow adding and removing the same gadget device")could be reverted. Cc: Roger Quadros Cc: Greg Kroah-Hartman Cc: Alan Stern Signed-off-by: Peter Chen --- drivers/usb/gadget/udc/core.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c index 473e74088b1f..43351b0af569 100644 --- a/drivers/usb/gadget/udc/core.c +++ b/drivers/usb/gadget/udc/core.c @@ -1386,7 +1386,6 @@ void usb_del_gadget_udc(struct usb_gadget *gadget) { usb_del_gadget(gadget); usb_put_gadget(gadget); - memset(&gadget->dev, 0x00, sizeof(gadget->dev)); } EXPORT_SYMBOL_GPL(usb_del_gadget_udc);