All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/25] leds: convert all kzalloc() to devm_kzalloc()
@ 2012-07-04  5:09 Bryan Wu
  2012-07-04  5:09 ` [PATCH 01/25] leds: convert Big Networks LED driver " Bryan Wu
                   ` (24 more replies)
  0 siblings, 25 replies; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  5:09 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

This convertion will simply the error handling in drivers.

Bryan Wu (25):
  leds: convert Big Networks LED driver to devm_kzalloc()
  leds: convert HTC ASIC3 LED driver to devm_kzalloc() and cleanup
    error exit path
  leds: convert Atmel PWM LED driver to devm_kzalloc()
  leds: convert LP3944 LED driver to devm_kzalloc()
  leds: convert DA9030/DA9034 LED driver to devm_kzalloc() and cleanup
    error exit path
  leds: convert LP5521 LED driver to devm_kzalloc() and cleanup error
    exit path
  leds: convert BD2802 RGB LED driver to devm_kzalloc() and cleanup
    error exit path
  leds: convert PCA9633 LED driver to devm_kzalloc()
  leds: convert LP5523 LED driver to devm_kzalloc() and cleanup error
    exit path
  leds: convert Renesas TPU LED driver to devm_kzalloc() and cleanup
    error exit path
  leds: convert LT3593 LED driver to devm_kzalloc()
  leds: convert PCA9532 LED driver to devm_kzalloc()
  leds: convert Sun Fire LED driver to devm_kzalloc() and cleanup error
    exit path
  leds: convert PCA955x LED driver to devm_kzalloc() and cleanup error
    exit path
  leds: convert ADP5520 LED driver to devm_kzalloc() and cleanup error
    exit path
  leds: convert Freescale MC13783 LED driver to devm_kzalloc() and
    cleanup error exit path
  leds: convert TCA6507 LED driver to devm_kzalloc()
  leds: convert LM3530 LED driver to devm_kzalloc() and cleanup error
    exit path
  leds: convert DAC124S085 LED driver to devm_kzalloc()
  leds: convert Network Space v2 LED driver to devm_kzalloc() and
    cleanup error exit path
  leds: convert transient LED trigger driver to devm_kzalloc()
  leds: convert GPIO LED trigger driver to devm_kzalloc() and cleanup
    error exit path
  leds: convert Backlight emulation LED trigger driver to
    devm_kzalloc() and cleanup error exit path
  leds: convert Heartbeat LED trigger driver to devm_kzalloc()
  leds: convert One-shot LED trigger driver to devm_kzalloc() and
    cleanup error exit path

 drivers/leds/leds-adp5520.c      |    8 +++-----
 drivers/leds/leds-asic3.c        |   16 ++++++----------
 drivers/leds/leds-atmel-pwm.c    |    5 ++---
 drivers/leds/leds-bd2802.c       |    8 ++------
 drivers/leds/leds-da903x.c       |    9 ++-------
 drivers/leds/leds-dac124s085.c   |    4 +---
 drivers/leds/leds-lm3530.c       |   24 ++++++++----------------
 drivers/leds/leds-lp3944.c       |    9 +++------
 drivers/leds/leds-lp5521.c       |   18 +++++++-----------
 drivers/leds/leds-lp5523.c       |   24 ++++++++++--------------
 drivers/leds/leds-lt3593.c       |    9 +++------
 drivers/leds/leds-mc13783.c      |    8 +++-----
 drivers/leds/leds-netxbig.c      |   10 +++-------
 drivers/leds/leds-ns2.c          |   19 ++++++-------------
 drivers/leds/leds-pca9532.c      |   10 ++--------
 drivers/leds/leds-pca955x.c      |   18 +++++-------------
 drivers/leds/leds-pca9633.c      |    6 +-----
 drivers/leds/leds-renesas-tpu.c  |   23 +++++++++--------------
 drivers/leds/leds-sunfire.c      |   21 ++++++---------------
 drivers/leds/leds-tca6507.c      |    4 +---
 drivers/leds/ledtrig-backlight.c |   10 +++-------
 drivers/leds/ledtrig-gpio.c      |    8 ++------
 drivers/leds/ledtrig-heartbeat.c |    4 ++--
 drivers/leds/ledtrig-oneshot.c   |    8 +++-----
 drivers/leds/ledtrig-transient.c |    5 ++---
 25 files changed, 95 insertions(+), 193 deletions(-)

-- 
1.7.10.4


^ permalink raw reply	[flat|nested] 38+ messages in thread

* [PATCH 01/25] leds: convert Big Networks LED driver to devm_kzalloc()
  2012-07-04  5:09 [PATCH 00/25] leds: convert all kzalloc() to devm_kzalloc() Bryan Wu
@ 2012-07-04  5:09 ` Bryan Wu
  2012-07-04  5:09 ` [PATCH 02/25] leds: convert HTC ASIC3 LED driver to devm_kzalloc() and cleanup error exit path Bryan Wu
                   ` (23 subsequent siblings)
  24 siblings, 0 replies; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  5:09 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

Cc: Simon Guinot <sguinot@lacie.com>
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
 drivers/leds/leds-netxbig.c |   10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/leds/leds-netxbig.c b/drivers/leds/leds-netxbig.c
index 73973fd..e37618e 100644
--- a/drivers/leds/leds-netxbig.c
+++ b/drivers/leds/leds-netxbig.c
@@ -362,14 +362,14 @@ static int __devinit netxbig_led_probe(struct platform_device *pdev)
 	if (!pdata)
 		return -EINVAL;
 
-	leds_data = kzalloc(sizeof(struct netxbig_led_data) * pdata->num_leds,
-			    GFP_KERNEL);
+	leds_data = devm_kzalloc(&pdev->dev,
+		sizeof(struct netxbig_led_data) * pdata->num_leds, GFP_KERNEL);
 	if (!leds_data)
 		return -ENOMEM;
 
 	ret = gpio_ext_init(pdata->gpio_ext);
 	if (ret < 0)
-		goto err_free_data;
+		return ret;
 
 	for (i = 0; i < pdata->num_leds; i++) {
 		ret = create_netxbig_led(pdev, &leds_data[i], &pdata->leds[i]);
@@ -386,9 +386,6 @@ err_free_leds:
 		delete_netxbig_led(&leds_data[i]);
 
 	gpio_ext_free(pdata->gpio_ext);
-err_free_data:
-	kfree(leds_data);
-
 	return ret;
 }
 
@@ -404,7 +401,6 @@ static int __devexit netxbig_led_remove(struct platform_device *pdev)
 		delete_netxbig_led(&leds_data[i]);
 
 	gpio_ext_free(pdata->gpio_ext);
-	kfree(leds_data);
 
 	return 0;
 }
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 02/25] leds: convert HTC ASIC3 LED driver to devm_kzalloc() and cleanup error exit path
  2012-07-04  5:09 [PATCH 00/25] leds: convert all kzalloc() to devm_kzalloc() Bryan Wu
  2012-07-04  5:09 ` [PATCH 01/25] leds: convert Big Networks LED driver " Bryan Wu
@ 2012-07-04  5:09 ` Bryan Wu
  2012-07-04  5:09 ` [PATCH 03/25] leds: convert Atmel PWM LED driver to devm_kzalloc() Bryan Wu
                   ` (22 subsequent siblings)
  24 siblings, 0 replies; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  5:09 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

Cc: Paul Parsons <lost.distance@yahoo.com>
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
 drivers/leds/leds-asic3.c |   16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/drivers/leds/leds-asic3.c b/drivers/leds/leds-asic3.c
index 525a924..5de74ff 100644
--- a/drivers/leds/leds-asic3.c
+++ b/drivers/leds/leds-asic3.c
@@ -99,12 +99,13 @@ static int __devinit asic3_led_probe(struct platform_device *pdev)
 
 	ret = mfd_cell_enable(pdev);
 	if (ret < 0)
-		goto ret0;
+		return ret;
 
-	led->cdev = kzalloc(sizeof(struct led_classdev), GFP_KERNEL);
+	led->cdev = devm_kzalloc(&pdev->dev, sizeof(struct led_classdev),
+				GFP_KERNEL);
 	if (!led->cdev) {
 		ret = -ENOMEM;
-		goto ret1;
+		goto out;
 	}
 
 	led->cdev->name = led->name;
@@ -115,15 +116,12 @@ static int __devinit asic3_led_probe(struct platform_device *pdev)
 
 	ret = led_classdev_register(&pdev->dev, led->cdev);
 	if (ret < 0)
-		goto ret2;
+		goto out;
 
 	return 0;
 
-ret2:
-	kfree(led->cdev);
-ret1:
+out:
 	(void) mfd_cell_disable(pdev);
-ret0:
 	return ret;
 }
 
@@ -133,8 +131,6 @@ static int __devexit asic3_led_remove(struct platform_device *pdev)
 
 	led_classdev_unregister(led->cdev);
 
-	kfree(led->cdev);
-
 	return mfd_cell_disable(pdev);
 }
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 03/25] leds: convert Atmel PWM LED driver to devm_kzalloc()
  2012-07-04  5:09 [PATCH 00/25] leds: convert all kzalloc() to devm_kzalloc() Bryan Wu
  2012-07-04  5:09 ` [PATCH 01/25] leds: convert Big Networks LED driver " Bryan Wu
  2012-07-04  5:09 ` [PATCH 02/25] leds: convert HTC ASIC3 LED driver to devm_kzalloc() and cleanup error exit path Bryan Wu
@ 2012-07-04  5:09 ` Bryan Wu
  2012-07-04  5:09 ` [PATCH 04/25] leds: convert LP3944 " Bryan Wu
                   ` (21 subsequent siblings)
  24 siblings, 0 replies; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  5:09 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
 drivers/leds/leds-atmel-pwm.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/leds/leds-atmel-pwm.c b/drivers/leds/leds-atmel-pwm.c
index 64ad702..4543063 100644
--- a/drivers/leds/leds-atmel-pwm.c
+++ b/drivers/leds/leds-atmel-pwm.c
@@ -46,7 +46,8 @@ static int __devinit pwmled_probe(struct platform_device *pdev)
 	if (!pdata || pdata->num_leds < 1)
 		return -ENODEV;
 
-	leds = kcalloc(pdata->num_leds, sizeof(*leds), GFP_KERNEL);
+	leds = devm_kzalloc(&pdev->dev, pdata->num_leds * sizeof(*leds),
+			GFP_KERNEL);
 	if (!leds)
 		return -ENOMEM;
 
@@ -108,7 +109,6 @@ err:
 			pwm_channel_free(&leds[i].pwmc);
 		}
 	}
-	kfree(leds);
 
 	return status;
 }
@@ -129,7 +129,6 @@ static int __exit pwmled_remove(struct platform_device *pdev)
 		pwm_channel_free(&led->pwmc);
 	}
 
-	kfree(leds);
 	platform_set_drvdata(pdev, NULL);
 	return 0;
 }
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 04/25] leds: convert LP3944 LED driver to devm_kzalloc()
  2012-07-04  5:09 [PATCH 00/25] leds: convert all kzalloc() to devm_kzalloc() Bryan Wu
                   ` (2 preceding siblings ...)
  2012-07-04  5:09 ` [PATCH 03/25] leds: convert Atmel PWM LED driver to devm_kzalloc() Bryan Wu
@ 2012-07-04  5:09 ` Bryan Wu
  2012-07-04  7:34   ` Bryan Wu
  2012-07-04  5:09 ` [PATCH 05/25] leds: convert DA9030/DA9034 LED driver to devm_kzalloc() and cleanup error exit path Bryan Wu
                   ` (20 subsequent siblings)
  24 siblings, 1 reply; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  5:09 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

Cc: Antonio Ospite <ospite@studenti.unina.it>
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
 drivers/leds/leds-lp3944.c |    9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/leds/leds-lp3944.c b/drivers/leds/leds-lp3944.c
index b8f9f0a..e8b1021 100644
--- a/drivers/leds/leds-lp3944.c
+++ b/drivers/leds/leds-lp3944.c
@@ -393,7 +393,8 @@ static int __devinit lp3944_probe(struct i2c_client *client,
 		return -ENODEV;
 	}
 
-	data = kzalloc(sizeof(struct lp3944_data), GFP_KERNEL);
+	data = devm_kzalloc(&pdev->dev, sizeof(struct lp3944_data),
+			GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
 
@@ -403,10 +404,8 @@ static int __devinit lp3944_probe(struct i2c_client *client,
 	mutex_init(&data->lock);
 
 	err = lp3944_configure(client, data, lp3944_pdata);
-	if (err < 0) {
-		kfree(data);
+	if (err < 0)
 		return err;
-	}
 
 	dev_info(&client->dev, "lp3944 enabled\n");
 	return 0;
@@ -431,8 +430,6 @@ static int __devexit lp3944_remove(struct i2c_client *client)
 			break;
 		}
 
-	kfree(data);
-
 	return 0;
 }
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 05/25] leds: convert DA9030/DA9034 LED driver to devm_kzalloc() and cleanup error exit path
  2012-07-04  5:09 [PATCH 00/25] leds: convert all kzalloc() to devm_kzalloc() Bryan Wu
                   ` (3 preceding siblings ...)
  2012-07-04  5:09 ` [PATCH 04/25] leds: convert LP3944 " Bryan Wu
@ 2012-07-04  5:09 ` Bryan Wu
  2012-07-04  5:09 ` [PATCH 06/25] leds: convert LP5521 " Bryan Wu
                   ` (19 subsequent siblings)
  24 siblings, 0 replies; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  5:09 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

Cc: Eric Miao <eric.miao@canonical.com>
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
 drivers/leds/leds-da903x.c |    9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/leds/leds-da903x.c b/drivers/leds/leds-da903x.c
index d9cd73e..cc77c9d 100644
--- a/drivers/leds/leds-da903x.c
+++ b/drivers/leds/leds-da903x.c
@@ -108,7 +108,7 @@ static int __devinit da903x_led_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	led = kzalloc(sizeof(struct da903x_led), GFP_KERNEL);
+	led = devm_kzalloc(&pdev->dev, sizeof(struct da903x_led), GFP_KERNEL);
 	if (led == NULL) {
 		dev_err(&pdev->dev, "failed to alloc memory for LED%d\n", id);
 		return -ENOMEM;
@@ -129,15 +129,11 @@ static int __devinit da903x_led_probe(struct platform_device *pdev)
 	ret = led_classdev_register(led->master, &led->cdev);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to register LED %d\n", id);
-		goto err;
+		return ret;
 	}
 
 	platform_set_drvdata(pdev, led);
 	return 0;
-
-err:
-	kfree(led);
-	return ret;
 }
 
 static int __devexit da903x_led_remove(struct platform_device *pdev)
@@ -145,7 +141,6 @@ static int __devexit da903x_led_remove(struct platform_device *pdev)
 	struct da903x_led *led = platform_get_drvdata(pdev);
 
 	led_classdev_unregister(&led->cdev);
-	kfree(led);
 	return 0;
 }
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 06/25] leds: convert LP5521 LED driver to devm_kzalloc() and cleanup error exit path
  2012-07-04  5:09 [PATCH 00/25] leds: convert all kzalloc() to devm_kzalloc() Bryan Wu
                   ` (4 preceding siblings ...)
  2012-07-04  5:09 ` [PATCH 05/25] leds: convert DA9030/DA9034 LED driver to devm_kzalloc() and cleanup error exit path Bryan Wu
@ 2012-07-04  5:09 ` Bryan Wu
  2012-07-04  7:35   ` Bryan Wu
  2012-07-04  5:09 ` [PATCH 07/25] leds: convert BD2802 RGB " Bryan Wu
                   ` (18 subsequent siblings)
  24 siblings, 1 reply; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  5:09 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
 drivers/leds/leds-lp5521.c |   18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c
index 2381562..760d743 100644
--- a/drivers/leds/leds-lp5521.c
+++ b/drivers/leds/leds-lp5521.c
@@ -744,7 +744,7 @@ static int __devinit lp5521_probe(struct i2c_client *client,
 	int ret, i, led;
 	u8 buf;
 
-	chip = kzalloc(sizeof(*chip), GFP_KERNEL);
+	chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
 	if (!chip)
 		return -ENOMEM;
 
@@ -755,8 +755,7 @@ static int __devinit lp5521_probe(struct i2c_client *client,
 
 	if (!pdata) {
 		dev_err(&client->dev, "no platform data\n");
-		ret = -EINVAL;
-		goto fail1;
+		return -EINVAL;
 	}
 
 	mutex_init(&chip->lock);
@@ -766,7 +765,7 @@ static int __devinit lp5521_probe(struct i2c_client *client,
 	if (pdata->setup_resources) {
 		ret = pdata->setup_resources();
 		if (ret < 0)
-			goto fail1;
+			return ret;
 	}
 
 	if (pdata->enable) {
@@ -807,7 +806,7 @@ static int __devinit lp5521_probe(struct i2c_client *client,
 	ret = lp5521_configure(client);
 	if (ret < 0) {
 		dev_err(&client->dev, "error configuring chip\n");
-		goto fail2;
+		goto fail1;
 	}
 
 	/* Initialize leds */
@@ -840,21 +839,19 @@ static int __devinit lp5521_probe(struct i2c_client *client,
 	ret = lp5521_register_sysfs(client);
 	if (ret) {
 		dev_err(&client->dev, "registering sysfs failed\n");
-		goto fail3;
+		goto fail2;
 	}
 	return ret;
-fail3:
+fail2:
 	for (i = 0; i < chip->num_leds; i++) {
 		led_classdev_unregister(&chip->leds[i].cdev);
 		cancel_work_sync(&chip->leds[i].brightness_work);
 	}
-fail2:
+fail1:
 	if (pdata->enable)
 		pdata->enable(0);
 	if (pdata->release_resources)
 		pdata->release_resources();
-fail1:
-	kfree(chip);
 	return ret;
 }
 
@@ -875,7 +872,6 @@ static int __devexit lp5521_remove(struct i2c_client *client)
 		chip->pdata->enable(0);
 	if (chip->pdata->release_resources)
 		chip->pdata->release_resources();
-	kfree(chip);
 	return 0;
 }
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 07/25] leds: convert BD2802 RGB LED driver to devm_kzalloc() and cleanup error exit path
  2012-07-04  5:09 [PATCH 00/25] leds: convert all kzalloc() to devm_kzalloc() Bryan Wu
                   ` (5 preceding siblings ...)
  2012-07-04  5:09 ` [PATCH 06/25] leds: convert LP5521 " Bryan Wu
@ 2012-07-04  5:09 ` Bryan Wu
  2012-07-04  5:10 ` [PATCH 08/25] leds: convert PCA9633 LED driver to devm_kzalloc() Bryan Wu
                   ` (17 subsequent siblings)
  24 siblings, 0 replies; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  5:09 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

Cc: Kim Kyuwon <q1.kim@samsung.com>
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
 drivers/leds/leds-bd2802.c |    8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/leds/leds-bd2802.c b/drivers/leds/leds-bd2802.c
index 591cbdf..89ca6a2 100644
--- a/drivers/leds/leds-bd2802.c
+++ b/drivers/leds/leds-bd2802.c
@@ -677,7 +677,7 @@ static int __devinit bd2802_probe(struct i2c_client *client,
 	struct bd2802_led_platform_data *pdata;
 	int ret, i;
 
-	led = kzalloc(sizeof(struct bd2802_led), GFP_KERNEL);
+	led = devm_kzalloc(&client->dev, sizeof(struct bd2802_led), GFP_KERNEL);
 	if (!led) {
 		dev_err(&client->dev, "failed to allocate driver data\n");
 		return -ENOMEM;
@@ -697,7 +697,7 @@ static int __devinit bd2802_probe(struct i2c_client *client,
 	ret = bd2802_write_byte(client, BD2802_REG_CLKSETUP, 0x00);
 	if (ret < 0) {
 		dev_err(&client->dev, "failed to detect device\n");
-		goto failed_free;
+		return ret;
 	} else
 		dev_info(&client->dev, "return 0x%02x\n", ret);
 
@@ -729,9 +729,6 @@ static int __devinit bd2802_probe(struct i2c_client *client,
 failed_unregister_dev_file:
 	for (i--; i >= 0; i--)
 		device_remove_file(&led->client->dev, bd2802_attributes[i]);
-failed_free:
-	kfree(led);
-
 	return ret;
 }
 
@@ -746,7 +743,6 @@ static int __exit bd2802_remove(struct i2c_client *client)
 		bd2802_disable_adv_conf(led);
 	for (i = 0; i < ARRAY_SIZE(bd2802_attributes); i++)
 		device_remove_file(&led->client->dev, bd2802_attributes[i]);
-	kfree(led);
 
 	return 0;
 }
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 08/25] leds: convert PCA9633 LED driver to devm_kzalloc()
  2012-07-04  5:09 [PATCH 00/25] leds: convert all kzalloc() to devm_kzalloc() Bryan Wu
                   ` (6 preceding siblings ...)
  2012-07-04  5:09 ` [PATCH 07/25] leds: convert BD2802 RGB " Bryan Wu
@ 2012-07-04  5:10 ` Bryan Wu
  2012-07-04  5:10 ` [PATCH 09/25] leds: convert LP5523 LED driver to devm_kzalloc() and cleanup error exit path Bryan Wu
                   ` (16 subsequent siblings)
  24 siblings, 0 replies; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  5:10 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

Cc: Peter Meerwald <p.meerwald@bct-electronic.com>
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
 drivers/leds/leds-pca9633.c |    6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/leds/leds-pca9633.c b/drivers/leds/leds-pca9633.c
index d8926fd..edcd706 100644
--- a/drivers/leds/leds-pca9633.c
+++ b/drivers/leds/leds-pca9633.c
@@ -108,7 +108,7 @@ static int __devinit pca9633_probe(struct i2c_client *client,
 		}
 	}
 
-	pca9633 = kcalloc(4, sizeof(*pca9633), GFP_KERNEL);
+	pca9633 = devm_kzalloc(&client->dev, 4 * sizeof(*pca9633), GFP_KERNEL);
 	if (!pca9633)
 		return -ENOMEM;
 
@@ -156,8 +156,6 @@ exit:
 		cancel_work_sync(&pca9633[i].work);
 	}
 
-	kfree(pca9633);
-
 	return err;
 }
 
@@ -171,8 +169,6 @@ static int __devexit pca9633_remove(struct i2c_client *client)
 		cancel_work_sync(&pca9633[i].work);
 	}
 
-	kfree(pca9633);
-
 	return 0;
 }
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 09/25] leds: convert LP5523 LED driver to devm_kzalloc() and cleanup error exit path
  2012-07-04  5:09 [PATCH 00/25] leds: convert all kzalloc() to devm_kzalloc() Bryan Wu
                   ` (7 preceding siblings ...)
  2012-07-04  5:10 ` [PATCH 08/25] leds: convert PCA9633 LED driver to devm_kzalloc() Bryan Wu
@ 2012-07-04  5:10 ` Bryan Wu
  2012-07-04  5:10 ` [PATCH 10/25] leds: convert Renesas TPU " Bryan Wu
                   ` (15 subsequent siblings)
  24 siblings, 0 replies; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  5:10 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

Cc: Mathias Nyman <mathias.nyman@nokia.com>
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
 drivers/leds/leds-lp5523.c |   24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c
index e8a2712..fbc12ac 100644
--- a/drivers/leds/leds-lp5523.c
+++ b/drivers/leds/leds-lp5523.c
@@ -877,7 +877,7 @@ static int __devinit lp5523_probe(struct i2c_client *client,
 	struct lp5523_platform_data	*pdata;
 	int ret, i, led;
 
-	chip = kzalloc(sizeof(*chip), GFP_KERNEL);
+	chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
 	if (!chip)
 		return -ENOMEM;
 
@@ -888,8 +888,7 @@ static int __devinit lp5523_probe(struct i2c_client *client,
 
 	if (!pdata) {
 		dev_err(&client->dev, "no platform data\n");
-		ret = -EINVAL;
-		goto fail1;
+		return -EINVAL;
 	}
 
 	mutex_init(&chip->lock);
@@ -899,7 +898,7 @@ static int __devinit lp5523_probe(struct i2c_client *client,
 	if (pdata->setup_resources) {
 		ret = pdata->setup_resources();
 		if (ret < 0)
-			goto fail1;
+			return ret;
 	}
 
 	if (pdata->enable) {
@@ -916,7 +915,7 @@ static int __devinit lp5523_probe(struct i2c_client *client,
 				     */
 	ret = lp5523_detect(client);
 	if (ret)
-		goto fail2;
+		goto fail1;
 
 	dev_info(&client->dev, "LP5523 Programmable led chip found\n");
 
@@ -925,13 +924,13 @@ static int __devinit lp5523_probe(struct i2c_client *client,
 		ret = lp5523_init_engine(&chip->engines[i], i + 1);
 		if (ret) {
 			dev_err(&client->dev, "error initializing engine\n");
-			goto fail2;
+			goto fail1;
 		}
 	}
 	ret = lp5523_configure(client);
 	if (ret < 0) {
 		dev_err(&client->dev, "error configuring chip\n");
-		goto fail2;
+		goto fail1;
 	}
 
 	/* Initialize leds */
@@ -949,7 +948,7 @@ static int __devinit lp5523_probe(struct i2c_client *client,
 		ret = lp5523_init_led(&chip->leds[led], &client->dev, i, pdata);
 		if (ret) {
 			dev_err(&client->dev, "error initializing leds\n");
-			goto fail3;
+			goto fail2;
 		}
 		chip->num_leds++;
 
@@ -965,21 +964,19 @@ static int __devinit lp5523_probe(struct i2c_client *client,
 	ret = lp5523_register_sysfs(client);
 	if (ret) {
 		dev_err(&client->dev, "registering sysfs failed\n");
-		goto fail3;
+		goto fail2;
 	}
 	return ret;
-fail3:
+fail2:
 	for (i = 0; i < chip->num_leds; i++) {
 		led_classdev_unregister(&chip->leds[i].cdev);
 		cancel_work_sync(&chip->leds[i].brightness_work);
 	}
-fail2:
+fail1:
 	if (pdata->enable)
 		pdata->enable(0);
 	if (pdata->release_resources)
 		pdata->release_resources();
-fail1:
-	kfree(chip);
 	return ret;
 }
 
@@ -999,7 +996,6 @@ static int lp5523_remove(struct i2c_client *client)
 		chip->pdata->enable(0);
 	if (chip->pdata->release_resources)
 		chip->pdata->release_resources();
-	kfree(chip);
 	return 0;
 }
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 10/25] leds: convert Renesas TPU LED driver to devm_kzalloc() and cleanup error exit path
  2012-07-04  5:09 [PATCH 00/25] leds: convert all kzalloc() to devm_kzalloc() Bryan Wu
                   ` (8 preceding siblings ...)
  2012-07-04  5:10 ` [PATCH 09/25] leds: convert LP5523 LED driver to devm_kzalloc() and cleanup error exit path Bryan Wu
@ 2012-07-04  5:10 ` Bryan Wu
  2012-07-04  5:10 ` [PATCH 11/25] leds: convert LT3593 LED driver to devm_kzalloc() Bryan Wu
                   ` (14 subsequent siblings)
  24 siblings, 0 replies; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  5:10 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

Cc: Magnus Damm <damm@opensource.se>
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
 drivers/leds/leds-renesas-tpu.c |   23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/drivers/leds/leds-renesas-tpu.c b/drivers/leds/leds-renesas-tpu.c
index 32fe337..9ee12c2 100644
--- a/drivers/leds/leds-renesas-tpu.c
+++ b/drivers/leds/leds-renesas-tpu.c
@@ -243,31 +243,30 @@ static int __devinit r_tpu_probe(struct platform_device *pdev)
 	struct led_renesas_tpu_config *cfg = pdev->dev.platform_data;
 	struct r_tpu_priv *p;
 	struct resource *res;
-	int ret = -ENXIO;
+	int ret;
 
 	if (!cfg) {
 		dev_err(&pdev->dev, "missing platform data\n");
 		goto err0;
 	}
 
-	p = kzalloc(sizeof(*p), GFP_KERNEL);
+	p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL);
 	if (p == NULL) {
 		dev_err(&pdev->dev, "failed to allocate driver data\n");
-		ret = -ENOMEM;
-		goto err0;
+		return -ENOMEM;
 	}
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!res) {
 		dev_err(&pdev->dev, "failed to get I/O memory\n");
-		goto err1;
+		return -ENXIO;
 	}
 
 	/* map memory, let mapbase point to our channel */
 	p->mapbase = ioremap_nocache(res->start, resource_size(res));
 	if (p->mapbase == NULL) {
 		dev_err(&pdev->dev, "failed to remap I/O memory\n");
-		goto err1;
+		return -ENXIO;
 	}
 
 	/* get hold of clock */
@@ -275,7 +274,7 @@ static int __devinit r_tpu_probe(struct platform_device *pdev)
 	if (IS_ERR(p->clk)) {
 		dev_err(&pdev->dev, "cannot get clock\n");
 		ret = PTR_ERR(p->clk);
-		goto err2;
+		goto err0;
 	}
 
 	p->pdev = pdev;
@@ -294,7 +293,7 @@ static int __devinit r_tpu_probe(struct platform_device *pdev)
 	p->ldev.flags |= LED_CORE_SUSPENDRESUME;
 	ret = led_classdev_register(&pdev->dev, &p->ldev);
 	if (ret < 0)
-		goto err3;
+		goto err1;
 
 	/* max_brightness may be updated by the LED core code */
 	p->min_rate = p->ldev.max_brightness * p->refresh_rate;
@@ -302,14 +301,11 @@ static int __devinit r_tpu_probe(struct platform_device *pdev)
 	pm_runtime_enable(&pdev->dev);
 	return 0;
 
- err3:
+ err1:
 	r_tpu_set_pin(p, R_TPU_PIN_UNUSED, LED_OFF);
 	clk_put(p->clk);
- err2:
-	iounmap(p->mapbase);
- err1:
-	kfree(p);
  err0:
+	iounmap(p->mapbase);
 	return ret;
 }
 
@@ -327,7 +323,6 @@ static int __devexit r_tpu_remove(struct platform_device *pdev)
 	clk_put(p->clk);
 
 	iounmap(p->mapbase);
-	kfree(p);
 	return 0;
 }
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 11/25] leds: convert LT3593 LED driver to devm_kzalloc()
  2012-07-04  5:09 [PATCH 00/25] leds: convert all kzalloc() to devm_kzalloc() Bryan Wu
                   ` (9 preceding siblings ...)
  2012-07-04  5:10 ` [PATCH 10/25] leds: convert Renesas TPU " Bryan Wu
@ 2012-07-04  5:10 ` Bryan Wu
  2012-07-04  5:10 ` [PATCH 12/25] leds: convert PCA9532 " Bryan Wu
                   ` (13 subsequent siblings)
  24 siblings, 0 replies; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  5:10 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

Cc: Daniel Mack <daniel@caiaq.de>
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
 drivers/leds/leds-lt3593.c |    9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/leds/leds-lt3593.c b/drivers/leds/leds-lt3593.c
index e311a96c..09a7322 100644
--- a/drivers/leds/leds-lt3593.c
+++ b/drivers/leds/leds-lt3593.c
@@ -149,8 +149,9 @@ static int __devinit lt3593_led_probe(struct platform_device *pdev)
 	if (!pdata)
 		return -EBUSY;
 
-	leds_data = kzalloc(sizeof(struct lt3593_led_data) * pdata->num_leds,
-				GFP_KERNEL);
+	leds_data = devm_kzalloc(&pdev->dev,
+			sizeof(struct lt3593_led_data) * pdata->num_leds,
+			GFP_KERNEL);
 	if (!leds_data)
 		return -ENOMEM;
 
@@ -169,8 +170,6 @@ err:
 	for (i = i - 1; i >= 0; i--)
 		delete_lt3593_led(&leds_data[i]);
 
-	kfree(leds_data);
-
 	return ret;
 }
 
@@ -185,8 +184,6 @@ static int __devexit lt3593_led_remove(struct platform_device *pdev)
 	for (i = 0; i < pdata->num_leds; i++)
 		delete_lt3593_led(&leds_data[i]);
 
-	kfree(leds_data);
-
 	return 0;
 }
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 12/25] leds: convert PCA9532 LED driver to devm_kzalloc()
  2012-07-04  5:09 [PATCH 00/25] leds: convert all kzalloc() to devm_kzalloc() Bryan Wu
                   ` (10 preceding siblings ...)
  2012-07-04  5:10 ` [PATCH 11/25] leds: convert LT3593 LED driver to devm_kzalloc() Bryan Wu
@ 2012-07-04  5:10 ` Bryan Wu
  2012-07-04  5:10 ` [PATCH 13/25] leds: convert Sun Fire LED driver to devm_kzalloc() and cleanup error exit path Bryan Wu
                   ` (12 subsequent siblings)
  24 siblings, 0 replies; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  5:10 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

Cc: Riku Voipio <riku.voipio@iki.fi>
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
 drivers/leds/leds-pca9532.c |   10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/leds/leds-pca9532.c b/drivers/leds/leds-pca9532.c
index ceccab4..cee8a5b 100644
--- a/drivers/leds/leds-pca9532.c
+++ b/drivers/leds/leds-pca9532.c
@@ -449,7 +449,6 @@ static int pca9532_probe(struct i2c_client *client,
 {
 	struct pca9532_data *data = i2c_get_clientdata(client);
 	struct pca9532_platform_data *pca9532_pdata = client->dev.platform_data;
-	int err;
 
 	if (!pca9532_pdata)
 		return -EIO;
@@ -458,7 +457,7 @@ static int pca9532_probe(struct i2c_client *client,
 		I2C_FUNC_SMBUS_BYTE_DATA))
 		return -EIO;
 
-	data = kzalloc(sizeof(*data), GFP_KERNEL);
+	data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
 
@@ -469,11 +468,7 @@ static int pca9532_probe(struct i2c_client *client,
 	data->client = client;
 	mutex_init(&data->update_lock);
 
-	err = pca9532_configure(client, data, pca9532_pdata);
-	if (err)
-		kfree(data);
-
-	return err;
+	return pca9532_configure(client, data, pca9532_pdata);
 }
 
 static int pca9532_remove(struct i2c_client *client)
@@ -485,7 +480,6 @@ static int pca9532_remove(struct i2c_client *client)
 	if (err)
 		return err;
 
-	kfree(data);
 	return 0;
 }
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 13/25] leds: convert Sun Fire LED driver to devm_kzalloc() and cleanup error exit path
  2012-07-04  5:09 [PATCH 00/25] leds: convert all kzalloc() to devm_kzalloc() Bryan Wu
                   ` (11 preceding siblings ...)
  2012-07-04  5:10 ` [PATCH 12/25] leds: convert PCA9532 " Bryan Wu
@ 2012-07-04  5:10 ` Bryan Wu
  2012-07-04  5:10 ` [PATCH 14/25] leds: convert PCA955x " Bryan Wu
                   ` (11 subsequent siblings)
  24 siblings, 0 replies; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  5:10 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

Cc: David S. Miller <davem@davemloft.net>
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
 drivers/leds/leds-sunfire.c |   21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/drivers/leds/leds-sunfire.c b/drivers/leds/leds-sunfire.c
index 1757396..134d9a4 100644
--- a/drivers/leds/leds-sunfire.c
+++ b/drivers/leds/leds-sunfire.c
@@ -132,15 +132,13 @@ static int __devinit sunfire_led_generic_probe(struct platform_device *pdev,
 	if (pdev->num_resources != 1) {
 		printk(KERN_ERR PFX "Wrong number of resources %d, should be 1\n",
 		       pdev->num_resources);
-		err = -EINVAL;
-		goto out;
+		return -EINVAL;
 	}
 
-	p = kzalloc(sizeof(*p), GFP_KERNEL);
+	p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL);
 	if (!p) {
 		printk(KERN_ERR PFX "Could not allocate struct sunfire_drvdata\n");
-		err = -ENOMEM;
-		goto out;
+		return -ENOMEM;
 	}
 
 	for (i = 0; i < NUM_LEDS_PER_BOARD; i++) {
@@ -156,20 +154,15 @@ static int __devinit sunfire_led_generic_probe(struct platform_device *pdev,
 		if (err) {
 			printk(KERN_ERR PFX "Could not register %s LED\n",
 			       lp->name);
-			goto out_unregister_led_cdevs;
+			for (i--; i >= 0; i--)
+				led_classdev_unregister(&p->leds[i].led_cdev);
+			return err;
 		}
 	}
 
 	dev_set_drvdata(&pdev->dev, p);
 
 	return 0;
-
-out_unregister_led_cdevs:
-	for (i--; i >= 0; i--)
-		led_classdev_unregister(&p->leds[i].led_cdev);
-	kfree(p);
-out:
-	return err;
 }
 
 static int __devexit sunfire_led_generic_remove(struct platform_device *pdev)
@@ -180,8 +173,6 @@ static int __devexit sunfire_led_generic_remove(struct platform_device *pdev)
 	for (i = 0; i < NUM_LEDS_PER_BOARD; i++)
 		led_classdev_unregister(&p->leds[i].led_cdev);
 
-	kfree(p);
-
 	return 0;
 }
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 14/25] leds: convert PCA955x LED driver to devm_kzalloc() and cleanup error exit path
  2012-07-04  5:09 [PATCH 00/25] leds: convert all kzalloc() to devm_kzalloc() Bryan Wu
                   ` (12 preceding siblings ...)
  2012-07-04  5:10 ` [PATCH 13/25] leds: convert Sun Fire LED driver to devm_kzalloc() and cleanup error exit path Bryan Wu
@ 2012-07-04  5:10 ` Bryan Wu
  2012-07-04  5:10 ` [PATCH 15/25] leds: convert ADP5520 " Bryan Wu
                   ` (10 subsequent siblings)
  24 siblings, 0 replies; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  5:10 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

Cc: Nate Case <ncase@xes-inc.com>
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
 drivers/leds/leds-pca955x.c |   18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/drivers/leds/leds-pca955x.c b/drivers/leds/leds-pca955x.c
index 5f462db..aef3cf0 100644
--- a/drivers/leds/leds-pca955x.c
+++ b/drivers/leds/leds-pca955x.c
@@ -293,15 +293,14 @@ static int __devinit pca955x_probe(struct i2c_client *client,
 		}
 	}
 
-	pca955x = kzalloc(sizeof(*pca955x), GFP_KERNEL);
+	pca955x = devm_kzalloc(&client->dev, sizeof(*pca955x), GFP_KERNEL);
 	if (!pca955x)
 		return -ENOMEM;
 
-	pca955x->leds = kzalloc(sizeof(*pca955x_led) * chip->bits, GFP_KERNEL);
-	if (!pca955x->leds) {
-		err = -ENOMEM;
-		goto exit_nomem;
-	}
+	pca955x->leds = devm_kzalloc(&client->dev,
+			sizeof(*pca955x_led) * chip->bits, GFP_KERNEL);
+	if (!pca955x->leds)
+		return -ENOMEM;
 
 	i2c_set_clientdata(client, pca955x);
 
@@ -361,10 +360,6 @@ exit:
 		cancel_work_sync(&pca955x->leds[i].work);
 	}
 
-	kfree(pca955x->leds);
-exit_nomem:
-	kfree(pca955x);
-
 	return err;
 }
 
@@ -378,9 +373,6 @@ static int __devexit pca955x_remove(struct i2c_client *client)
 		cancel_work_sync(&pca955x->leds[i].work);
 	}
 
-	kfree(pca955x->leds);
-	kfree(pca955x);
-
 	return 0;
 }
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 15/25] leds: convert ADP5520 LED driver to devm_kzalloc() and cleanup error exit path
  2012-07-04  5:09 [PATCH 00/25] leds: convert all kzalloc() to devm_kzalloc() Bryan Wu
                   ` (13 preceding siblings ...)
  2012-07-04  5:10 ` [PATCH 14/25] leds: convert PCA955x " Bryan Wu
@ 2012-07-04  5:10 ` Bryan Wu
  2012-07-04  7:40   ` Bryan Wu
  2012-07-04  5:10 ` [PATCH 16/25] leds: convert Freescale MC13783 " Bryan Wu
                   ` (9 subsequent siblings)
  24 siblings, 1 reply; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  5:10 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

Cc: Michael Hennerich <hennerich@blackfin.uclinux.org>
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
 drivers/leds/leds-adp5520.c |    8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/leds/leds-adp5520.c b/drivers/leds/leds-adp5520.c
index b1400db..72b110f 100644
--- a/drivers/leds/leds-adp5520.c
+++ b/drivers/leds/leds-adp5520.c
@@ -119,7 +119,8 @@ static int __devinit adp5520_led_probe(struct platform_device *pdev)
 		return -EFAULT;
 	}
 
-	led = kzalloc(sizeof(*led) * pdata->num_leds, GFP_KERNEL);
+	led = devm_kzalloc(&pdev->dev, sizeof(*led) * pdata->num_leds,
+				GFP_KERNEL);
 	if (led == NULL) {
 		dev_err(&pdev->dev, "failed to alloc memory\n");
 		return -ENOMEM;
@@ -129,7 +130,7 @@ static int __devinit adp5520_led_probe(struct platform_device *pdev)
 
 	if (ret) {
 		dev_err(&pdev->dev, "failed to write\n");
-		goto err_free;
+		return ret
 	}
 
 	for (i = 0; i < pdata->num_leds; ++i) {
@@ -179,8 +180,6 @@ err:
 		}
 	}
 
-err_free:
-	kfree(led);
 	return ret;
 }
 
@@ -200,7 +199,6 @@ static int __devexit adp5520_led_remove(struct platform_device *pdev)
 		cancel_work_sync(&led[i].work);
 	}
 
-	kfree(led);
 	return 0;
 }
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 16/25] leds: convert Freescale MC13783 LED driver to devm_kzalloc() and cleanup error exit path
  2012-07-04  5:09 [PATCH 00/25] leds: convert all kzalloc() to devm_kzalloc() Bryan Wu
                   ` (14 preceding siblings ...)
  2012-07-04  5:10 ` [PATCH 15/25] leds: convert ADP5520 " Bryan Wu
@ 2012-07-04  5:10 ` Bryan Wu
  2012-07-04  5:10 ` [PATCH 17/25] leds: convert TCA6507 LED driver to devm_kzalloc() Bryan Wu
                   ` (8 subsequent siblings)
  24 siblings, 0 replies; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  5:10 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

Cc: Philippe Retornaz <philippe.retornaz@epfl.ch>
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
 drivers/leds/leds-mc13783.c |    8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/leds/leds-mc13783.c b/drivers/leds/leds-mc13783.c
index 6515c11..2a5d434 100644
--- a/drivers/leds/leds-mc13783.c
+++ b/drivers/leds/leds-mc13783.c
@@ -280,7 +280,8 @@ static int __devinit mc13783_led_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	led = kcalloc(pdata->num_leds, sizeof(*led), GFP_KERNEL);
+	led = devm_kzalloc(&pdev->dev, pdata->num_leds * sizeof(*led),
+				GFP_KERNEL);
 	if (led == NULL) {
 		dev_err(&pdev->dev, "failed to alloc memory\n");
 		return -ENOMEM;
@@ -289,7 +290,7 @@ static int __devinit mc13783_led_probe(struct platform_device *pdev)
 	ret = mc13783_leds_prepare(pdev);
 	if (ret) {
 		dev_err(&pdev->dev, "unable to init led driver\n");
-		goto err_free;
+		return ret;
 	}
 
 	for (i = 0; i < pdata->num_leds; i++) {
@@ -344,8 +345,6 @@ err_register:
 		cancel_work_sync(&led[i].work);
 	}
 
-err_free:
-	kfree(led);
 	return ret;
 }
 
@@ -373,7 +372,6 @@ static int __devexit mc13783_led_remove(struct platform_device *pdev)
 	mc13xxx_unlock(dev);
 
 	platform_set_drvdata(pdev, NULL);
-	kfree(led);
 	return 0;
 }
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 17/25] leds: convert TCA6507 LED driver to devm_kzalloc()
  2012-07-04  5:09 [PATCH 00/25] leds: convert all kzalloc() to devm_kzalloc() Bryan Wu
                   ` (15 preceding siblings ...)
  2012-07-04  5:10 ` [PATCH 16/25] leds: convert Freescale MC13783 " Bryan Wu
@ 2012-07-04  5:10 ` Bryan Wu
  2012-07-04  5:10 ` [PATCH 18/25] leds: convert LM3530 LED driver to devm_kzalloc() and cleanup error exit path Bryan Wu
                   ` (7 subsequent siblings)
  24 siblings, 0 replies; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  5:10 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

Cc: Neil Brown <neilb@suse.de>
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
 drivers/leds/leds-tca6507.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/leds/leds-tca6507.c b/drivers/leds/leds-tca6507.c
index f74a45a..dabcf7a 100644
--- a/drivers/leds/leds-tca6507.c
+++ b/drivers/leds/leds-tca6507.c
@@ -687,7 +687,7 @@ static int __devinit tca6507_probe(struct i2c_client *client,
 			NUM_LEDS);
 		return -ENODEV;
 	}
-	tca = kzalloc(sizeof(*tca), GFP_KERNEL);
+	tca = devm_kzalloc(&client->dev, sizeof(*tca), GFP_KERNEL);
 	if (!tca)
 		return -ENOMEM;
 
@@ -727,7 +727,6 @@ exit:
 		if (tca->leds[i].led_cdev.name)
 			led_classdev_unregister(&tca->leds[i].led_cdev);
 	}
-	kfree(tca);
 	return err;
 }
 
@@ -743,7 +742,6 @@ static int __devexit tca6507_remove(struct i2c_client *client)
 	}
 	tca6507_remove_gpio(tca);
 	cancel_work_sync(&tca->work);
-	kfree(tca);
 
 	return 0;
 }
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 18/25] leds: convert LM3530 LED driver to devm_kzalloc() and cleanup error exit path
  2012-07-04  5:09 [PATCH 00/25] leds: convert all kzalloc() to devm_kzalloc() Bryan Wu
                   ` (16 preceding siblings ...)
  2012-07-04  5:10 ` [PATCH 17/25] leds: convert TCA6507 LED driver to devm_kzalloc() Bryan Wu
@ 2012-07-04  5:10 ` Bryan Wu
  2012-07-05  0:01   ` Linus Walleij
  2012-07-04  5:10 ` [PATCH 19/25] leds: convert DAC124S085 LED driver to devm_kzalloc() Bryan Wu
                   ` (6 subsequent siblings)
  24 siblings, 1 reply; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  5:10 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

Cc: Shreshtha Kumar SAHU <shreshthakumar.sahu@stericsson.com>
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
 drivers/leds/leds-lm3530.c |   24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/drivers/leds/leds-lm3530.c b/drivers/leds/leds-lm3530.c
index 84ba6de..23637bd 100644
--- a/drivers/leds/leds-lm3530.c
+++ b/drivers/leds/leds-lm3530.c
@@ -386,28 +386,24 @@ static int __devinit lm3530_probe(struct i2c_client *client,
 
 	if (pdata == NULL) {
 		dev_err(&client->dev, "platform data required\n");
-		err = -ENODEV;
-		goto err_out;
+		return -ENODEV;
 	}
 
 	/* BL mode */
 	if (pdata->mode > LM3530_BL_MODE_PWM) {
 		dev_err(&client->dev, "Illegal Mode request\n");
-		err = -EINVAL;
-		goto err_out;
+		return -EINVAL;
 	}
 
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
 		dev_err(&client->dev, "I2C_FUNC_I2C not supported\n");
-		err = -EIO;
-		goto err_out;
+		return -EIO;
 	}
 
-	drvdata = kzalloc(sizeof(struct lm3530_data), GFP_KERNEL);
-	if (drvdata == NULL) {
-		err = -ENOMEM;
-		goto err_out;
-	}
+	drvdata = devm_kzalloc(&client->dev, sizeof(struct lm3530_data),
+				GFP_KERNEL);
+	if (drvdata == NULL)
+		return -ENOMEM;
 
 	drvdata->mode = pdata->mode;
 	drvdata->client = client;
@@ -425,7 +421,7 @@ static int __devinit lm3530_probe(struct i2c_client *client,
 		dev_err(&client->dev, "regulator get failed\n");
 		err = PTR_ERR(drvdata->regulator);
 		drvdata->regulator = NULL;
-		goto err_regulator_get;
+		return err;
 	}
 
 	if (drvdata->pdata->brt_val) {
@@ -458,9 +454,6 @@ err_create_file:
 err_class_register:
 err_reg_init:
 	regulator_put(drvdata->regulator);
-err_regulator_get:
-	kfree(drvdata);
-err_out:
 	return err;
 }
 
@@ -474,7 +467,6 @@ static int __devexit lm3530_remove(struct i2c_client *client)
 		regulator_disable(drvdata->regulator);
 	regulator_put(drvdata->regulator);
 	led_classdev_unregister(&drvdata->led_dev);
-	kfree(drvdata);
 	return 0;
 }
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 19/25] leds: convert DAC124S085 LED driver to devm_kzalloc()
  2012-07-04  5:09 [PATCH 00/25] leds: convert all kzalloc() to devm_kzalloc() Bryan Wu
                   ` (17 preceding siblings ...)
  2012-07-04  5:10 ` [PATCH 18/25] leds: convert LM3530 LED driver to devm_kzalloc() and cleanup error exit path Bryan Wu
@ 2012-07-04  5:10 ` Bryan Wu
  2012-07-04  5:10 ` [PATCH 20/25] leds: convert Network Space v2 LED driver to devm_kzalloc() and cleanup error exit path Bryan Wu
                   ` (5 subsequent siblings)
  24 siblings, 0 replies; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  5:10 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

Cc: Guennadi Liakhovetski <lg@denx.de>
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
 drivers/leds/leds-dac124s085.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/leds/leds-dac124s085.c b/drivers/leds/leds-dac124s085.c
index d56c142..1f9d8e6 100644
--- a/drivers/leds/leds-dac124s085.c
+++ b/drivers/leds/leds-dac124s085.c
@@ -69,7 +69,7 @@ static int dac124s085_probe(struct spi_device *spi)
 	struct dac124s085_led	*led;
 	int i, ret;
 
-	dac = kzalloc(sizeof(*dac), GFP_KERNEL);
+	dac = devm_kzalloc(&spi->dev, sizeof(*dac), GFP_KERNEL);
 	if (!dac)
 		return -ENOMEM;
 
@@ -102,7 +102,6 @@ eledcr:
 		led_classdev_unregister(&dac->leds[i].ldev);
 
 	spi_set_drvdata(spi, NULL);
-	kfree(dac);
 	return ret;
 }
 
@@ -117,7 +116,6 @@ static int dac124s085_remove(struct spi_device *spi)
 	}
 
 	spi_set_drvdata(spi, NULL);
-	kfree(dac);
 
 	return 0;
 }
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 20/25] leds: convert Network Space v2 LED driver to devm_kzalloc() and cleanup error exit path
  2012-07-04  5:09 [PATCH 00/25] leds: convert all kzalloc() to devm_kzalloc() Bryan Wu
                   ` (18 preceding siblings ...)
  2012-07-04  5:10 ` [PATCH 19/25] leds: convert DAC124S085 LED driver to devm_kzalloc() Bryan Wu
@ 2012-07-04  5:10 ` Bryan Wu
  2012-07-04  5:10 ` [PATCH 21/25] leds: convert transient LED trigger driver to devm_kzalloc() Bryan Wu
                   ` (4 subsequent siblings)
  24 siblings, 0 replies; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  5:10 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

Cc: Simon Guinot <sguinot@lacie.com>
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
 drivers/leds/leds-ns2.c |   19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index 01cf89e..10528da 100644
--- a/drivers/leds/leds-ns2.c
+++ b/drivers/leds/leds-ns2.c
@@ -273,29 +273,23 @@ static int __devinit ns2_led_probe(struct platform_device *pdev)
 	if (!pdata)
 		return -EINVAL;
 
-	leds_data = kzalloc(sizeof(struct ns2_led_data) *
+	leds_data = devm_kzalloc(&pdev->dev, sizeof(struct ns2_led_data) *
 			    pdata->num_leds, GFP_KERNEL);
 	if (!leds_data)
 		return -ENOMEM;
 
 	for (i = 0; i < pdata->num_leds; i++) {
 		ret = create_ns2_led(pdev, &leds_data[i], &pdata->leds[i]);
-		if (ret < 0)
-			goto err;
-
+		if (ret < 0) {
+			for (i = i - 1; i >= 0; i--)
+				delete_ns2_led(&leds_data[i]);
+			return ret;
+		}
 	}
 
 	platform_set_drvdata(pdev, leds_data);
 
 	return 0;
-
-err:
-	for (i = i - 1; i >= 0; i--)
-		delete_ns2_led(&leds_data[i]);
-
-	kfree(leds_data);
-
-	return ret;
 }
 
 static int __devexit ns2_led_remove(struct platform_device *pdev)
@@ -309,7 +303,6 @@ static int __devexit ns2_led_remove(struct platform_device *pdev)
 	for (i = 0; i < pdata->num_leds; i++)
 		delete_ns2_led(&leds_data[i]);
 
-	kfree(leds_data);
 	platform_set_drvdata(pdev, NULL);
 
 	return 0;
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 21/25] leds: convert transient LED trigger driver to devm_kzalloc()
  2012-07-04  5:09 [PATCH 00/25] leds: convert all kzalloc() to devm_kzalloc() Bryan Wu
                   ` (19 preceding siblings ...)
  2012-07-04  5:10 ` [PATCH 20/25] leds: convert Network Space v2 LED driver to devm_kzalloc() and cleanup error exit path Bryan Wu
@ 2012-07-04  5:10 ` Bryan Wu
  2012-07-05 16:42   ` Shuah Khan
  2012-07-04  5:10 ` [PATCH 22/25] leds: convert GPIO LED trigger driver to devm_kzalloc() and cleanup error exit path Bryan Wu
                   ` (3 subsequent siblings)
  24 siblings, 1 reply; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  5:10 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

Cc: Shuah Khan <shuahkhan@gmail.com>
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
 drivers/leds/ledtrig-transient.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/leds/ledtrig-transient.c b/drivers/leds/ledtrig-transient.c
index 398f104..8e30b0df 100644
--- a/drivers/leds/ledtrig-transient.c
+++ b/drivers/leds/ledtrig-transient.c
@@ -161,7 +161,8 @@ static void transient_trig_activate(struct led_classdev *led_cdev)
 	int rc;
 	struct transient_trig_data *tdata;
 
-	tdata = kzalloc(sizeof(struct transient_trig_data), GFP_KERNEL);
+	tdata = devm_kzalloc(led_cdev->dev,
+		sizeof(struct transient_trig_data), GFP_KERNEL);
 	if (!tdata) {
 		dev_err(led_cdev->dev,
 			"unable to allocate transient trigger\n");
@@ -194,7 +195,6 @@ err_out_duration:
 err_out:
 	dev_err(led_cdev->dev, "unable to register transient trigger\n");
 	led_cdev->trigger_data = NULL;
-	kfree(tdata);
 }
 
 static void transient_trig_deactivate(struct led_classdev *led_cdev)
@@ -209,7 +209,6 @@ static void transient_trig_deactivate(struct led_classdev *led_cdev)
 		device_remove_file(led_cdev->dev, &dev_attr_state);
 		led_cdev->trigger_data = NULL;
 		led_cdev->activated = false;
-		kfree(transient_data);
 	}
 }
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 22/25] leds: convert GPIO LED trigger driver to devm_kzalloc() and cleanup error exit path
  2012-07-04  5:09 [PATCH 00/25] leds: convert all kzalloc() to devm_kzalloc() Bryan Wu
                   ` (20 preceding siblings ...)
  2012-07-04  5:10 ` [PATCH 21/25] leds: convert transient LED trigger driver to devm_kzalloc() Bryan Wu
@ 2012-07-04  5:10 ` Bryan Wu
  2012-07-05 16:45   ` Shuah Khan
  2012-07-04  5:10 ` [PATCH 23/25] leds: convert Backlight emulation " Bryan Wu
                   ` (2 subsequent siblings)
  24 siblings, 1 reply; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  5:10 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

Cc: Felipe Balbi <me@felipebalbi.com>
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
 drivers/leds/ledtrig-gpio.c |    8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/leds/ledtrig-gpio.c b/drivers/leds/ledtrig-gpio.c
index ba215dc..39bd8e4 100644
--- a/drivers/leds/ledtrig-gpio.c
+++ b/drivers/leds/ledtrig-gpio.c
@@ -181,13 +181,13 @@ static void gpio_trig_activate(struct led_classdev *led)
 	struct gpio_trig_data *gpio_data;
 	int ret;
 
-	gpio_data = kzalloc(sizeof(*gpio_data), GFP_KERNEL);
+	gpio_data = devm_kzalloc(led->dev, sizeof(*gpio_data), GFP_KERNEL);
 	if (!gpio_data)
 		return;
 
 	ret = device_create_file(led->dev, &dev_attr_gpio);
 	if (ret)
-		goto err_gpio;
+		return;
 
 	ret = device_create_file(led->dev, &dev_attr_inverted);
 	if (ret)
@@ -209,9 +209,6 @@ err_brightness:
 
 err_inverted:
 	device_remove_file(led->dev, &dev_attr_gpio);
-
-err_gpio:
-	kfree(gpio_data);
 }
 
 static void gpio_trig_deactivate(struct led_classdev *led)
@@ -225,7 +222,6 @@ static void gpio_trig_deactivate(struct led_classdev *led)
 		flush_work(&gpio_data->work);
 		if (gpio_data->gpio != 0)
 			free_irq(gpio_to_irq(gpio_data->gpio), led);
-		kfree(gpio_data);
 		led->activated = false;
 	}
 }
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 23/25] leds: convert Backlight emulation LED trigger driver to devm_kzalloc() and cleanup error exit path
  2012-07-04  5:09 [PATCH 00/25] leds: convert all kzalloc() to devm_kzalloc() Bryan Wu
                   ` (21 preceding siblings ...)
  2012-07-04  5:10 ` [PATCH 22/25] leds: convert GPIO LED trigger driver to devm_kzalloc() and cleanup error exit path Bryan Wu
@ 2012-07-04  5:10 ` Bryan Wu
  2012-07-05 16:46   ` Shuah Khan
  2012-07-04  5:10 ` [PATCH 24/25] leds: convert Heartbeat LED trigger driver to devm_kzalloc() Bryan Wu
  2012-07-04  5:10 ` [PATCH 25/25] leds: convert One-shot LED trigger driver to devm_kzalloc() and cleanup error exit path Bryan Wu
  24 siblings, 1 reply; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  5:10 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

Cc: Rodolfo Giometti <giometti@linux.it>
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
 drivers/leds/ledtrig-backlight.c |   10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/leds/ledtrig-backlight.c b/drivers/leds/ledtrig-backlight.c
index b941685..3fa20a9 100644
--- a/drivers/leds/ledtrig-backlight.c
+++ b/drivers/leds/ledtrig-backlight.c
@@ -101,7 +101,8 @@ static void bl_trig_activate(struct led_classdev *led)
 
 	struct bl_trig_notifier *n;
 
-	n = kzalloc(sizeof(struct bl_trig_notifier), GFP_KERNEL);
+	n = devm_kzalloc(led->dev, sizeof(struct bl_trig_notifier),
+			GFP_KERNEL);
 	led->trigger_data = n;
 	if (!n) {
 		dev_err(led->dev, "unable to allocate backlight trigger\n");
@@ -110,7 +111,7 @@ static void bl_trig_activate(struct led_classdev *led)
 
 	ret = device_create_file(led->dev, &dev_attr_inverted);
 	if (ret)
-		goto err_invert;
+		led->trigger_data = NULL;
 
 	n->led = led;
 	n->brightness = led->brightness;
@@ -123,10 +124,6 @@ static void bl_trig_activate(struct led_classdev *led)
 	led->activated = true;
 
 	return;
-
-err_invert:
-	led->trigger_data = NULL;
-	kfree(n);
 }
 
 static void bl_trig_deactivate(struct led_classdev *led)
@@ -137,7 +134,6 @@ static void bl_trig_deactivate(struct led_classdev *led)
 	if (led->activated) {
 		device_remove_file(led->dev, &dev_attr_inverted);
 		fb_unregister_client(&n->notifier);
-		kfree(n);
 		led->activated = false;
 	}
 }
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 24/25] leds: convert Heartbeat LED trigger driver to devm_kzalloc()
  2012-07-04  5:09 [PATCH 00/25] leds: convert all kzalloc() to devm_kzalloc() Bryan Wu
                   ` (22 preceding siblings ...)
  2012-07-04  5:10 ` [PATCH 23/25] leds: convert Backlight emulation " Bryan Wu
@ 2012-07-04  5:10 ` Bryan Wu
  2012-07-05 16:46   ` Shuah Khan
  2012-07-04  5:10 ` [PATCH 25/25] leds: convert One-shot LED trigger driver to devm_kzalloc() and cleanup error exit path Bryan Wu
  24 siblings, 1 reply; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  5:10 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

Cc: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
 drivers/leds/ledtrig-heartbeat.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/leds/ledtrig-heartbeat.c b/drivers/leds/ledtrig-heartbeat.c
index d3039f2..5caa01b 100644
--- a/drivers/leds/ledtrig-heartbeat.c
+++ b/drivers/leds/ledtrig-heartbeat.c
@@ -75,7 +75,8 @@ static void heartbeat_trig_activate(struct led_classdev *led_cdev)
 {
 	struct heartbeat_trig_data *heartbeat_data;
 
-	heartbeat_data = kzalloc(sizeof(*heartbeat_data), GFP_KERNEL);
+	heartbeat_data = devm_kzalloc(led_cdev->dev, sizeof(*heartbeat_data),
+				GFP_KERNEL);
 	if (!heartbeat_data)
 		return;
 
@@ -93,7 +94,6 @@ static void heartbeat_trig_deactivate(struct led_classdev *led_cdev)
 
 	if (led_cdev->activated) {
 		del_timer_sync(&heartbeat_data->timer);
-		kfree(heartbeat_data);
 		led_cdev->activated = false;
 	}
 }
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 25/25] leds: convert One-shot LED trigger driver to devm_kzalloc() and cleanup error exit path
  2012-07-04  5:09 [PATCH 00/25] leds: convert all kzalloc() to devm_kzalloc() Bryan Wu
                   ` (23 preceding siblings ...)
  2012-07-04  5:10 ` [PATCH 24/25] leds: convert Heartbeat LED trigger driver to devm_kzalloc() Bryan Wu
@ 2012-07-04  5:10 ` Bryan Wu
  2012-07-05 16:47   ` Shuah Khan
  24 siblings, 1 reply; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  5:10 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

Cc: Fabio Baltieri <fabio.baltieri@gmail.com>
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
 drivers/leds/ledtrig-oneshot.c |    8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/leds/ledtrig-oneshot.c b/drivers/leds/ledtrig-oneshot.c
index 2c029aa..6395a38 100644
--- a/drivers/leds/ledtrig-oneshot.c
+++ b/drivers/leds/ledtrig-oneshot.c
@@ -127,7 +127,8 @@ static void oneshot_trig_activate(struct led_classdev *led_cdev)
 	struct oneshot_trig_data *oneshot_data;
 	int rc;
 
-	oneshot_data = kzalloc(sizeof(*oneshot_data), GFP_KERNEL);
+	oneshot_data = devm_kzalloc(led_cdev->dev, sizeof(*oneshot_data),
+				GFP_KERNEL);
 	if (!oneshot_data)
 		return;
 
@@ -135,7 +136,7 @@ static void oneshot_trig_activate(struct led_classdev *led_cdev)
 
 	rc = device_create_file(led_cdev->dev, &dev_attr_delay_on);
 	if (rc)
-		goto err_out_trig_data;
+		return;
 	rc = device_create_file(led_cdev->dev, &dev_attr_delay_off);
 	if (rc)
 		goto err_out_delayon;
@@ -159,8 +160,6 @@ err_out_delayoff:
 	device_remove_file(led_cdev->dev, &dev_attr_delay_off);
 err_out_delayon:
 	device_remove_file(led_cdev->dev, &dev_attr_delay_on);
-err_out_trig_data:
-	kfree(led_cdev->trigger_data);
 }
 
 static void oneshot_trig_deactivate(struct led_classdev *led_cdev)
@@ -172,7 +171,6 @@ static void oneshot_trig_deactivate(struct led_classdev *led_cdev)
 		device_remove_file(led_cdev->dev, &dev_attr_delay_off);
 		device_remove_file(led_cdev->dev, &dev_attr_invert);
 		device_remove_file(led_cdev->dev, &dev_attr_shot);
-		kfree(oneshot_data);
 		led_cdev->activated = false;
 	}
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* Re: [PATCH 04/25] leds: convert LP3944 LED driver to devm_kzalloc()
  2012-07-04  5:09 ` [PATCH 04/25] leds: convert LP3944 " Bryan Wu
@ 2012-07-04  7:34   ` Bryan Wu
  0 siblings, 0 replies; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  7:34 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

On Wed, Jul 4, 2012 at 1:09 PM, Bryan Wu <bryan.wu@canonical.com> wrote:
> Cc: Antonio Ospite <ospite@studenti.unina.it>
> Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
> ---
>  drivers/leds/leds-lp3944.c |    9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/leds/leds-lp3944.c b/drivers/leds/leds-lp3944.c
> index b8f9f0a..e8b1021 100644
> --- a/drivers/leds/leds-lp3944.c
> +++ b/drivers/leds/leds-lp3944.c
> @@ -393,7 +393,8 @@ static int __devinit lp3944_probe(struct i2c_client *client,
>                 return -ENODEV;
>         }
>
> -       data = kzalloc(sizeof(struct lp3944_data), GFP_KERNEL);
> +       data = devm_kzalloc(&pdev->dev, sizeof(struct lp3944_data),

Sorry, this should be "devm_kzalloc(&client->dev, sizeof(struct lp3944_data),"
I've put the right version in my devel branch.

Thanks,
-Bryan

> +                       GFP_KERNEL);
>         if (!data)
>                 return -ENOMEM;
>
> @@ -403,10 +404,8 @@ static int __devinit lp3944_probe(struct i2c_client *client,
>         mutex_init(&data->lock);
>
>         err = lp3944_configure(client, data, lp3944_pdata);
> -       if (err < 0) {
> -               kfree(data);
> +       if (err < 0)
>                 return err;
> -       }
>
>         dev_info(&client->dev, "lp3944 enabled\n");
>         return 0;
> @@ -431,8 +430,6 @@ static int __devexit lp3944_remove(struct i2c_client *client)
>                         break;
>                 }
>
> -       kfree(data);
> -
>         return 0;
>  }
>
> --
> 1.7.10.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-leds" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



-- 
Bryan Wu <bryan.wu@canonical.com>
Kernel Developer    +86.186-168-78255 Mobile
Canonical Ltd.      www.canonical.com
Ubuntu - Linux for human beings | www.ubuntu.com

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 06/25] leds: convert LP5521 LED driver to devm_kzalloc() and cleanup error exit path
  2012-07-04  5:09 ` [PATCH 06/25] leds: convert LP5521 " Bryan Wu
@ 2012-07-04  7:35   ` Bryan Wu
  0 siblings, 0 replies; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  7:35 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

On Wed, Jul 4, 2012 at 1:09 PM, Bryan Wu <bryan.wu@canonical.com> wrote:
> Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
> ---
>  drivers/leds/leds-lp5521.c |   18 +++++++-----------
>  1 file changed, 7 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c
> index 2381562..760d743 100644
> --- a/drivers/leds/leds-lp5521.c
> +++ b/drivers/leds/leds-lp5521.c
> @@ -744,7 +744,7 @@ static int __devinit lp5521_probe(struct i2c_client *client,
>         int ret, i, led;
>         u8 buf;
>
> -       chip = kzalloc(sizeof(*chip), GFP_KERNEL);
> +       chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
>         if (!chip)
>                 return -ENOMEM;
>
> @@ -755,8 +755,7 @@ static int __devinit lp5521_probe(struct i2c_client *client,
>
>         if (!pdata) {
>                 dev_err(&client->dev, "no platform data\n");
> -               ret = -EINVAL;
> -               goto fail1;
> +               return -EINVAL;
>         }
>
>         mutex_init(&chip->lock);
> @@ -766,7 +765,7 @@ static int __devinit lp5521_probe(struct i2c_client *client,
>         if (pdata->setup_resources) {
>                 ret = pdata->setup_resources();
>                 if (ret < 0)
> -                       goto fail1;
> +                       return ret;
>         }
>
>         if (pdata->enable) {
> @@ -807,7 +806,7 @@ static int __devinit lp5521_probe(struct i2c_client *client,
>         ret = lp5521_configure(client);
>         if (ret < 0) {
>                 dev_err(&client->dev, "error configuring chip\n");
> -               goto fail2;
> +               goto fail1;
>         }
>
>         /* Initialize leds */
> @@ -840,21 +839,19 @@ static int __devinit lp5521_probe(struct i2c_client *client,
>         ret = lp5521_register_sysfs(client);
>         if (ret) {
>                 dev_err(&client->dev, "registering sysfs failed\n");
> -               goto fail3;
> +               goto fail2;
>         }
>         return ret;
> -fail3:
> +fail2:

Missed to change one 'fail3' to 'fail2', I've put the right version in
my devel branch.

Thanks,
-Bryan

>         for (i = 0; i < chip->num_leds; i++) {
>                 led_classdev_unregister(&chip->leds[i].cdev);
>                 cancel_work_sync(&chip->leds[i].brightness_work);
>         }
> -fail2:
> +fail1:
>         if (pdata->enable)
>                 pdata->enable(0);
>         if (pdata->release_resources)
>                 pdata->release_resources();
> -fail1:
> -       kfree(chip);
>         return ret;
>  }
>
> @@ -875,7 +872,6 @@ static int __devexit lp5521_remove(struct i2c_client *client)
>                 chip->pdata->enable(0);
>         if (chip->pdata->release_resources)
>                 chip->pdata->release_resources();
> -       kfree(chip);
>         return 0;
>  }
>
> --
> 1.7.10.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-leds" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



-- 
Bryan Wu <bryan.wu@canonical.com>
Kernel Developer    +86.186-168-78255 Mobile
Canonical Ltd.      www.canonical.com
Ubuntu - Linux for human beings | www.ubuntu.com

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 15/25] leds: convert ADP5520 LED driver to devm_kzalloc() and cleanup error exit path
  2012-07-04  5:10 ` [PATCH 15/25] leds: convert ADP5520 " Bryan Wu
@ 2012-07-04  7:40   ` Bryan Wu
  0 siblings, 0 replies; 38+ messages in thread
From: Bryan Wu @ 2012-07-04  7:40 UTC (permalink / raw)
  To: linux-leds, rpurdie, linux-kernel

On Wed, Jul 4, 2012 at 1:10 PM, Bryan Wu <bryan.wu@canonical.com> wrote:
> Cc: Michael Hennerich <hennerich@blackfin.uclinux.org>
> Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
> ---
>  drivers/leds/leds-adp5520.c |    8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/leds/leds-adp5520.c b/drivers/leds/leds-adp5520.c
> index b1400db..72b110f 100644
> --- a/drivers/leds/leds-adp5520.c
> +++ b/drivers/leds/leds-adp5520.c
> @@ -119,7 +119,8 @@ static int __devinit adp5520_led_probe(struct platform_device *pdev)
>                 return -EFAULT;
>         }
>
> -       led = kzalloc(sizeof(*led) * pdata->num_leds, GFP_KERNEL);
> +       led = devm_kzalloc(&pdev->dev, sizeof(*led) * pdata->num_leds,
> +                               GFP_KERNEL);
>         if (led == NULL) {
>                 dev_err(&pdev->dev, "failed to alloc memory\n");
>                 return -ENOMEM;
> @@ -129,7 +130,7 @@ static int __devinit adp5520_led_probe(struct platform_device *pdev)
>
>         if (ret) {
>                 dev_err(&pdev->dev, "failed to write\n");
> -               goto err_free;
> +               return ret
Missed one ";" at end of this line. I've fixed it in my devel branch.

Thanks,
-Bryan

>         }
>
>         for (i = 0; i < pdata->num_leds; ++i) {
> @@ -179,8 +180,6 @@ err:
>                 }
>         }
>
> -err_free:
> -       kfree(led);
>         return ret;
>  }
>
> @@ -200,7 +199,6 @@ static int __devexit adp5520_led_remove(struct platform_device *pdev)
>                 cancel_work_sync(&led[i].work);
>         }
>
> -       kfree(led);
>         return 0;
>  }
>
> --
> 1.7.10.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-leds" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



-- 
Bryan Wu <bryan.wu@canonical.com>
Kernel Developer    +86.186-168-78255 Mobile
Canonical Ltd.      www.canonical.com
Ubuntu - Linux for human beings | www.ubuntu.com

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 18/25] leds: convert LM3530 LED driver to devm_kzalloc() and cleanup error exit path
  2012-07-04  5:10 ` [PATCH 18/25] leds: convert LM3530 LED driver to devm_kzalloc() and cleanup error exit path Bryan Wu
@ 2012-07-05  0:01   ` Linus Walleij
  0 siblings, 0 replies; 38+ messages in thread
From: Linus Walleij @ 2012-07-05  0:01 UTC (permalink / raw)
  To: Bryan Wu; +Cc: linux-leds, rpurdie, linux-kernel

On Wed, Jul 4, 2012 at 7:10 AM, Bryan Wu <bryan.wu@canonical.com> wrote:

> Cc: Shreshtha Kumar SAHU <shreshthakumar.sahu@stericsson.com>
> Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
> ---
>  drivers/leds/leds-lm3530.c |   24 ++++++++----------------
>  1 file changed, 8 insertions(+), 16 deletions(-)

This is good stuff,
Acked-by: Linus Walleij <linus.walleij@linaro.org>

But make sure to send the patch by Andrew for it to be merged.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 21/25] leds: convert transient LED trigger driver to devm_kzalloc()
  2012-07-04  5:10 ` [PATCH 21/25] leds: convert transient LED trigger driver to devm_kzalloc() Bryan Wu
@ 2012-07-05 16:42   ` Shuah Khan
  0 siblings, 0 replies; 38+ messages in thread
From: Shuah Khan @ 2012-07-05 16:42 UTC (permalink / raw)
  To: Bryan Wu; +Cc: shuahkhan, linux-leds, rpurdie, linux-kernel

On Wed, 2012-07-04 at 13:10 +0800, Bryan Wu wrote:
> Cc: Shuah Khan <shuahkhan@gmail.com>
> Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
> ---
>  drivers/leds/ledtrig-transient.c |    5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/leds/ledtrig-transient.c b/drivers/leds/ledtrig-transient.c
> index 398f104..8e30b0df 100644
> --- a/drivers/leds/ledtrig-transient.c
> +++ b/drivers/leds/ledtrig-transient.c
> @@ -161,7 +161,8 @@ static void transient_trig_activate(struct led_classdev *led_cdev)
>  	int rc;
>  	struct transient_trig_data *tdata;
>  
> -	tdata = kzalloc(sizeof(struct transient_trig_data), GFP_KERNEL);
> +	tdata = devm_kzalloc(led_cdev->dev,
> +		sizeof(struct transient_trig_data), GFP_KERNEL);
>  	if (!tdata) {
>  		dev_err(led_cdev->dev,
>  			"unable to allocate transient trigger\n");
> @@ -194,7 +195,6 @@ err_out_duration:
>  err_out:
>  	dev_err(led_cdev->dev, "unable to register transient trigger\n");
>  	led_cdev->trigger_data = NULL;
> -	kfree(tdata);
>  }
>  
>  static void transient_trig_deactivate(struct led_classdev *led_cdev)
> @@ -209,7 +209,6 @@ static void transient_trig_deactivate(struct led_classdev *led_cdev)
>  		device_remove_file(led_cdev->dev, &dev_attr_state);
>  		led_cdev->trigger_data = NULL;
>  		led_cdev->activated = false;
> -		kfree(transient_data);
>  	}
>  }
>  

Bryan,

I don't believe memory triggers allocate in their activate routine
should be converted to devm_kzalloc(). Based on my understanding, the
memory allocated using devm_kzalloc() us free'ed when driver is
detached. In the case of led triggers, driver stays registered while the
triggers it supports can be activated and deactivated many times. By
converting these allocations into devm_kzalloc()s could lead to memory
leaks. Please correct me if my understanding is incorrect.

If what I am saying makes sense, please take this as comment that is
appicable to all led triggers, not just this one.

Thanks,
-- Shuah





^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 22/25] leds: convert GPIO LED trigger driver to devm_kzalloc() and cleanup error exit path
  2012-07-04  5:10 ` [PATCH 22/25] leds: convert GPIO LED trigger driver to devm_kzalloc() and cleanup error exit path Bryan Wu
@ 2012-07-05 16:45   ` Shuah Khan
  0 siblings, 0 replies; 38+ messages in thread
From: Shuah Khan @ 2012-07-05 16:45 UTC (permalink / raw)
  To: Bryan Wu; +Cc: shuahkhan, linux-leds, rpurdie, linux-kernel

On Wed, 2012-07-04 at 13:10 +0800, Bryan Wu wrote:
> Cc: Felipe Balbi <me@felipebalbi.com>
> Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
> ---
>  drivers/leds/ledtrig-gpio.c |    8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/leds/ledtrig-gpio.c b/drivers/leds/ledtrig-gpio.c
> index ba215dc..39bd8e4 100644
> --- a/drivers/leds/ledtrig-gpio.c
> +++ b/drivers/leds/ledtrig-gpio.c
> @@ -181,13 +181,13 @@ static void gpio_trig_activate(struct led_classdev *led)
>  	struct gpio_trig_data *gpio_data;
>  	int ret;
>  
> -	gpio_data = kzalloc(sizeof(*gpio_data), GFP_KERNEL);
> +	gpio_data = devm_kzalloc(led->dev, sizeof(*gpio_data), GFP_KERNEL);
>  	if (!gpio_data)
>  		return;
>  
>  	ret = device_create_file(led->dev, &dev_attr_gpio);
>  	if (ret)
> -		goto err_gpio;
> +		return;
>  
>  	ret = device_create_file(led->dev, &dev_attr_inverted);
>  	if (ret)
> @@ -209,9 +209,6 @@ err_brightness:
>  
>  err_inverted:
>  	device_remove_file(led->dev, &dev_attr_gpio);
> -
> -err_gpio:
> -	kfree(gpio_data);
>  }
>  
>  static void gpio_trig_deactivate(struct led_classdev *led)
> @@ -225,7 +222,6 @@ static void gpio_trig_deactivate(struct led_classdev *led)
>  		flush_work(&gpio_data->work);
>  		if (gpio_data->gpio != 0)
>  			free_irq(gpio_to_irq(gpio_data->gpio), led);
> -		kfree(gpio_data);
>  		led->activated = false;
>  	}
>  }

Bryan,

I don't believe memory triggers allocate in their activate routine
should be converted to devm_kzalloc(). Based on my understanding, the
memory allocated using devm_kzalloc() us free'ed when driver is
detached. In the case of led triggers, driver stays registered while the
triggers it supports can be activated and deactivated many times. By
converting these allocations into devm_kzalloc()s could lead to memory
leaks. Please correct me if my understanding is incorrect.

If what I am saying makes sense, please take this as comment that is
applicable to all led triggers, not just this one.

Thanks,
-- Shuah




^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 23/25] leds: convert Backlight emulation LED trigger driver to devm_kzalloc() and cleanup error exit path
  2012-07-04  5:10 ` [PATCH 23/25] leds: convert Backlight emulation " Bryan Wu
@ 2012-07-05 16:46   ` Shuah Khan
  0 siblings, 0 replies; 38+ messages in thread
From: Shuah Khan @ 2012-07-05 16:46 UTC (permalink / raw)
  To: Bryan Wu; +Cc: shuahkhan, linux-leds, rpurdie, linux-kernel

On Wed, 2012-07-04 at 13:10 +0800, Bryan Wu wrote:
> Cc: Rodolfo Giometti <giometti@linux.it>
> Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
> ---
>  drivers/leds/ledtrig-backlight.c |   10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/leds/ledtrig-backlight.c b/drivers/leds/ledtrig-backlight.c
> index b941685..3fa20a9 100644
> --- a/drivers/leds/ledtrig-backlight.c
> +++ b/drivers/leds/ledtrig-backlight.c
> @@ -101,7 +101,8 @@ static void bl_trig_activate(struct led_classdev *led)
>  
>  	struct bl_trig_notifier *n;
>  
> -	n = kzalloc(sizeof(struct bl_trig_notifier), GFP_KERNEL);
> +	n = devm_kzalloc(led->dev, sizeof(struct bl_trig_notifier),
> +			GFP_KERNEL);
>  	led->trigger_data = n;
>  	if (!n) {
>  		dev_err(led->dev, "unable to allocate backlight trigger\n");
> @@ -110,7 +111,7 @@ static void bl_trig_activate(struct led_classdev *led)
>  
>  	ret = device_create_file(led->dev, &dev_attr_inverted);
>  	if (ret)
> -		goto err_invert;
> +		led->trigger_data = NULL;
>  
>  	n->led = led;
>  	n->brightness = led->brightness;
> @@ -123,10 +124,6 @@ static void bl_trig_activate(struct led_classdev *led)
>  	led->activated = true;
>  
>  	return;
> -
> -err_invert:
> -	led->trigger_data = NULL;
> -	kfree(n);
>  }
>  
>  static void bl_trig_deactivate(struct led_classdev *led)
> @@ -137,7 +134,6 @@ static void bl_trig_deactivate(struct led_classdev *led)
>  	if (led->activated) {
>  		device_remove_file(led->dev, &dev_attr_inverted);
>  		fb_unregister_client(&n->notifier);
> -		kfree(n);
>  		led->activated = false;
>  	}
>  }

Bryan,

I don't believe memory triggers allocate in their activate routine
should be converted to devm_kzalloc(). Based on my understanding, the
memory allocated using devm_kzalloc() us free'ed when driver is
detached. In the case of led triggers, driver stays registered while the
triggers it supports can be activated and deactivated many times. By
converting these allocations into devm_kzalloc()s could lead to memory
leaks. Please correct me if my understanding is incorrect.

If what I am saying makes sense, please take this as comment that is
applicable to all led triggers, not just this one.

Thanks,
-- Shuah


^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 24/25] leds: convert Heartbeat LED trigger driver to devm_kzalloc()
  2012-07-04  5:10 ` [PATCH 24/25] leds: convert Heartbeat LED trigger driver to devm_kzalloc() Bryan Wu
@ 2012-07-05 16:46   ` Shuah Khan
  0 siblings, 0 replies; 38+ messages in thread
From: Shuah Khan @ 2012-07-05 16:46 UTC (permalink / raw)
  To: Bryan Wu; +Cc: shuahkhan, linux-leds, rpurdie, linux-kernel

On Wed, 2012-07-04 at 13:10 +0800, Bryan Wu wrote:
> Cc: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
> Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
> ---
>  drivers/leds/ledtrig-heartbeat.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/leds/ledtrig-heartbeat.c b/drivers/leds/ledtrig-heartbeat.c
> index d3039f2..5caa01b 100644
> --- a/drivers/leds/ledtrig-heartbeat.c
> +++ b/drivers/leds/ledtrig-heartbeat.c
> @@ -75,7 +75,8 @@ static void heartbeat_trig_activate(struct led_classdev *led_cdev)
>  {
>  	struct heartbeat_trig_data *heartbeat_data;
>  
> -	heartbeat_data = kzalloc(sizeof(*heartbeat_data), GFP_KERNEL);
> +	heartbeat_data = devm_kzalloc(led_cdev->dev, sizeof(*heartbeat_data),
> +				GFP_KERNEL);
>  	if (!heartbeat_data)
>  		return;
>  
> @@ -93,7 +94,6 @@ static void heartbeat_trig_deactivate(struct led_classdev *led_cdev)
>  
>  	if (led_cdev->activated) {
>  		del_timer_sync(&heartbeat_data->timer);
> -		kfree(heartbeat_data);
>  		led_cdev->activated = false;
>  	}
>  }
Bryan,
Bryan,

I don't believe memory triggers allocate in their activate routine
should be converted to devm_kzalloc(). Based on my understanding, the
memory allocated using devm_kzalloc() us free'ed when driver is
detached. In the case of led triggers, driver stays registered while the
triggers it supports can be activated and deactivated many times. By
converting these allocations into devm_kzalloc()s could lead to memory
leaks. Please correct me if my understanding is incorrect.

If what I am saying makes sense, please take this as comment that is
applicable to all led triggers, not just this one.

Thanks,
-- Shuah


^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 25/25] leds: convert One-shot LED trigger driver to devm_kzalloc() and cleanup error exit path
  2012-07-04  5:10 ` [PATCH 25/25] leds: convert One-shot LED trigger driver to devm_kzalloc() and cleanup error exit path Bryan Wu
@ 2012-07-05 16:47   ` Shuah Khan
  2012-07-05 19:48     ` Fabio Baltieri
  0 siblings, 1 reply; 38+ messages in thread
From: Shuah Khan @ 2012-07-05 16:47 UTC (permalink / raw)
  To: Bryan Wu; +Cc: shuahkhan, linux-leds, rpurdie, linux-kernel

On Wed, 2012-07-04 at 13:10 +0800, Bryan Wu wrote:
> Cc: Fabio Baltieri <fabio.baltieri@gmail.com>
> Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
> ---
>  drivers/leds/ledtrig-oneshot.c |    8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/leds/ledtrig-oneshot.c b/drivers/leds/ledtrig-oneshot.c
> index 2c029aa..6395a38 100644
> --- a/drivers/leds/ledtrig-oneshot.c
> +++ b/drivers/leds/ledtrig-oneshot.c
> @@ -127,7 +127,8 @@ static void oneshot_trig_activate(struct led_classdev *led_cdev)
>  	struct oneshot_trig_data *oneshot_data;
>  	int rc;
>  
> -	oneshot_data = kzalloc(sizeof(*oneshot_data), GFP_KERNEL);
> +	oneshot_data = devm_kzalloc(led_cdev->dev, sizeof(*oneshot_data),
> +				GFP_KERNEL);
>  	if (!oneshot_data)
>  		return;
>  
> @@ -135,7 +136,7 @@ static void oneshot_trig_activate(struct led_classdev *led_cdev)
>  
>  	rc = device_create_file(led_cdev->dev, &dev_attr_delay_on);
>  	if (rc)
> -		goto err_out_trig_data;
> +		return;
>  	rc = device_create_file(led_cdev->dev, &dev_attr_delay_off);
>  	if (rc)
>  		goto err_out_delayon;
> @@ -159,8 +160,6 @@ err_out_delayoff:
>  	device_remove_file(led_cdev->dev, &dev_attr_delay_off);
>  err_out_delayon:
>  	device_remove_file(led_cdev->dev, &dev_attr_delay_on);
> -err_out_trig_data:
> -	kfree(led_cdev->trigger_data);
>  }
>  
>  static void oneshot_trig_deactivate(struct led_classdev *led_cdev)
> @@ -172,7 +171,6 @@ static void oneshot_trig_deactivate(struct led_classdev *led_cdev)
>  		device_remove_file(led_cdev->dev, &dev_attr_delay_off);
>  		device_remove_file(led_cdev->dev, &dev_attr_invert);
>  		device_remove_file(led_cdev->dev, &dev_attr_shot);
> -		kfree(oneshot_data);
>  		led_cdev->activated = false;
>  	}
>  
Bryan,

I don't believe memory triggers allocate in their activate routine
should be converted to devm_kzalloc(). Based on my understanding, the
memory allocated using devm_kzalloc() us free'ed when driver is
detached. In the case of led triggers, driver stays registered while the
triggers it supports can be activated and deactivated many times. By
converting these allocations into devm_kzalloc()s could lead to memory
leaks. Please correct me if my understanding is incorrect.

If what I am saying makes sense, please take this as comment that is
applicable to all led triggers, not just this one.

Thanks,
-- Shuah


^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 25/25] leds: convert One-shot LED trigger driver to devm_kzalloc() and cleanup error exit path
  2012-07-05 16:47   ` Shuah Khan
@ 2012-07-05 19:48     ` Fabio Baltieri
  2012-07-05 20:35       ` Shuah Khan
  0 siblings, 1 reply; 38+ messages in thread
From: Fabio Baltieri @ 2012-07-05 19:48 UTC (permalink / raw)
  To: Shuah Khan; +Cc: Bryan Wu, linux-leds, rpurdie, linux-kernel

On Thu, Jul 05, 2012 at 10:47:19AM -0600, Shuah Khan wrote:
> On Wed, 2012-07-04 at 13:10 +0800, Bryan Wu wrote:
> > Cc: Fabio Baltieri <fabio.baltieri@gmail.com>
> > Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
> > ---
> >  drivers/leds/ledtrig-oneshot.c |    8 +++-----
> >  1 file changed, 3 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/leds/ledtrig-oneshot.c b/drivers/leds/ledtrig-oneshot.c
> > index 2c029aa..6395a38 100644
> > --- a/drivers/leds/ledtrig-oneshot.c
> > +++ b/drivers/leds/ledtrig-oneshot.c
> > @@ -127,7 +127,8 @@ static void oneshot_trig_activate(struct led_classdev *led_cdev)
> >  	struct oneshot_trig_data *oneshot_data;
> >  	int rc;
> >  
> > -	oneshot_data = kzalloc(sizeof(*oneshot_data), GFP_KERNEL);
> > +	oneshot_data = devm_kzalloc(led_cdev->dev, sizeof(*oneshot_data),
> > +				GFP_KERNEL);
> >  	if (!oneshot_data)
> >  		return;
> >  
> > @@ -135,7 +136,7 @@ static void oneshot_trig_activate(struct led_classdev *led_cdev)
> >  
> >  	rc = device_create_file(led_cdev->dev, &dev_attr_delay_on);
> >  	if (rc)
> > -		goto err_out_trig_data;
> > +		return;
> >  	rc = device_create_file(led_cdev->dev, &dev_attr_delay_off);
> >  	if (rc)
> >  		goto err_out_delayon;
> > @@ -159,8 +160,6 @@ err_out_delayoff:
> >  	device_remove_file(led_cdev->dev, &dev_attr_delay_off);
> >  err_out_delayon:
> >  	device_remove_file(led_cdev->dev, &dev_attr_delay_on);
> > -err_out_trig_data:
> > -	kfree(led_cdev->trigger_data);
> >  }
> >  
> >  static void oneshot_trig_deactivate(struct led_classdev *led_cdev)
> > @@ -172,7 +171,6 @@ static void oneshot_trig_deactivate(struct led_classdev *led_cdev)
> >  		device_remove_file(led_cdev->dev, &dev_attr_delay_off);
> >  		device_remove_file(led_cdev->dev, &dev_attr_invert);
> >  		device_remove_file(led_cdev->dev, &dev_attr_shot);
> > -		kfree(oneshot_data);
> >  		led_cdev->activated = false;
> >  	}
> >  
> Bryan,
> 
> I don't believe memory triggers allocate in their activate routine
> should be converted to devm_kzalloc(). Based on my understanding, the
> memory allocated using devm_kzalloc() us free'ed when driver is
> detached. In the case of led triggers, driver stays registered while the
> triggers it supports can be activated and deactivated many times. By
> converting these allocations into devm_kzalloc()s could lead to memory
> leaks. Please correct me if my understanding is incorrect.

Shuah,

I'm as the same opinion - as triggers are not really "driver", in the
sense that they are not using the driver structures, using devm_
functions doesn't seems to be really appropriate.

Specifically:

> > +	oneshot_data = devm_kzalloc(led_cdev->dev, sizeof(*oneshot_data),
> > +				GFP_KERNEL);

this one is registering the data on the relative LED's resources, so
that they are not freed until you unload the LED's driver itself.
I also think that this leads to memory leak if you keep activating
triggers, as the deactivate function is not actually freeing the
resources, so in that case the correct procedure should be the usual
kalloc/kfree.

Is this consistent with what your conclusions, Shuah?

Fabio

> If what I am saying makes sense, please take this as comment that is
> applicable to all led triggers, not just this one.
> 
> Thanks,
> -- Shuah
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-leds" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 25/25] leds: convert One-shot LED trigger driver to devm_kzalloc() and cleanup error exit path
  2012-07-05 19:48     ` Fabio Baltieri
@ 2012-07-05 20:35       ` Shuah Khan
  2012-07-06  4:02         ` Bryan Wu
  0 siblings, 1 reply; 38+ messages in thread
From: Shuah Khan @ 2012-07-05 20:35 UTC (permalink / raw)
  To: Fabio Baltieri; +Cc: shuahkhan, Bryan Wu, linux-leds, rpurdie, linux-kernel

On Thu, 2012-07-05 at 21:48 +0200, Fabio Baltieri wrote:

> > >  
> > Bryan,
> > 
> > I don't believe memory triggers allocate in their activate routine
> > should be converted to devm_kzalloc(). Based on my understanding, the
> > memory allocated using devm_kzalloc() us free'ed when driver is
> > detached. In the case of led triggers, driver stays registered while the
> > triggers it supports can be activated and deactivated many times. By
> > converting these allocations into devm_kzalloc()s could lead to memory
> > leaks. Please correct me if my understanding is incorrect.
> 
> Shuah,
> 
> I'm as the same opinion - as triggers are not really "driver", in the
> sense that they are not using the driver structures, using devm_
> functions doesn't seems to be really appropriate.
> 

Correct. Each driver could support multiple triggers and triggers are
not at the same level as the device.

> Specifically:
> 
> > > +	oneshot_data = devm_kzalloc(led_cdev->dev, sizeof(*oneshot_data),
> > > +				GFP_KERNEL);
> 
> this one is registering the data on the relative LED's resources, so
> that they are not freed until you unload the LED's driver itself.
> I also think that this leads to memory leak if you keep activating
> triggers, as the deactivate function is not actually freeing the
> resources, so in that case the correct procedure should be the usual
> kalloc/kfree.
> 
> Is this consistent with what your conclusions, Shuah?

Correct. Using devm_ in triggers is not the correct and there is no need
to change from using kalloc()/kfree().

-- Shuah
> 
> Fabio
> 
> > If what I am saying makes sense, please take this as comment that is
> > applicable to all led triggers, not just this one.
> > 
> > Thanks,
> > -- Shuah
> > 
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-leds" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 



^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 25/25] leds: convert One-shot LED trigger driver to devm_kzalloc() and cleanup error exit path
  2012-07-05 20:35       ` Shuah Khan
@ 2012-07-06  4:02         ` Bryan Wu
  0 siblings, 0 replies; 38+ messages in thread
From: Bryan Wu @ 2012-07-06  4:02 UTC (permalink / raw)
  To: shuahkhan; +Cc: Fabio Baltieri, linux-leds, rpurdie, linux-kernel

On Fri, Jul 6, 2012 at 4:35 AM, Shuah Khan <shuahkhan@gmail.com> wrote:
> On Thu, 2012-07-05 at 21:48 +0200, Fabio Baltieri wrote:
>
>> > >
>> > Bryan,
>> >
>> > I don't believe memory triggers allocate in their activate routine
>> > should be converted to devm_kzalloc(). Based on my understanding, the
>> > memory allocated using devm_kzalloc() us free'ed when driver is
>> > detached. In the case of led triggers, driver stays registered while the
>> > triggers it supports can be activated and deactivated many times. By
>> > converting these allocations into devm_kzalloc()s could lead to memory
>> > leaks. Please correct me if my understanding is incorrect.
>>
>> Shuah,
>>
>> I'm as the same opinion - as triggers are not really "driver", in the
>> sense that they are not using the driver structures, using devm_
>> functions doesn't seems to be really appropriate.
>>
>
> Correct. Each driver could support multiple triggers and triggers are
> not at the same level as the device.
>
>> Specifically:
>>
>> > > + oneshot_data = devm_kzalloc(led_cdev->dev, sizeof(*oneshot_data),
>> > > +                         GFP_KERNEL);
>>
>> this one is registering the data on the relative LED's resources, so
>> that they are not freed until you unload the LED's driver itself.
>> I also think that this leads to memory leak if you keep activating
>> triggers, as the deactivate function is not actually freeing the
>> resources, so in that case the correct procedure should be the usual
>> kalloc/kfree.
>>
>> Is this consistent with what your conclusions, Shuah?
>
> Correct. Using devm_ in triggers is not the correct and there is no need
> to change from using kalloc()/kfree().
>

Exactly, you guys are right about this. Thanks for correcting me.

Trigger drivers kzalloc() in activate() which will be called multiple
times as trigger drivers normally sit in memory and don't follow
normal driver probe/remove or device register/unregister.

I will drop these patches.

-Bryan

>>
>> > If what I am saying makes sense, please take this as comment that is
>> > applicable to all led triggers, not just this one.
>> >
>> > Thanks,
>> > -- Shuah
>> >
>> > --
>> > To unsubscribe from this list: send the line "unsubscribe linux-leds" in
>> > the body of a message to majordomo@vger.kernel.org
>> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at  http://www.tux.org/lkml/
>>
>

^ permalink raw reply	[flat|nested] 38+ messages in thread

end of thread, other threads:[~2012-07-06  4:02 UTC | newest]

Thread overview: 38+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-04  5:09 [PATCH 00/25] leds: convert all kzalloc() to devm_kzalloc() Bryan Wu
2012-07-04  5:09 ` [PATCH 01/25] leds: convert Big Networks LED driver " Bryan Wu
2012-07-04  5:09 ` [PATCH 02/25] leds: convert HTC ASIC3 LED driver to devm_kzalloc() and cleanup error exit path Bryan Wu
2012-07-04  5:09 ` [PATCH 03/25] leds: convert Atmel PWM LED driver to devm_kzalloc() Bryan Wu
2012-07-04  5:09 ` [PATCH 04/25] leds: convert LP3944 " Bryan Wu
2012-07-04  7:34   ` Bryan Wu
2012-07-04  5:09 ` [PATCH 05/25] leds: convert DA9030/DA9034 LED driver to devm_kzalloc() and cleanup error exit path Bryan Wu
2012-07-04  5:09 ` [PATCH 06/25] leds: convert LP5521 " Bryan Wu
2012-07-04  7:35   ` Bryan Wu
2012-07-04  5:09 ` [PATCH 07/25] leds: convert BD2802 RGB " Bryan Wu
2012-07-04  5:10 ` [PATCH 08/25] leds: convert PCA9633 LED driver to devm_kzalloc() Bryan Wu
2012-07-04  5:10 ` [PATCH 09/25] leds: convert LP5523 LED driver to devm_kzalloc() and cleanup error exit path Bryan Wu
2012-07-04  5:10 ` [PATCH 10/25] leds: convert Renesas TPU " Bryan Wu
2012-07-04  5:10 ` [PATCH 11/25] leds: convert LT3593 LED driver to devm_kzalloc() Bryan Wu
2012-07-04  5:10 ` [PATCH 12/25] leds: convert PCA9532 " Bryan Wu
2012-07-04  5:10 ` [PATCH 13/25] leds: convert Sun Fire LED driver to devm_kzalloc() and cleanup error exit path Bryan Wu
2012-07-04  5:10 ` [PATCH 14/25] leds: convert PCA955x " Bryan Wu
2012-07-04  5:10 ` [PATCH 15/25] leds: convert ADP5520 " Bryan Wu
2012-07-04  7:40   ` Bryan Wu
2012-07-04  5:10 ` [PATCH 16/25] leds: convert Freescale MC13783 " Bryan Wu
2012-07-04  5:10 ` [PATCH 17/25] leds: convert TCA6507 LED driver to devm_kzalloc() Bryan Wu
2012-07-04  5:10 ` [PATCH 18/25] leds: convert LM3530 LED driver to devm_kzalloc() and cleanup error exit path Bryan Wu
2012-07-05  0:01   ` Linus Walleij
2012-07-04  5:10 ` [PATCH 19/25] leds: convert DAC124S085 LED driver to devm_kzalloc() Bryan Wu
2012-07-04  5:10 ` [PATCH 20/25] leds: convert Network Space v2 LED driver to devm_kzalloc() and cleanup error exit path Bryan Wu
2012-07-04  5:10 ` [PATCH 21/25] leds: convert transient LED trigger driver to devm_kzalloc() Bryan Wu
2012-07-05 16:42   ` Shuah Khan
2012-07-04  5:10 ` [PATCH 22/25] leds: convert GPIO LED trigger driver to devm_kzalloc() and cleanup error exit path Bryan Wu
2012-07-05 16:45   ` Shuah Khan
2012-07-04  5:10 ` [PATCH 23/25] leds: convert Backlight emulation " Bryan Wu
2012-07-05 16:46   ` Shuah Khan
2012-07-04  5:10 ` [PATCH 24/25] leds: convert Heartbeat LED trigger driver to devm_kzalloc() Bryan Wu
2012-07-05 16:46   ` Shuah Khan
2012-07-04  5:10 ` [PATCH 25/25] leds: convert One-shot LED trigger driver to devm_kzalloc() and cleanup error exit path Bryan Wu
2012-07-05 16:47   ` Shuah Khan
2012-07-05 19:48     ` Fabio Baltieri
2012-07-05 20:35       ` Shuah Khan
2012-07-06  4:02         ` Bryan Wu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.