lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Thu, 05 Jul 2012 10:46:20 -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 23/25] leds: convert Backlight emulation LED trigger
 driver to devm_kzalloc() and cleanup error exit path

On Wed, 2012-07-04 at 13:10 +0800, Bryan Wu wrote:
> Cc: Rodolfo Giometti <giometti@...ux.it>
> Signed-off-by: Bryan Wu <bryan.wu@...onical.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

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

Powered by Openwall GNU/*/Linux Powered by OpenVZ