Commit 63306de0 authored by Geordan Neukum's avatar Geordan Neukum Committed by Greg Kroah-Hartman

staging: kpc2000: kpc_i2c: prevent memory leak in probe() error case

The probe() function performs a kzalloc to dynamically allocate memory
at runtime. If the allocation succeeds, yet invoking the function
i2c_add_adapter fails, the dynamically allocated memory is never freed.
Change the allocation to use the managed allocation API instead and
remove the manual freeing of the memory in the remove() function.
Signed-off-by: default avatarGeordan Neukum <gneukum1@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 11011c03
...@@ -628,7 +628,7 @@ int pi2c_probe(struct platform_device *pldev) ...@@ -628,7 +628,7 @@ int pi2c_probe(struct platform_device *pldev)
dev_dbg(&pldev->dev, "pi2c_probe(pldev = %p '%s')\n", pldev, pldev->name); dev_dbg(&pldev->dev, "pi2c_probe(pldev = %p '%s')\n", pldev, pldev->name);
priv = kzalloc(sizeof(struct i2c_device), GFP_KERNEL); priv = devm_kzalloc(&pldev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv) { if (!priv) {
return -ENOMEM; return -ENOMEM;
} }
...@@ -685,10 +685,6 @@ int pi2c_remove(struct platform_device *pldev) ...@@ -685,10 +685,6 @@ int pi2c_remove(struct platform_device *pldev)
//pci_set_drvdata(dev, NULL); //pci_set_drvdata(dev, NULL);
//cdev_del(&lddev->cdev); //cdev_del(&lddev->cdev);
if(lddev != 0) {
kfree(lddev);
pldev->dev.platform_data = 0;
}
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment