[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1341506814.2605.10.camel@lorien2>
Date: Thu, 05 Jul 2012 10:46:54 -0600
From: Shuah Khan <shuahkhan@...il.com>
To: Bryan Wu <bryan.wu@...onical.com>
Cc: shuahkhan@...il.com, linux-leds@...r.kernel.org, rpurdie@...ys.net,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH 24/25] leds: convert Heartbeat LED trigger driver to
devm_kzalloc()
On Wed, 2012-07-04 at 13:10 +0800, Bryan Wu wrote:
> Cc: Atsushi Nemoto <anemo@....ocn.ne.jp>
> Signed-off-by: Bryan Wu <bryan.wu@...onical.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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists