Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4640a3f2 authored by Dan Carpenter's avatar Dan Carpenter Committed by Greg Kroah-Hartman
Browse files

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: default avatarDan Carpenter <dan.carpenter@oracle.com>
Acked-by: default avatarAlessandro Rubini <rubini@gnudd.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent c2955da0
Loading
Loading
Loading
Loading
+11 −6
Original line number Diff line number Diff line
@@ -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 {
	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;
}