summaryrefslogtreecommitdiffstats
path: root/drivers/fmc
diff options
context:
space:
mode:
authorDan Carpenter <dan.carpenter@oracle.com>2013-06-20 11:10:18 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-06-24 16:23:25 -0700
commit4640a3f2bff64b808bdedadcddf882aa4606f374 (patch)
tree1b7fdf74ef6ff7eab4df7a39a1756f8f5c5024ca /drivers/fmc
parentc2955da0e101c3432ae21945e5d77786adf1f094 (diff)
downloadlinux-4640a3f2bff64b808bdedadcddf882aa4606f374.tar.gz
linux-4640a3f2bff64b808bdedadcddf882aa4606f374.tar.bz2
linux-4640a3f2bff64b808bdedadcddf882aa4606f374.zip
FMC: fix error handling in probe() function
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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/fmc')
-rw-r--r--drivers/fmc/fmc-chardev.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/drivers/fmc/fmc-chardev.c b/drivers/fmc/fmc-chardev.c
index b0710393ede6..cc031db2d2a3 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;
}