lkml.org 
[lkml]   [2012]   [Jul]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH 21/25] leds: convert transient LED trigger driver to devm_kzalloc()
From
Date
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






\
 
 \ /
  Last update: 2012-07-05 19:21    [W:0.209 / U:4.408 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site