public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: shuahkhan@gmail.com
Cc: LKML <linux-kernel@vger.kernel.org>,
	Richard Purdie <richard.purdie@linuxfoundation.org>
Subject: Re: [PATCH] leds: ledtrig-timer trigger_data allocation fix
Date: Tue, 17 Apr 2012 16:12:39 -0700	[thread overview]
Message-ID: <20120417161239.57c41966.akpm@linux-foundation.org> (raw)
In-Reply-To: <1334703911.2655.9.camel@lorien2>

On Tue, 17 Apr 2012 17:05:11 -0600
Shuah Khan <shuahkhan@gmail.com> wrote:

> ledtrig-timer doesn't allocate memory for trigger_data and assigns
> (void *)1 to save state. Fixed it to allocate int instead. Please 
> note that non-null trigger_data is used to key off of to do proper
> cleanup in deactivation routine and not used during the life of the
> trigger itself.

In that case, overloading the value of ->trigger_data in this fashion
is inappropriate and a new field should be added to led_classdev for
this purpose.

> -	led_cdev->trigger_data = (void *)1;
> +	led_cdev->trigger_data = kzalloc(sizeof(int), GFP_KERNEL);

But that's better than what we have now.

It does require a comment though:

--- a/drivers/leds/ledtrig-timer.c~leds-ledtrig-timer-trigger_data-allocation-fix-fix
+++ a/drivers/leds/ledtrig-timer.c
@@ -89,6 +89,11 @@ static void timer_trig_activate(struct l
 	led_blink_set(led_cdev, &led_cdev->blink_delay_on,
 		      &led_cdev->blink_delay_off);
 
+	/*
+	 * Place a dummy allocation at ->trigger_data so that
+	 * timer_trig_deactivate() cleans up correctly.  This data is never
+	 * actually used.
+	 */
 	led_cdev->trigger_data = kzalloc(sizeof(int), GFP_KERNEL);
 	if (!led_cdev->trigger_data)
 		goto err_out_delayoff;
_


  reply	other threads:[~2012-04-17 23:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-17 23:05 [PATCH] leds: ledtrig-timer trigger_data allocation fix Shuah Khan
2012-04-17 23:12 ` Andrew Morton [this message]
2012-04-20  3:48   ` [PATCH] leds: add new field to led_classdev struct to save activation state Shuah Khan
2012-04-20 20:14     ` [PATCH ] leds: change existing triggers to use activated flag Shuah Khan
2012-04-20 20:17     ` [PATCH] leds: change ledtrig-timer " Shuah Khan
2012-04-20 21:03       ` Andrew Morton
2012-04-20 21:16         ` Shuah Khan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120417161239.57c41966.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=richard.purdie@linuxfoundation.org \
    --cc=shuahkhan@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox