Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Dan Carpenter and committed by
Greg Kroah-Hartman
4640a3f2 c2955da0

+11 -6
+11 -6
drivers/fmc/fmc-chardev.c
··· 136 136 137 137 /* Create a char device: we want to create it anew */ 138 138 fc = kzalloc(sizeof(*fc), GFP_KERNEL); 139 + if (!fc) 140 + return -ENOMEM; 139 141 fc->fmc = fmc; 140 142 fc->misc.minor = MISC_DYNAMIC_MINOR; 141 143 fc->misc.fops = &fc_fops; ··· 145 143 146 144 spin_lock(&fc_lock); 147 145 ret = misc_register(&fc->misc); 148 - if (ret < 0) { 149 - kfree(fc->misc.name); 150 - kfree(fc); 151 - } else { 152 - list_add(&fc->list, &fc_devices); 153 - } 146 + if (ret < 0) 147 + goto err_unlock; 148 + list_add(&fc->list, &fc_devices); 154 149 spin_unlock(&fc_lock); 155 150 dev_info(&fc->fmc->dev, "Created misc device \"%s\"\n", 156 151 fc->misc.name); 152 + return 0; 153 + 154 + err_unlock: 155 + spin_unlock(&fc_lock); 156 + kfree(fc->misc.name); 157 + kfree(fc); 157 158 return ret; 158 159 } 159 160