From patchwork Thu Oct 3 11:47:15 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?=C5=81ukasz_Majewski?= X-Patchwork-Id: 280282 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 17D4E2C00C5 for ; Thu, 3 Oct 2013 21:50:56 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2D46B4A0A2; Thu, 3 Oct 2013 13:50:47 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2OtFU93qKHSZ; Thu, 3 Oct 2013 13:50:46 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E40BF4A0AE; Thu, 3 Oct 2013 13:50:39 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B8D4F4A092 for ; Thu, 3 Oct 2013 13:50:27 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gzPTaALHf49c for ; Thu, 3 Oct 2013 13:50:20 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by theia.denx.de (Postfix) with ESMTP id 41A614A0C2 for ; Thu, 3 Oct 2013 13:49:49 +0200 (CEST) Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MU300AGCCREA7I0@mailout2.samsung.com> for u-boot@lists.denx.de; Thu, 03 Oct 2013 20:47:49 +0900 (KST) X-AuditID: cbfee61b-b7f776d0000016c8-e3-524d5965dd27 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id F7.40.05832.5695D425; Thu, 03 Oct 2013 20:47:49 +0900 (KST) Received: from mcdsrvbld02.digital.local ([106.116.37.23]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MU300KGQCR0H800@mmp2.samsung.com>; Thu, 03 Oct 2013 20:47:49 +0900 (KST) From: Lukasz Majewski To: u-boot@lists.denx.de Date: Thu, 03 Oct 2013 13:47:15 +0200 Message-id: <1380800841-21673-5-git-send-email-l.majewski@samsung.com> X-Mailer: git-send-email 1.7.10 In-reply-to: <1380800841-21673-1-git-send-email-l.majewski@samsung.com> References: <1380800841-21673-1-git-send-email-l.majewski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrDLMWRmVeSWpSXmKPExsVy+t9jQd3USN8ggyc/9S0u79e22HHnPrPF rr/3GS1u/GpjtXjzcDOjxZu2RkaL240r2Cx23Z7MYnFg7nsWi8mL5zNbvN3bye7A7THv50Qm j3mzTrB4nL2zg9Gjb8sqRo/tJycxeRy/sZ0pgC2KyyYlNSezLLVI3y6BK6N7fhNzwWW+ikX9 0Q2Ma3m6GDk4JARMJJ7fde5i5AQyxSQu3FvP1sXIxSEkMJ1RYuOtM0wQTheTxJqTT5hAqtgE 9CQ+330KZosISEj86r/KCFLELPCcSWLJ8UVsIAlhgVyJ9wvXgBWxCKhK7Ph2nR3E5hVwk/h+ sZMZYp28xNP7fWD1nALuEicbusFsIaCat4/3sU9g5F3AyLCKUTS1ILmgOCk910ivODG3uDQv XS85P3cTIzgMn0nvYFzVYHGIUYCDUYmHt0PFJ0iINbGsuDL3EKMEB7OSCO+1IN8gId6UxMqq 1KL8+KLSnNTiQ4zSHCxK4rwHW60DhQTSE0tSs1NTC1KLYLJMHJxSDYx9xz8zc0++tO18nkxF 5bIN7TzCc1z00qyfML3KOy/z45/kt4j/7kkxU5Xm/Ht6i+2/B2Nc7IJPj5z2yMZq2miYb1Fr Ld+tZXHepWDZUcPFCrPz8jhzbxy+YWPpdLX/14EMgUlB7K/nz+1uyDAQvVJZ8WDt5ThbuYl9 j8/PiAxo2aRZv/DF3TIlluKMREMt5qLiRADInjsbPwIAAA== Cc: Marek Vasut , Egli Samuel , Pantelis Antoniou , Jaehoon Chung , Myungjoo Ham , Tom Rini , ideal.song@samsung.com Subject: [U-Boot] [PATCH 04/10] usb:g_dnl: Replace static usb_configuration structure with dynamically allocated one X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de When the usb_configuration structure is declared as static, it is very hard to assure, that relevant fields (as e.g. config->interfaces[]) are cleared out before new call to g_dnl related functions. Signed-off-by: Lukasz Majewski Marek Vasut --- drivers/usb/gadget/g_dnl.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/drivers/usb/gadget/g_dnl.c b/drivers/usb/gadget/g_dnl.c index 40868c0..1aaf78f 100644 --- a/drivers/usb/gadget/g_dnl.c +++ b/drivers/usb/gadget/g_dnl.c @@ -79,6 +79,8 @@ static int g_dnl_unbind(struct usb_composite_dev *cdev) { struct usb_gadget *gadget = cdev->gadget; + free(cdev->config); + cdev->config = NULL; debug("%s: calling usb_gadget_disconnect for " "controller '%s'\n", shortname, gadget->name); usb_gadget_disconnect(gadget); @@ -105,16 +107,22 @@ static int g_dnl_do_config(struct usb_configuration *c) static int g_dnl_config_register(struct usb_composite_dev *cdev) { - static struct usb_configuration config = { - .label = "usb_dnload", - .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, - .bConfigurationValue = CONFIGURATION_NUMBER, - .iConfiguration = STRING_USBDOWN, + struct usb_configuration *config; + const char *name = "usb_dnload"; - .bind = g_dnl_do_config, - }; + config = memalign(CONFIG_SYS_CACHELINE_SIZE, sizeof(*config)); + if (!config) + return -ENOMEM; - return usb_add_config(cdev, &config); + memset(config, 0, sizeof(*config)); + + config->label = name; + config->bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER; + config->bConfigurationValue = CONFIGURATION_NUMBER; + config->iConfiguration = STRING_USBDOWN; + config->bind = g_dnl_do_config; + + return usb_add_config(cdev, config); } __weak