Re: [PATCH 21/25] leds: convert transient LED trigger driver todevm_kzalloc()

From: Shuah Khan
Date: Thu Jul 05 2012 - 12:42:48 EST


On Wed, 2012-07-04 at 13:10 +0800, Bryan Wu wrote:
> Cc: Shuah Khan <shuahkhan@xxxxxxxxx>
> Signed-off-by: Bryan Wu <bryan.wu@xxxxxxxxxxxxx>
> ---
> 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




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