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.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Jan-Simon Möller <jansimon.moeller@gmx.de>
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
This commit is contained in:
Dan Carpenter 2012-07-26 15:59:51 +08:00 committed by Bryan Wu
parent eb80411b54
commit 4d8729a139

View File

@ -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 */ /* 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_led *led = cdev_to_blmled(led_cdev);
struct blinkm_data *data = i2c_get_clientdata(led->i2c_client); struct blinkm_data *data = i2c_get_clientdata(led->i2c_client);
struct blinkm_work *bl_work = kzalloc(sizeof(struct blinkm_work), struct blinkm_work *bl_work;
GFP_ATOMIC);
switch (color) { switch (color) {
case RED: case RED:
@ -511,6 +510,10 @@ static int blinkm_led_common_set(struct led_classdev *led_cdev,
return -EINVAL; return -EINVAL;
} }
bl_work = kzalloc(sizeof(*bl_work), GFP_ATOMIC);
if (!bl_work)
return -ENOMEM;
atomic_inc(&led->active); atomic_inc(&led->active);
dev_dbg(&led->i2c_client->dev, dev_dbg(&led->i2c_client->dev,
"#TO_SCHED# next_red = %d, next_green = %d," "#TO_SCHED# next_red = %d, next_green = %d,"