leds: lm3532: Fix optional led-max-microamp prop error handling
PATCH v2 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
---
v2 - Changed full scale current check to use min function
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" ); +else +min (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
Jacek Anaszewski
AppliedHi Dan,
Thank you for the update.
Quoted 29 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]>---
v2 - Changed full scale current check to use min function
drivers/leds/leds-lm3532.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)drivers/leds/leds-lm3532.c +2
-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",
drivers/leds/leds-lm3532.c static int lm3532_parse_node(struct lm3532_data *priv) · line 615
Quoted 10 lines
drivers/leds/leds-lm3532.c +7
-0+ &led->full_scale_current)) +dev_err (&priv->client->dev, +"Failed getting led-max-microamp\n" ); + else + min(led->full_scale_current, +LM3532_FS_CURR_MAX ); + }if (led->mode ==LM3532_BL_MODE_ALS ) { led->mode =LM3532_ALS_CTRL ;
Applied.
Signature · 2 lines
Best regards, Jacek Anaszewski
On 9/12/19 8:32 PM, Jacek Anaszewski wrote:> Hi Dan,
Quoted 25 lines
Thank you 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]>---
v2 - Changed full scale current check to use min function
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 13 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" ); +else +min (led->full_scale_current, +LM3532_FS_CURR_MAX );
I didn't previously notice lack of assignment of min() return value.
I've amended that and while at it improved a bit this construction to avoid some indentations and line breaks:
drivers/leds/leds-lm3532.c +8 -5
@@ -601,11 +601,14 @@ 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" ) && +fwnode_property_read_u32 (child,"led-max-microamp" , + &led->full_scale_current)) +dev_err (&priv->client->dev, +"Failed getting led-max-microamp\n" ); +else + led->full_scale_current =min (led->full_scale_current, +LM3532_FS_CURR_MAX );if (led->mode ==LM3532_BL_MODE_ALS ) { led->mode =LM3532_ALS_CTRL ;
Please let me know in case of any doubts.
Quoted 8 lines
drivers/leds/leds-lm3532.c static int lm3532_parse_node(struct lm3532_data *priv) · line 615
Quoted 5 lines
drivers/leds/leds-lm3532.c +1
-0+ }if (led->mode ==LM3532_BL_MODE_ALS ) { led->mode =LM3532_ALS_CTRL ;Applied.
Signature · 2 lines
Best regards, Jacek Anaszewski
Jacek
Quoted 69 lines · Jacek Anaszewski
On 9/12/19 8:32 PM, Jacek Anaszewski wrote:> Hi Dan,
Quoted 24 lines
Thank you 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]>---
v2 - Changed full scale current check to use min function
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 13 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" ); +else +min (led->full_scale_current, +LM3532_FS_CURR_MAX );I didn't previously notice lack of assignment of
min()return value.I've amended that and while at it improved a bit this construction to avoid some indentations and line breaks:
drivers/leds/leds-lm3532.c +8
-5@@ -601,11 +601,14 @@ 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" ) && +fwnode_property_read_u32 (child,"led-max-microamp" , + &led->full_scale_current)) +dev_err (&priv->client->dev, +"Failed getting led-max-microamp\n" ); +else + led->full_scale_current =min (led->full_scale_current, +LM3532_FS_CURR_MAX );if (led->mode ==LM3532_BL_MODE_ALS ) { led->mode =LM3532_ALS_CTRL ;
Quoted 1 line
Please let me know in case of any doubts.
This looks fine. It always passed for me because I never set the FSC above max
Dan