Skip to contentSkip to conversation

leds: lp3952: Store leds[LP3952_LED_ALL] in struct lp3952_led_array

PATCH In review Axel Lin 2 participants 3 messages Jul 17, 2016 – Jul 18, 2016 1 message not in the archive LED

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 leds: lp3952: Store leds[LP3952_LED_ALL] in struct lp3952_led_array

The LP3952_LED_ALL is known at compile time, so we can just store leds[LP3952_LED_ALL] in struct lp3952_led_array rather than calling devm_kcalloc() to allocate the memory.

---
 drivers/leds/leds-lp3952.c  | 9 ---------
 include/linux/leds-lp3952.h | 2 +-
 2 files changed, 1 insertion(+), 10 deletions(-)
drivers/leds/leds-lp3952.c +0 -9
index f6157c0..a73c8ff 100644
@@ -215,21 +215,12 @@ static int lp3952_probe(struct i2c_client *client,
 			const struct i2c_device_id *id)
 {
 	int status;
-	struct lp3952_ctrl_hdl *leds;
 	struct lp3952_led_array *priv;
 
 	priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)
 		return -ENOMEM;
 
-	leds = devm_kcalloc(&client->dev, LP3952_LED_ALL, sizeof(*leds),
-			    GFP_KERNEL);
-	if (!leds) {
-		devm_kfree(&client->dev, priv);
-		return -ENOMEM;
-	}
-
-	priv->leds = leds;
 	priv->client = client;
 
 	priv->enable_gpio = devm_gpiod_get(&client->dev, "nrst",
include/linux/leds-lp3952.h +1 -1
index edd5ed6..49b37ed 100644
@@ -119,7 +119,7 @@ struct lp3952_led_array {
 	struct regmap *regmap;
 	struct i2c_client *client;
 	struct gpio_desc *enable_gpio;
-	struct lp3952_ctrl_hdl *leds;
+	struct lp3952_ctrl_hdl leds[LP3952_LED_ALL];
 };
 
 #endif /* LEDS_LP3952_H_ */
Signature · 1 line
2.5.0
#1 lore raw

Hi Axel,

Thanks for catching this. I missed also redundant devm_kfree here. Would it be OK for you if I merged your cleanup with the original patch and added your Reviewed-by to the commit message instead? This driver hasn't been pushed to the mainline yet, so it would be nice not to introduce its original version with some shortcomings that need to be immediately fixed.

Best regards,
Jacek Anaszewski

Quoted 50 lines · Axel Lin

The LP3952_LED_ALL is known at compile time, so we can just store leds[LP3952_LED_ALL] in struct lp3952_led_array rather than calling devm_kcalloc() to allocate the memory.

---
  drivers/leds/leds-lp3952.c  | 9 ---------
  include/linux/leds-lp3952.h | 2 +-
  2 files changed, 1 insertion(+), 10 deletions(-)
drivers/leds/leds-lp3952.c +0 -9
index f6157c0..a73c8ff 100644
@@ -215,21 +215,12 @@ static int lp3952_probe(struct i2c_client *client,
  			const struct i2c_device_id *id)
  {
  	int status;
-	struct lp3952_ctrl_hdl *leds;
  	struct lp3952_led_array *priv;
 
  	priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL);
  	if (!priv)
  		return -ENOMEM;
 
-	leds = devm_kcalloc(&client->dev, LP3952_LED_ALL, sizeof(*leds),
-			    GFP_KERNEL);
-	if (!leds) {
-		devm_kfree(&client->dev, priv);
-		return -ENOMEM;
-	}
-
-	priv->leds = leds;
  	priv->client = client;
 
  	priv->enable_gpio = devm_gpiod_get(&client->dev, "nrst",
include/linux/leds-lp3952.h +1 -1
index edd5ed6..49b37ed 100644
@@ -119,7 +119,7 @@ struct lp3952_led_array {
  	struct regmap *regmap;
  	struct i2c_client *client;
  	struct gpio_desc *enable_gpio;
-	struct lp3952_ctrl_hdl *leds;
+	struct lp3952_ctrl_hdl leds[LP3952_LED_ALL];
  };
 
  #endif /* LEDS_LP3952_H_ */

A message that is not in the archive (sent off-list or not yet received): CAFRkauAKLnXakKH1qBKyGdTn7-0-z7Gp_7zj7ii6RBK1uXavAA@mail.gmail.com

#3 lore raw
Quoted 12 lines · Axel Lin

2016-07-18 14:48 GMT+08:00 Jacek Anaszewski <[email protected] <mailto:[email protected]>>:

Hi Axel,

Thanks for catching this. I missed also redundant devm_kfree here. Would it be OK for you if I merged your cleanup with the original patch and added your Reviewed-by to the commit message instead?

Quoted 6 lines

That's fine, you can add Reviewed-by: Axel Lin <[email protected] <mailto:[email protected]>>.

This driver hasn't been pushed to the mainline yet, so it would be nice not to introduce its original version with some shortcomings that need to be immediately fixed.

Fixed up the original patch and updated for-next branch of linux-leds.git.

Signature · 2 lines
Best regards,
Jacek Anaszewski