Skip to contentSkip to conversation

leds: lm3532: Fix optional led-max-microamp prop error handling

PATCH Superseded Dan Murphy 3 participants 5 messages Aug 29, 2019 – Aug 30, 2019 LED

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Dan Murphy

author
#0 lore raw

PATCH 1/1 leds: lm3532: Fix optional led-max-microamp prop error handling

Fix the error handling for the led-max-microamp property. Need to check if the property is present and then if it is retrieve the setting and its max boundary

---
 drivers/leds/leds-lm3532.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/leds/leds-lm3532.c +9 -5
index c5cfd8e3f15f..13b4265fb85a 100644
@@ -601,11 +601,15 @@ static int lm3532_parse_node(struct lm3532_data *priv)
 			goto child_out;
 		}
 
-		ret = fwnode_property_read_u32(child, "led-max-microamp",
-					       &led->full_scale_current);
-
-		if (led->full_scale_current > LM3532_FS_CURR_MAX)
-			led->full_scale_current = LM3532_FS_CURR_MAX;
+		if (fwnode_property_present(child, "led-max-microamp")) {
+			if (fwnode_property_read_u32(child, "led-max-microamp",
+						     &led->full_scale_current))
+				dev_err(&priv->client->dev,
+					"Failed getting led-max-microamp\n");
+
+			if (led->full_scale_current > LM3532_FS_CURR_MAX)
+				led->full_scale_current = LM3532_FS_CURR_MAX;
+		}
 
 		if (led->mode == LM3532_BL_MODE_ALS) {
 			led->mode = LM3532_ALS_CTRL;
Signature · 1 line
2.22.0.214.g8dca754b1e
#1 lore raw

Hi Dan,

Thanks for the update.

Quoted 21 lines · Dan Murphy

Fix the error handling for the led-max-microamp property. Need to check if the property is present and then if it is retrieve the setting and its max boundary

---
 drivers/leds/leds-lm3532.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/leds/leds-lm3532.c +0 -3
index c5cfd8e3f15f..13b4265fb85a 100644
@@ -601,11 +601,15 @@ static int lm3532_parse_node(struct lm3532_data *priv)
 			goto child_out;
 		}
 
-		ret = fwnode_property_read_u32(child, "led-max-microamp",
-					       &led->full_scale_current);
-

drivers/leds/leds-lm3532.c static int lm3532_parse_node(struct lm3532_data *priv) · line 611

Quoted 10 lines
drivers/leds/leds-lm3532.c +8 -2
-		if (led->full_scale_current > LM3532_FS_CURR_MAX)
-			led->full_scale_current = LM3532_FS_CURR_MAX;
+		if (fwnode_property_present(child, "led-max-microamp")) {
+			if (fwnode_property_read_u32(child, "led-max-microamp",
+						     &led->full_scale_current))
+				dev_err(&priv->client->dev,
+					"Failed getting led-max-microamp\n");
+
+			if (led->full_scale_current > LM3532_FS_CURR_MAX)
+				led->full_scale_current = LM3532_FS_CURR_MAX;

One more nit: we have min() macro in kernel.h for such things.

Quoted 5 lines
drivers/leds/leds-lm3532.c +1 -0
+		}
 
 		if (led->mode == LM3532_BL_MODE_ALS) {
 			led->mode = LM3532_ALS_CTRL;
Signature · 2 lines
Best regards,
Jacek Anaszewski
#2 lore raw
Quoted 23 lines · Jacek Anaszewski

Hi Dan,

Thanks for the update.

Quoted 18 lines · Dan Murphy

Fix the error handling for the led-max-microamp property. Need to check if the property is present and then if it is retrieve the setting and its max boundary

---
 drivers/leds/leds-lm3532.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/leds/leds-lm3532.c +0 -0
index c5cfd8e3f15f..13b4265fb85a 100644
@@ -601,11 +601,15 @@ static int lm3532_parse_node(struct lm3532_data *priv)
 			goto child_out;
 		}
 
Quoted 15 lines

drivers/leds/leds-lm3532.c static int lm3532_parse_node(struct lm3532_data *priv) · line 611

Quoted 13 lines
drivers/leds/leds-lm3532.c +8 -5
-		ret = fwnode_property_read_u32(child, "led-max-microamp",
-					       &led->full_scale_current);
-
-		if (led->full_scale_current > LM3532_FS_CURR_MAX)
-			led->full_scale_current = LM3532_FS_CURR_MAX;
+		if (fwnode_property_present(child, "led-max-microamp")) {
+			if (fwnode_property_read_u32(child, "led-max-microamp",
+						     &led->full_scale_current))
+				dev_err(&priv->client->dev,
+					"Failed getting led-max-microamp\n");
+
+			if (led->full_scale_current > LM3532_FS_CURR_MAX)
+				led->full_scale_current = LM3532_FS_CURR_MAX;

One more nit: we have min() macro in kernel.h for such things.

Actually, I believe this one is okay. min() would be also good, but improvement is not that big, as it still duplicates the argument.

led->full_scale_current = min(led->full_scale_current, LM3532_FS_CURR_MAX)

Best regards,
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#3 lore raw
Quoted 40 lines · Pavel Machek
Quoted 23 lines · Jacek Anaszewski

Hi Dan,

Thanks for the update.

Quoted 18 lines · Dan Murphy

Fix the error handling for the led-max-microamp property. Need to check if the property is present and then if it is retrieve the setting and its max boundary

---
 drivers/leds/leds-lm3532.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/leds/leds-lm3532.c +0 -0
index c5cfd8e3f15f..13b4265fb85a 100644
@@ -601,11 +601,15 @@ static int lm3532_parse_node(struct lm3532_data *priv)
 			goto child_out;
 		}
 
Quoted 15 lines

drivers/leds/leds-lm3532.c static int lm3532_parse_node(struct lm3532_data *priv) · line 611

Quoted 13 lines
drivers/leds/leds-lm3532.c +8 -5
-		ret = fwnode_property_read_u32(child, "led-max-microamp",
-					       &led->full_scale_current);
-
-		if (led->full_scale_current > LM3532_FS_CURR_MAX)
-			led->full_scale_current = LM3532_FS_CURR_MAX;
+		if (fwnode_property_present(child, "led-max-microamp")) {
+			if (fwnode_property_read_u32(child, "led-max-microamp",
+						     &led->full_scale_current))
+				dev_err(&priv->client->dev,
+					"Failed getting led-max-microamp\n");
+
+			if (led->full_scale_current > LM3532_FS_CURR_MAX)
+				led->full_scale_current = LM3532_FS_CURR_MAX;

One more nit: we have min() macro in kernel.h for such things.

Quoted 4 lines

Actually, I believe this one is okay. min() would be also good, but improvement is not that big, as it still duplicates the argument.

led->full_scale_current = min(led->full_scale_current, LM3532_FS_CURR_MAX)

I don't see any excuse for not improving that if we are at patch stage. It looks simply cleaner.

Signature · 2 lines
Best regards,
Jacek Anaszewski
Acked-by on v1 1/1
#4 lore raw
In reply to Dan Murphy
Quoted 6 lines · Dan Murphy

Fix the error handling for the led-max-microamp property. Need to check if the property is present and then if it is retrieve the setting and its max boundary

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