Skip to contentSkip to conversation

leds: an30259a: add a check for devm_regmap_init_i2c

PATCH Applied Chuhong Yuan 3 participants 3 messages Oct 16, 2019 – Nov 4, 2019 LED

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 leds: an30259a: add a check for devm_regmap_init_i2c

an30259a_probe misses a check for devm_regmap_init_i2c and may cause problems.
Add a check and print errors like other leds drivers.

---
Changes in v2:
- Use goto exit instead of return to destroy the mutex when failed.

 drivers/leds/leds-an30259a.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/leds/leds-an30259a.c +7 -0
index 250dc9d6f635..82350a28a564 100644
@@ -305,6 +305,13 @@ static int an30259a_probe(struct i2c_client *client)
 
 	chip->regmap = devm_regmap_init_i2c(client, &an30259a_regmap_config);
 
+	if (IS_ERR(chip->regmap)) {
+		err = PTR_ERR(chip->regmap);
+		dev_err(&client->dev, "Failed to allocate register map: %d\n",
+			err);
+		goto exit;
+	}
+
 	for (i = 0; i < chip->num_leds; i++) {
 		struct led_init_data init_data = {};
 
Signature · 1 line
2.20.1
Reviewed-by on v2 1/1
#1 lore raw

Chuhong

Quoted 17 lines · Chuhong Yuan

an30259a_probe misses a check for devm_regmap_init_i2c and may cause problems.
Add a check and print errors like other leds drivers.

---
Changes in v2:
- Use goto exit instead of return to destroy the mutex when failed.

  drivers/leds/leds-an30259a.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/leds/leds-an30259a.c +0 -0
index 250dc9d6f635..82350a28a564 100644

drivers/leds/leds-an30259a.c static int an30259a_probe(struct i2c_client *client) · line 314

Quoted 10 lines
drivers/leds/leds-an30259a.c +7 -0
@@ -305,6 +305,13 @@ static int an30259a_probe(struct i2c_client *client)
 
  	chip->regmap = devm_regmap_init_i2c(client, &an30259a_regmap_config);
 
+	if (IS_ERR(chip->regmap)) {
+		err = PTR_ERR(chip->regmap);
+		dev_err(&client->dev, "Failed to allocate register map: %d\n",
+			err);
+		goto exit;
+	}
+
Quoted 3 lines
drivers/leds/leds-an30259a.c +0 -0
  	for (i = 0; i < chip->num_leds; i++) {
  		struct led_init_data init_data = {};
 
Applied
#2 lore raw
In reply to Chuhong Yuan
Quoted 5 lines · Chuhong Yuan

an30259a_probe misses a check for devm_regmap_init_i2c and may cause problems.
Add a check and print errors like other leds drivers.

Thanks, applied.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html