Commit c71c8fd4 authored by Axel Lin's avatar Axel Lin Committed by Mark Brown

regulator: palmas: Fix wrong kfree calls

The devm_kzalloc function eliminates the need for manual resource releasing
and simplify error handling. Resources allocated by devm_* are freed
automatically on driver detach.

Thus adding kfree calls here will introduce double free bug.

The memory of desc array and the pointers to the rdev[] are allocated by
devm_kzalloc call for struct palmas_pmic.

struct palmas_pmic {
        struct palmas *palmas;
        struct device *dev;
        struct regulator_desc desc[PALMAS_NUM_REGS];
        struct regulator_dev *rdev[PALMAS_NUM_REGS];
        struct mutex mutex;

        int smps123;
        int smps457;

        int range[PALMAS_REG_SMPS10];
};

Which means we should not call kfree for pmic->rdev and pmic->desc.
Signed-off-by: default avatarAxel Lin <axel.lin@gmail.com>
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent f8f5701b
...@@ -775,9 +775,6 @@ static __devinit int palmas_probe(struct platform_device *pdev) ...@@ -775,9 +775,6 @@ static __devinit int palmas_probe(struct platform_device *pdev)
err_unregister_regulator: err_unregister_regulator:
while (--id >= 0) while (--id >= 0)
regulator_unregister(pmic->rdev[id]); regulator_unregister(pmic->rdev[id]);
kfree(pmic->rdev);
kfree(pmic->desc);
kfree(pmic);
return ret; return ret;
} }
...@@ -788,10 +785,6 @@ static int __devexit palmas_remove(struct platform_device *pdev) ...@@ -788,10 +785,6 @@ static int __devexit palmas_remove(struct platform_device *pdev)
for (id = 0; id < PALMAS_NUM_REGS; id++) for (id = 0; id < PALMAS_NUM_REGS; id++)
regulator_unregister(pmic->rdev[id]); regulator_unregister(pmic->rdev[id]);
kfree(pmic->rdev);
kfree(pmic->desc);
kfree(pmic);
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