Skip to contentSkip to conversation

leds: lm3556: Don't call kfree for the memory allocated by devm_kzalloc

PATCH New Axel Lin 1 participant 1 message Apr 22, 2012 LED

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 leds: lm3556: Don't call kfree for the memory allocated by devm_kzalloc

The devm_* functions eliminate the need for manual resource releasing and simplify error handling. Resources allocated by devm_* are freed automatically on driver detach.

Thus adding kfree calls here will introduce double free bug.

---
 drivers/leds/leds-lm3556.c |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)
drivers/leds/leds-lm3556.c +2 -5
index cc0abbc..15a5acd 100644
@@ -360,9 +360,8 @@ static int lm3556_probe(struct i2c_client *client,
 		return -ENODATA;
 	}
 
-	chip =
-	    devm_kzalloc(&client->dev, sizeof(struct lm3556_chip_data),
-			 GFP_KERNEL);
+	chip = devm_kzalloc(&client->dev, sizeof(struct lm3556_chip_data),
+			    GFP_KERNEL);
 	if (!chip)
 		return -ENOMEM;
 
@@ -416,7 +415,6 @@ err_create_torch_file:
 err_create_flash_file:
 err_chip_init:
 	i2c_set_clientdata(client, NULL);
-	kfree(chip);
 	return err;
 }
 
@@ -430,7 +428,6 @@ static int lm3556_remove(struct i2c_client *client)
 	led_classdev_unregister(&chip->cdev_flash);
 	lm3556_write_reg(client, REG_ENABLE, 0);
 
-	kfree(chip);
 	return 0;
 }
 
Signature · 1 line
1.7.5.4