The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] USB: gadget: f_mass_storage: fix in fsg_common_init() error recovery
@ 2010-05-12  8:16 Michal Nazarewicz
  2010-05-12  8:29 ` Viral Mehta
  0 siblings, 1 reply; 16+ messages in thread
From: Michal Nazarewicz @ 2010-05-12  8:16 UTC (permalink / raw)
  To: linux-usb; +Cc: Kyungmin Park, Marek Szyprowski, linux-kernel

In to places in fsg_common_init() an unconditional call to kfree()
on common was performed in error recovery which is not a valid
behaviour since fsg_common structure is not always allocated by
fsg_common_init().

To fix, the calls has been replaced with a goto to a proper error
recovery which does the correct thing.
---
 drivers/usb/gadget/f_mass_storage.c |   12 +++++-------
 1 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index 6cfd2f4..9a59941 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -2742,10 +2742,8 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
 	/* Maybe allocate device-global string IDs, and patch descriptors */
 	if (fsg_strings[FSG_STRING_INTERFACE].id == 0) {
 		rc = usb_string_id(cdev);
-		if (rc < 0) {
-			kfree(common);
-			return ERR_PTR(rc);
-		}
+		if (unlikely(rc < 0))
+			goto error_release;
 		fsg_strings[FSG_STRING_INTERFACE].id = rc;
 		fsg_intf_desc.iInterface = rc;
 	}
@@ -2753,9 +2751,9 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
 	/* Create the LUNs, open their backing files, and register the
 	 * LUN devices in sysfs. */
 	curlun = kzalloc(nluns * sizeof *curlun, GFP_KERNEL);
-	if (!curlun) {
-		kfree(common);
-		return ERR_PTR(-ENOMEM);
+	if (unlikely(!curlun)) {
+		rc = -ENOMEM;
+		goto error_release;
 	}
 	common->luns = curlun;
 
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2010-05-12 22:16 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-12  8:16 [PATCH] USB: gadget: f_mass_storage: fix in fsg_common_init() error recovery Michal Nazarewicz
2010-05-12  8:29 ` Viral Mehta
2010-05-12  9:02   ` Michał Nazarewicz
2010-05-12  9:28     ` Viral Mehta
2010-05-12  9:36       ` Viral Mehta
2010-05-12  9:57         ` Michał Nazarewicz
2010-05-12 10:33           ` Viral Mehta
2010-05-12 10:51             ` [PATCH] USB: gadget: f_mass_storage: fix in " Michal Nazarewicz
2010-05-12 12:03               ` Viral Mehta
2010-05-12 21:39               ` Greg KH
2010-05-12 22:16                 ` Michal Nazarewicz
2010-05-12  9:53       ` [PATCH] USB: gadget: f_mass_storage: fix in fsg_common_init() " Michał Nazarewicz
2010-05-12 10:06         ` Viral Mehta
2010-05-12 10:34           ` Michał Nazarewicz
2010-05-12 10:37             ` Viral Mehta
2010-05-12 10:52               ` Michał Nazarewicz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox