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

mfd: Fix memory leak in ab3100_otp_probe

In current implementation, there is a memory leak if ab3100_otp_read fail.
And in the case of ab3100_otp_init_debugfs fail, it does not properly remove
sysfs entries.
This patch properly handle above failure cases.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
Acked-by: Linus Walleij <linus.walleij@stericsson.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>

authored by

Axel Lin and committed by
Samuel Ortiz
d281b80c 21f1fc38

+8 -8
+8 -8
drivers/mfd/ab3100-otp.c
··· 199 199 200 200 err = ab3100_otp_read(otp); 201 201 if (err) 202 - return err; 202 + goto err_otp_read; 203 203 204 204 dev_info(&pdev->dev, "AB3100 OTP readout registered\n"); 205 205 ··· 208 208 err = device_create_file(&pdev->dev, 209 209 &ab3100_otp_attrs[i]); 210 210 if (err) 211 - goto out_no_sysfs; 211 + goto err_create_file; 212 212 } 213 213 214 214 /* debugfs entries */ 215 215 err = ab3100_otp_init_debugfs(&pdev->dev, otp); 216 216 if (err) 217 - goto out_no_debugfs; 217 + goto err_init_debugfs; 218 218 219 219 return 0; 220 220 221 - out_no_sysfs: 222 - for (i = 0; i < ARRAY_SIZE(ab3100_otp_attrs); i++) 223 - device_remove_file(&pdev->dev, 224 - &ab3100_otp_attrs[i]); 225 - out_no_debugfs: 221 + err_init_debugfs: 222 + err_create_file: 223 + while (--i >= 0) 224 + device_remove_file(&pdev->dev, &ab3100_otp_attrs[i]); 225 + err_otp_read: 226 226 kfree(otp); 227 227 return err; 228 228 }