diff options
author | Dan Carpenter <dan.carpenter@oracle.com> | 2013-06-20 04:10:18 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-06-24 19:23:25 -0400 |
commit | 4640a3f2bff64b808bdedadcddf882aa4606f374 (patch) | |
tree | 1b7fdf74ef6ff7eab4df7a39a1756f8f5c5024ca /drivers/fmc | |
parent | c2955da0e101c3432ae21945e5d77786adf1f094 (diff) |
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.c | 17 |
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) | |||
136 | 136 | ||
137 | /* Create a char device: we want to create it anew */ | 137 | /* Create a char device: we want to create it anew */ |
138 | fc = kzalloc(sizeof(*fc), GFP_KERNEL); | 138 | fc = kzalloc(sizeof(*fc), GFP_KERNEL); |
139 | if (!fc) | ||
140 | return -ENOMEM; | ||
139 | fc->fmc = fmc; | 141 | fc->fmc = fmc; |
140 | fc->misc.minor = MISC_DYNAMIC_MINOR; | 142 | fc->misc.minor = MISC_DYNAMIC_MINOR; |
141 | fc->misc.fops = &fc_fops; | 143 | fc->misc.fops = &fc_fops; |
@@ -143,15 +145,18 @@ static int fc_probe(struct fmc_device *fmc) | |||
143 | 145 | ||
144 | spin_lock(&fc_lock); | 146 | spin_lock(&fc_lock); |
145 | ret = misc_register(&fc->misc); | 147 | ret = misc_register(&fc->misc); |
146 | if (ret < 0) { | 148 | if (ret < 0) |
147 | kfree(fc->misc.name); | 149 | goto err_unlock; |
148 | kfree(fc); | 150 | list_add(&fc->list, &fc_devices); |
149 | } else { | ||
150 | list_add(&fc->list, &fc_devices); | ||
151 | } | ||
152 | spin_unlock(&fc_lock); | 151 | spin_unlock(&fc_lock); |
153 | dev_info(&fc->fmc->dev, "Created misc device \"%s\"\n", | 152 | dev_info(&fc->fmc->dev, "Created misc device \"%s\"\n", |
154 | fc->misc.name); | 153 | fc->misc.name); |
154 | return 0; | ||
155 | |||
156 | err_unlock: | ||
157 | spin_unlock(&fc_lock); | ||
158 | kfree(fc->misc.name); | ||
159 | kfree(fc); | ||
155 | return ret; | 160 | return ret; |
156 | } | 161 | } |
157 | 162 | ||