public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] leds: ledtrig-timer trigger_data allocation fix
@ 2012-04-17 23:05 Shuah Khan
  2012-04-17 23:12 ` Andrew Morton
  0 siblings, 1 reply; 7+ messages in thread
From: Shuah Khan @ 2012-04-17 23:05 UTC (permalink / raw)
  To: Andrew Morton; +Cc: shuahkhan, LKML, Richard Purdie

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.

>From 9f7a6fc40ce7322145b6adea8771c8d547c151ec Mon Sep 17 00:00:00 2001
From: Shuah Khan <shuahkhan@gmail.com>
Date: Tue, 17 Apr 2012 16:04:56 -0600
Subject: [PATCH] leds: ledtrig-timer trigger_data allocation fix


Signed-off-by: Shuah Khan <shuahkhan@gmail.com>
---
 drivers/leds/ledtrig-timer.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/drivers/leds/ledtrig-timer.c b/drivers/leds/ledtrig-timer.c
index b32d5ea..64b6915 100644
--- a/drivers/leds/ledtrig-timer.c
+++ b/drivers/leds/ledtrig-timer.c
@@ -16,6 +16,7 @@
 #include <linux/init.h>
 #include <linux/device.h>
 #include <linux/ctype.h>
+#include <linux/slab.h>
 #include <linux/leds.h>
 #include "leds.h"
 
@@ -88,10 +89,14 @@ static void timer_trig_activate(struct led_classdev *led_cdev)
 	led_blink_set(led_cdev, &led_cdev->blink_delay_on,
 		      &led_cdev->blink_delay_off);
 
-	led_cdev->trigger_data = (void *)1;
+	led_cdev->trigger_data = kzalloc(sizeof(int), GFP_KERNEL);
+	if (!led_cdev->trigger_data)
+		goto err_out_delayoff;
 
 	return;
 
+err_out_delayoff:
+	device_remove_file(led_cdev->dev, &dev_attr_delay_off);
 err_out_delayon:
 	device_remove_file(led_cdev->dev, &dev_attr_delay_on);
 }
@@ -101,6 +106,7 @@ static void timer_trig_deactivate(struct led_classdev *led_cdev)
 	if (led_cdev->trigger_data) {
 		device_remove_file(led_cdev->dev, &dev_attr_delay_on);
 		device_remove_file(led_cdev->dev, &dev_attr_delay_off);
+		kfree(led_cdev->trigger_data);
 	}
 
 	/* Stop blinking */
-- 
1.7.5.4






^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-04-20 21:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-17 23:05 [PATCH] leds: ledtrig-timer trigger_data allocation fix Shuah Khan
2012-04-17 23:12 ` Andrew Morton
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox