Skip to contentSkip to conversation

drivers: mfd: tps65912: Convert to use devm_kzalloc

PATCH In review Leon Romanovsky 3 participants 9 messages May 15, 2013 – May 28, 2013 1 message not in the archive Multifunction devices (MFD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers: mfd: tps65912: Convert to use devm_kzalloc

There is no need to call kfree while using devm_kzalloc, remove it from *_device_init function.

---
 drivers/mfd/tps65912-core.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/mfd/tps65912-core.c +2 -3
index aeb8e40..f25e552 100644
@@ -127,7 +127,8 @@ int tps65912_device_init(struct tps65912 *tps65912)
 	struct tps65912_platform_data *init_data;
 	int ret, dcdc_avs, value;
 
-	init_data = kzalloc(sizeof(struct tps65912_platform_data), GFP_KERNEL);
+	init_data = devm_kzalloc(&tps65912->dev,
+			sizeof(struct tps65912_platform_data), GFP_KERNEL);
 	if (init_data == NULL)
 		return -ENOMEM;
 
@@ -156,11 +157,9 @@ int tps65912_device_init(struct tps65912 *tps65912)
 	if (ret < 0)
 		goto err;
 
-	kfree(init_data);
 	return ret;
 
 err:
-	kfree(init_data);
 	mfd_remove_devices(tps65912->dev);
 	kfree(tps65912);
 	return ret;
Signature · 1 line
1.8.1.5
#1 lore raw

Hi Samuel,

Quoted 7 lines · Leon Romanovsky

There is no need to call kfree while using devm_kzalloc, remove it from *_device_init function.

---
 drivers/mfd/tps65912-core.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

To be honest the whole tps65912 looks strange to me. For example, kfree(tps65912) calls all over the code.

tps65912_i2c_probe allocates tps65912 struct, but tps65912_device_exit releases it.

--
Leon Romanovsky | Independent Linux Consultant
www.leon.nu | [email protected]

#2 lore raw
Quoted 8 lines
Quoted 7 lines

There is no need to call kfree while using devm_kzalloc, remove it from *_device_init function.

---
 drivers/mfd/tps65912-core.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
Quoted 5 lines

To be honest the whole tps65912 looks strange to me. For example, kfree(tps65912) calls all over the code.

tps65912_i2c_probe allocates tps65912 struct, but tps65912_device_exit releases it.

Yes, this is expected.

tps65912_[spi|i2c]_remove() both call tps65912_device_exit() which in turn frees tps65912. Saves duplicating code.

I'll clean thinks up a little, so this is less confusing.

Signature · 4 lines
Lee Jones
Linaro ST-Ericsson Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#3 lore raw
In reply to Leon Romanovsky
Quoted 7 lines · Leon Romanovsky

There is no need to call kfree while using devm_kzalloc, remove it from *_device_init function.

---
 drivers/mfd/tps65912-core.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Applied thanks.

Signature · 4 lines
Lee Jones
Linaro ST-Ericsson Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#4 lore raw
In reply to Leon Romanovsky
Quoted 13 lines · Leon Romanovsky

There is no need to call kfree while using devm_kzalloc, remove it from *_device_init function.

---
 drivers/mfd/tps65912-core.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/mfd/tps65912-core.c +0 -0
index aeb8e40..f25e552 100644

drivers/mfd/tps65912-core.c int tps65912_device_init(struct tps65912 *tps65912) · line 131

Quoted 6 lines
drivers/mfd/tps65912-core.c +2 -1
@@ -127,7 +127,8 @@ int tps65912_device_init(struct tps65912 *tps65912)
 	struct tps65912_platform_data *init_data;
 	int ret, dcdc_avs, value;
 
-	init_data = kzalloc(sizeof(struct tps65912_platform_data), GFP_KERNEL);
+	init_data = devm_kzalloc(&tps65912->dev,
+			sizeof(struct tps65912_platform_data), GFP_KERNEL);

On second thoughts, have you actually built this?

Signature · 4 lines
Lee Jones
Linaro ST-Ericsson Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

A message that is not in the archive (sent off-list or not yet received): CALq1K=Las2mwV9x6ajEUDYg6nLbcK2KVLK8TH2B1f=9fQ7JfTg@mail.gmail.com

#6 lore raw
Quoted 22 lines · Leon Romanovsky
Quoted 19 lines · Lee Jones
Quoted 16 lines · Leon Romanovsky

There is no need to call kfree while using devm_kzalloc, remove it from *_device_init function.

---
 drivers/mfd/tps65912-core.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/mfd/tps65912-core.c +0 -0
index aeb8e40..f25e552 100644
@@ -127,7 +127,8 @@ int tps65912_device_init(struct tps65912 *tps65912)
      struct tps65912_platform_data *init_data;
      int ret, dcdc_avs, value;
 
Quoted 1 line

drivers/mfd/tps65912-core.c int tps65912_device_init(struct tps65912 *tps65912) · line 130

Quoted 1 line
drivers/mfd/tps65912-core.c +0 -1
-     init_data = kzalloc(sizeof(struct tps65912_platform_data),

GFP_KERNEL);

Quoted 7 lines
Quoted 2 lines

drivers/mfd/tps65912-core.c int tps65912_device_init(struct tps65912 *tps65912) · line 131

Quoted 2 lines
drivers/mfd/tps65912-core.c +2 -0
+     init_data = devm_kzalloc(&tps65912->dev,
+                     sizeof(struct tps65912_platform_data),

GFP_KERNEL);

Quoted 2 lines

On second thoughts, have you actually built this?

Sure, I hope, that I didn't miss anything.

Can you make absolutely sure that you did please?

I mention it because I would expect lots of warnings if you did.

Something like:

drivers/mfd/tps65912-core.c: In function ‘tps65912_reg_write’:
drivers/mfd/tps65912-core.c:117:3: warning: passing argument 1 of ‘dev_err’ from incompatible pointer type [enabled by default] In file included from include/linux/platform_device.h:14:0,

                 from include/linux/mfd/core.h:17,
                 from drivers/mfd/tps65912-core.c:21:

include/linux/device.h:954:5: note: expected ‘const struct device *’ but argument is of type ‘struct device **’ drivers/mfd/tps65912-core.c: In function ‘tps65912_device_init’:
drivers/mfd/tps65912-core.c:131:18: warning: passing argument 1 of ‘devm_kzalloc’ from incompatible pointer type [enabled by default] In file included from include/linux/platform_device.h:14:0,

                 from include/linux/mfd/core.h:17,
                 from drivers/mfd/tps65912-core.c:21:

include/linux/device.h:574:14: note: expected ‘struct device *’ but argument is of type ‘struct device **’

Can you check and make sure, because there's some disparity somewhere.

Signature · 4 lines
Lee Jones
Linaro ST-Ericsson Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#7 lore raw
Quoted 3 lines · Lee Jones
Quoted 1 line · Leon Romanovsky
Quoted 1 line
Quoted 1 line

+ init_data = devm_kzalloc(&tps65912->dev,

There is an obvious typo: no need of & here if I got it correctly.

Quoted 6 lines

drivers/mfd/tps65912-core.c: In function ‘tps65912_device_init’:
drivers/mfd/tps65912-core.c:131:18: warning: passing argument 1 of ‘devm_kzalloc’ from incompatible pointer type [enabled by default] In file included from include/linux/platform_device.h:14:0,

                 from include/linux/mfd/core.h:17,
                 from drivers/mfd/tps65912-core.c:21:

include/linux/device.h:574:14: note: expected ‘struct device *’ but argument is of type ‘struct device **’

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#8 lore raw
Quoted 13 lines · Andy Shevchenko
Quoted 3 lines · Lee Jones
Quoted 1 line · Leon Romanovsky
Quoted 1 line
Quoted 1 line

+ init_data = devm_kzalloc(&tps65912->dev,

There is an obvious typo: no need of & here if I got it correctly.

Quoted 6 lines

drivers/mfd/tps65912-core.c: In function ‘tps65912_device_init’:
drivers/mfd/tps65912-core.c:131:18: warning: passing argument 1 of ‘devm_kzalloc’ from incompatible pointer type [enabled by default] In file included from include/linux/platform_device.h:14:0,

                 from include/linux/mfd/core.h:17,
                 from drivers/mfd/tps65912-core.c:21:

include/linux/device.h:574:14: note: expected ‘struct device *’ but argument is of type ‘struct device **’

You are absolutely right, I sent the wrong patch with typo :(

Lee,
Do I need to resend it ? Or you can fix it by yourself ?

Quoted 4 lines

--
With Best Regards,
Andy Shevchenko

--
Leon Romanovsky | Independent Linux Consultant
www.leon.nu | [email protected]

#9 lore raw
Quoted 15 lines · Leon Romanovsky
Quoted 13 lines · Andy Shevchenko
Quoted 3 lines · Lee Jones
Quoted 1 line · Leon Romanovsky
Quoted 1 line
Quoted 1 line

+ init_data = devm_kzalloc(&tps65912->dev,

There is an obvious typo: no need of & here if I got it correctly.

Quoted 6 lines

drivers/mfd/tps65912-core.c: In function ‘tps65912_device_init’:
drivers/mfd/tps65912-core.c:131:18: warning: passing argument 1 of ‘devm_kzalloc’ from incompatible pointer type [enabled by default] In file included from include/linux/platform_device.h:14:0,

                 from include/linux/mfd/core.h:17,
                 from drivers/mfd/tps65912-core.c:21:

include/linux/device.h:574:14: note: expected ‘struct device *’ but argument is of type ‘struct device **’

Quoted 4 lines

You are absolutely right, I sent the wrong patch with typo :(

Lee,
Do I need to resend it ? Or you can fix it by yourself ?

I've already fixed it up and tested.

I just wanted to clarify exactly what happened, as it couldn't have been tested.

No worries, patch applied.

Signature · 4 lines
Lee Jones
Linaro ST-Ericsson Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog