Skip to content

Commit 4640a3f

Browse files
Dan Carpentergregkh
authored andcommitted
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>
1 parent c2955da commit 4640a3f

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

‎drivers/fmc/fmc-chardev.c‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,22 +136,27 @@ static int fc_probe(struct fmc_device *fmc)
136136

137137
/* Create a char device: we want to create it anew */
138138
fc = kzalloc(sizeof(*fc), GFP_KERNEL);
139+
if (!fc)
140+
return -ENOMEM;
139141
fc->fmc = fmc;
140142
fc->misc.minor = MISC_DYNAMIC_MINOR;
141143
fc->misc.fops = &fc_fops;
142144
fc->misc.name = kstrdup(dev_name(&fmc->dev), GFP_KERNEL);
143145

144146
spin_lock(&fc_lock);
145147
ret = misc_register(&fc->misc);
146-
if (ret < 0) {
147-
kfree(fc->misc.name);
148-
kfree(fc);
149-
} else {
150-
list_add(&fc->list, &fc_devices);
151-
}
148+
if (ret < 0)
149+
goto err_unlock;
150+
list_add(&fc->list, &fc_devices);
152151
spin_unlock(&fc_lock);
153152
dev_info(&fc->fmc->dev, "Created misc device \"%s\"\n",
154153
fc->misc.name);
154+
return 0;
155+
156+
err_unlock:
157+
spin_unlock(&fc_lock);
158+
kfree(fc->misc.name);
159+
kfree(fc);
155160
return ret;
156161
}
157162

0 commit comments

Comments
 (0)