Skip to contentSkip to conversation

LEDS: memory leak in blinkm_led_common_set()

PATCH Applied Dan Carpenter 3 participants 3 messages Jul 26, 2012 – Jul 27, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 LEDS: memory leak in blinkm_led_common_set()

This can return without freeing the bl_work struct. Also there was no check for allocation failure.

drivers/leds/leds-blinkm.c +5 -2
index 5a9df43..ae6ad63 100644
@@ -468,8 +468,7 @@ static int blinkm_led_common_set(struct led_classdev *led_cdev,
 	/* led_brightness is 0, 127 or 255 - we just use it here as-is */
 	struct blinkm_led *led = cdev_to_blmled(led_cdev);
 	struct blinkm_data *data = i2c_get_clientdata(led->i2c_client);
-	struct blinkm_work *bl_work = kzalloc(sizeof(struct blinkm_work),
-					      GFP_ATOMIC);
+	struct blinkm_work *bl_work;
 
 	switch (color) {
 	case RED:
@@ -511,6 +510,10 @@ static int blinkm_led_common_set(struct led_classdev *led_cdev,
 		return -EINVAL;
 	}
 
+	bl_work = kzalloc(sizeof(*bl_work), GFP_ATOMIC);
+	if (!bl_work)
+		return -ENOMEM;
+
 	atomic_inc(&led->active);
 	dev_dbg(&led->i2c_client->dev,
 			"#TO_SCHED# next_red = %d, next_green = %d,"
#1 lore raw

Ack'ed!

Thanks, Dan!

Regards,
Jan-Simon
Am Donnerstag, 26. Juli 2012, 09:59:51 schrieb Dan Carpenter:

Quoted 30 lines

This can return without freeing the bl_work struct. Also there was no check for allocation failure.

drivers/leds/leds-blinkm.c +5 -2
index 5a9df43..ae6ad63 100644
@@ -468,8 +468,7 @@ static int blinkm_led_common_set(struct led_classdev
 *led_cdev, /* led_brightness is 0, 127 or 255 - we just use it here as-is
 */ struct blinkm_led *led = cdev_to_blmled(led_cdev);
 	struct blinkm_data *data = i2c_get_clientdata(led->i2c_client);
-	struct blinkm_work *bl_work = kzalloc(sizeof(struct blinkm_work),
-					      GFP_ATOMIC);
+	struct blinkm_work *bl_work;
 
 	switch (color) {
 	case RED:
@@ -511,6 +510,10 @@ static int blinkm_led_common_set(struct led_classdev
 *led_cdev, return -EINVAL;
 	}
 
+	bl_work = kzalloc(sizeof(*bl_work), GFP_ATOMIC);
+	if (!bl_work)
+		return -ENOMEM;
+
 	atomic_inc(&led->active);
 	dev_dbg(&led->i2c_client->dev,
 			"#TO_SCHED# next_red = %d, next_green = %d,"
Applied
#2 lore raw
In reply to Dan Carpenter

Applied to my for-next. Thanks Dan and Jan-Simon,

-Bryan

Quoted 42 lines · Jan-Simon Möller

Ack'ed!

Thanks, Dan!

Regards,
Jan-Simon
Am Donnerstag, 26. Juli 2012, 09:59:51 schrieb Dan Carpenter:

Quoted 20 lines

This can return without freeing the bl_work struct. Also there was no check for allocation failure.

drivers/leds/leds-blinkm.c +1 -2
index 5a9df43..ae6ad63 100644
@@ -468,8 +468,7 @@ static int blinkm_led_common_set(struct led_classdev
 *led_cdev, /* led_brightness is 0, 127 or 255 - we just use it here as-is
 */ struct blinkm_led *led = cdev_to_blmled(led_cdev);
      struct blinkm_data *data = i2c_get_clientdata(led->i2c_client);
-     struct blinkm_work *bl_work = kzalloc(sizeof(struct blinkm_work),
-                                           GFP_ATOMIC);
+     struct blinkm_work *bl_work;
 
      switch (color) {
      case RED:

drivers/leds/leds-blinkm.c static int blinkm_led_common_set(struct led_classdev · line 519

Quoted 10 lines
drivers/leds/leds-blinkm.c +4 -0
@@ -511,6 +510,10 @@ static int blinkm_led_common_set(struct led_classdev
 *led_cdev, return -EINVAL;
      }
 
+     bl_work = kzalloc(sizeof(*bl_work), GFP_ATOMIC);
+     if (!bl_work)
+             return -ENOMEM;
+
      atomic_inc(&led->active);
      dev_dbg(&led->i2c_client->dev,
                      "#TO_SCHED# next_red = %d, next_green = %d,"

--
To unsubscribe from this list: send the line "unsubscribe linux-leds" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 8 lines
Bryan Wu <[email protected]>
Kernel Developer    +86.186-168-78255 Mobile
Canonical Ltd.      www.canonical.com
Ubuntu - Linux for human beings | www.ubuntu.com
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html