Re: [PATCH 24/25] leds: convert Heartbeat LED trigger driver todevm_kzalloc()

From: Shuah Khan
Date: Thu Jul 05 2012 - 12:46:51 EST


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

--
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/