Skip to content

Commit

Permalink
FMC: fix error handling in probe() function
Browse files Browse the repository at this point in the history
The call to kzalloc() wasn't checked.
The dev_info() message dereferenced freed memory on error.

Signed-off-by: Dan Carpenter <[email protected]>
Acked-by: Alessandro Rubini <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
Dan Carpenter authored and gregkh committed Jun 24, 2013
1 parent c2955da commit 4640a3f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions drivers/fmc/fmc-chardev.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,27 @@ 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;
fc->misc.name = kstrdup(dev_name(&fmc->dev), GFP_KERNEL);

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;
}

Expand Down

0 comments on commit 4640a3f

Please sign in to comment.