Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Linux: Kernel

[PATCH] regulator: palmas: Fix wrong kfree calls

 

 

Linux kernel RSS feed   Index | Next | Previous | View Threaded


axel.lin at gmail

May 21, 2012, 5:55 AM

Post #1 of 2 (27 views)
Permalink
[PATCH] 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: Axel Lin <axel.lin [at] gmail>
---
drivers/regulator/palmas-regulator.c | 7 -------
1 files changed, 0 insertions(+), 7 deletions(-)

diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c
index c4435f6..9b7ca90 100644
--- a/drivers/regulator/palmas-regulator.c
+++ b/drivers/regulator/palmas-regulator.c
@@ -775,9 +775,6 @@ static __devinit int palmas_probe(struct platform_device *pdev)
err_unregister_regulator:
while (--id >= 0)
regulator_unregister(pmic->rdev[id]);
- kfree(pmic->rdev);
- kfree(pmic->desc);
- kfree(pmic);
return ret;
}

@@ -788,10 +785,6 @@ static int __devexit palmas_remove(struct platform_device *pdev)

for (id = 0; id < PALMAS_NUM_REGS; id++)
regulator_unregister(pmic->rdev[id]);
-
- kfree(pmic->rdev);
- kfree(pmic->desc);
- kfree(pmic);
return 0;
}

--
1.7.5.4



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


broonie at opensource

May 21, 2012, 7:48 AM

Post #2 of 2 (26 views)
Permalink
Re: [PATCH] regulator: palmas: Fix wrong kfree calls [In reply to]

On Mon, May 21, 2012 at 08:55:40PM +0800, Axel Lin wrote:
> 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.

Applied, thanks.
Attachments: signature.asc (0.82 KB)

Linux kernel RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.