leds: lm3532: Fix optional led-max-microamp prop error handling
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
@@ -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
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
Reported-by Pavel Machek <[email protected]>Signed-off-by Dan Murphy <[email protected]>--- drivers/leds/leds-lm3532.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)drivers/leds/leds-lm3532.c +0
-3@@ -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
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
Reported-by Pavel Machek <[email protected]>Signed-off-by Dan Murphy <[email protected]>--- drivers/leds/leds-lm3532.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)drivers/leds/leds-lm3532.c +0
-0@@ -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 inkernel.hfor 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
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
Reported-by Pavel Machek <[email protected]>Signed-off-by Dan Murphy <[email protected]>--- drivers/leds/leds-lm3532.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)drivers/leds/leds-lm3532.c +0
-0@@ -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 inkernel.hfor 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
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
Reported-by Pavel Machek <[email protected]>Signed-off-by Dan Murphy <[email protected]>
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html