* [patch] usb: gadget: f_tcm: memory leak on error in tcm_alloc_inst()
@ 2015-12-09 10:23 Dan Carpenter
2015-12-10 16:52 ` Felipe Balbi
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2015-12-09 10:23 UTC (permalink / raw)
To: kernel-janitors
We need to kfree(opts) on error. Also it's nicer to allocate opts
before taking the lock.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c
index ed47e40..0a26a2e 100644
--- a/drivers/usb/gadget/function/f_tcm.c
+++ b/drivers/usb/gadget/function/f_tcm.c
@@ -2300,20 +2300,19 @@ static struct usb_function_instance *tcm_alloc_inst(void)
struct f_tcm_opts *opts;
int i;
- mutex_lock(&tpg_instances_lock);
- opts = kzalloc(sizeof(*opts), GFP_KERNEL);
- if (!opts) {
- mutex_unlock(&tpg_instances_lock);
+ opts = kzalloc(sizeof(*opts), GFP_KERNEL);
+ if (!opts)
return ERR_PTR(-ENOMEM);
- }
+
+ mutex_lock(&tpg_instances_lock);
for (i = 0; i < TPG_INSTANCES; ++i)
if (!tpg_instances[i].func_inst)
break;
if (i = TPG_INSTANCES) {
mutex_unlock(&tpg_instances_lock);
-
+ kfree(opts);
return ERR_PTR(-EBUSY);
}
tpg_instances[i].func_inst = &opts->func_inst;
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-12-10 16:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-09 10:23 [patch] usb: gadget: f_tcm: memory leak on error in tcm_alloc_inst() Dan Carpenter
2015-12-10 16:52 ` Felipe Balbi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox