* [patch] FMC: fix error handling in probe() function
@ 2013-06-20 8:10 Dan Carpenter
2013-06-20 14:09 ` Alessandro Rubini
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2013-06-20 8:10 UTC (permalink / raw)
To: Alessandro Rubini, gregkh; +Cc: linux-kernel, kernel-janitors
The call to kzalloc() wasn't checked.
The dev_info() message dereferenced freed memory on error.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/drivers/fmc/fmc-chardev.c b/drivers/fmc/fmc-chardev.c
index b071039..cc031db 100644
--- a/drivers/fmc/fmc-chardev.c
+++ b/drivers/fmc/fmc-chardev.c
@@ -136,6 +136,8 @@ static int fc_probe(struct fmc_device *fmc)
/* Create a char device: we want to create it anew */
fc = kzalloc(sizeof(*fc), GFP_KERNEL);
+ if (!fc)
+ return -ENOMEM;
fc->fmc = fmc;
fc->misc.minor = MISC_DYNAMIC_MINOR;
fc->misc.fops = &fc_fops;
@@ -143,15 +145,18 @@ static int fc_probe(struct fmc_device *fmc)
spin_lock(&fc_lock);
ret = misc_register(&fc->misc);
- if (ret < 0) {
- kfree(fc->misc.name);
- kfree(fc);
- } else {
- list_add(&fc->list, &fc_devices);
- }
+ if (ret < 0)
+ goto err_unlock;
+ list_add(&fc->list, &fc_devices);
spin_unlock(&fc_lock);
dev_info(&fc->fmc->dev, "Created misc device \"%s\"\n",
fc->misc.name);
+ return 0;
+
+err_unlock:
+ spin_unlock(&fc_lock);
+ kfree(fc->misc.name);
+ kfree(fc);
return ret;
}
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [patch] FMC: fix error handling in probe() function
2013-06-20 8:10 [patch] FMC: fix error handling in probe() function Dan Carpenter
@ 2013-06-20 14:09 ` Alessandro Rubini
0 siblings, 0 replies; 2+ messages in thread
From: Alessandro Rubini @ 2013-06-20 14:09 UTC (permalink / raw)
To: dan.carpenter; +Cc: gregkh, linux-kernel, kernel-janitors
> The call to kzalloc() wasn't checked.
> The dev_info() message dereferenced freed memory on error.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
Thanks!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-06-20 14:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-20 8:10 [patch] FMC: fix error handling in probe() function Dan Carpenter
2013-06-20 14:09 ` Alessandro Rubini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox