From patchwork Fri Jun 24 20:05:05 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 2314 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 4DD1423F6D for ; Fri, 24 Jun 2011 20:05:19 +0000 (UTC) Received: from mail-qw0-f52.google.com (mail-qw0-f52.google.com [209.85.216.52]) by fiordland.canonical.com (Postfix) with ESMTP id 0595EA1800D for ; Fri, 24 Jun 2011 20:05:18 +0000 (UTC) Received: by qwb8 with SMTP id 8so2301129qwb.11 for ; Fri, 24 Jun 2011 13:05:18 -0700 (PDT) Received: by 10.229.40.139 with SMTP id k11mr2864959qce.135.1308945918460; Fri, 24 Jun 2011 13:05:18 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.229.230.139 with SMTP id jm11cs58465qcb; Fri, 24 Jun 2011 13:05:18 -0700 (PDT) Received: by 10.236.181.225 with SMTP id l61mr6061194yhm.225.1308945917479; Fri, 24 Jun 2011 13:05:17 -0700 (PDT) Received: from mail-pv0-f178.google.com (mail-pv0-f178.google.com [74.125.83.178]) by mx.google.com with ESMTPS id g63si17100762yhn.28.2011.06.24.13.05.16 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 24 Jun 2011 13:05:17 -0700 (PDT) Received-SPF: neutral (google.com: 74.125.83.178 is neither permitted nor denied by best guess record for domain of jaswinder.singh@linaro.org) client-ip=74.125.83.178; Authentication-Results: mx.google.com; spf=neutral (google.com: 74.125.83.178 is neither permitted nor denied by best guess record for domain of jaswinder.singh@linaro.org) smtp.mail=jaswinder.singh@linaro.org Received: by mail-pv0-f178.google.com with SMTP id 7so2219038pvg.37 for ; Fri, 24 Jun 2011 13:05:16 -0700 (PDT) Received: by 10.68.0.106 with SMTP id 10mr1912962pbd.434.1308945916522; Fri, 24 Jun 2011 13:05:16 -0700 (PDT) Received: from localhost.localdomain ([122.167.86.144]) by mx.google.com with ESMTPS id g2sm2277175pbh.95.2011.06.24.13.05.12 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 24 Jun 2011 13:05:15 -0700 (PDT) From: Jassi Brar To: linux-usb@vger.kernel.org Cc: stern@rowland.harvard.edu, laurent.pinchart@ideasonboard.com, gregkh@suse.de, patches@linaro.org, balbi@ti.com, ti@lists.linaro.org, Jassi Brar Subject: [PATCH 2/3] USB: Gadget: Zero: Free resources in config unbind Date: Sat, 25 Jun 2011 01:35:05 +0530 Message-Id: <1308945905-682-1-git-send-email-jaswinder.singh@linaro.org> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1308945851-607-1-git-send-email-jaswinder.singh@linaro.org> References: <1308945851-607-1-git-send-email-jaswinder.singh@linaro.org> Resources allocated during configuration 'bind' should be freed in configuration 'unbind'. Signed-off-by: Jassi Brar --- drivers/usb/gadget/f_loopback.c | 19 ++++++++++++------- drivers/usb/gadget/f_sourcesink.c | 18 +++++++++++------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/drivers/usb/gadget/f_loopback.c b/drivers/usb/gadget/f_loopback.c index b37960f..932f38d 100644 --- a/drivers/usb/gadget/f_loopback.c +++ b/drivers/usb/gadget/f_loopback.c @@ -181,12 +181,6 @@ autoconf_fail: return 0; } -static void -loopback_unbind(struct usb_configuration *c, struct usb_function *f) -{ - kfree(func_to_loop(f)); -} - static void loopback_complete(struct usb_ep *ep, struct usb_request *req) { struct f_loopback *loop = ep->driver_data; @@ -336,19 +330,30 @@ static int __init loopback_bind_config(struct usb_configuration *c) loop->function.name = "loopback"; loop->function.descriptors = fs_loopback_descs; loop->function.bind = loopback_bind; - loop->function.unbind = loopback_unbind; loop->function.set_alt = loopback_set_alt; loop->function.disable = loopback_disable; status = usb_add_function(c, &loop->function); if (status) kfree(loop); + else + c->data = (void *)loop; + return status; } +static void __exit loopback_unbind_config(struct usb_configuration *c) +{ + struct f_loopback *loop = c->data; + + kfree(loop) + c->data = NULL; +} + static struct usb_configuration loopback_driver = { .label = "loopback", .strings = loopback_strings, + .unbind = loopback_unbind_config, .bConfigurationValue = 2, .bmAttributes = USB_CONFIG_ATT_SELFPOWER, /* .iConfiguration = DYNAMIC */ diff --git a/drivers/usb/gadget/f_sourcesink.c b/drivers/usb/gadget/f_sourcesink.c index e403a53..9ab0bde 100644 --- a/drivers/usb/gadget/f_sourcesink.c +++ b/drivers/usb/gadget/f_sourcesink.c @@ -193,12 +193,6 @@ autoconf_fail: return 0; } -static void -sourcesink_unbind(struct usb_configuration *c, struct usb_function *f) -{ - kfree(func_to_ss(f)); -} - /* optionally require specific source/sink data patterns */ static int check_read_data(struct f_sourcesink *ss, struct usb_request *req) { @@ -416,16 +410,25 @@ static int __init sourcesink_bind_config(struct usb_configuration *c) ss->function.name = "source/sink"; ss->function.descriptors = fs_source_sink_descs; ss->function.bind = sourcesink_bind; - ss->function.unbind = sourcesink_unbind; ss->function.set_alt = sourcesink_set_alt; ss->function.disable = sourcesink_disable; status = usb_add_function(c, &ss->function); if (status) kfree(ss); + else + c->data = (void *)ss; return status; } +static void __exit sourcesink_unbind_config(struct usb_configuration *c) +{ + struct f_sourcesink *ss = c->data; + + kfree(ss); + c->data = NULL; +} + static int sourcesink_setup(struct usb_configuration *c, const struct usb_ctrlrequest *ctrl) { @@ -498,6 +501,7 @@ unknown: static struct usb_configuration sourcesink_driver = { .label = "source/sink", .strings = sourcesink_strings, + .unbind = sourcesink_unbind_config, .setup = sourcesink_setup, .bConfigurationValue = 3, .bmAttributes = USB_CONFIG_ATT_SELFPOWER,