linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] leds: lm3532: Fix optional led-max-microamp prop error handling
@ 2019-08-29 19:18 Dan Murphy
  2019-08-29 20:04 ` Jacek Anaszewski
  2019-08-29 21:23 ` Pavel Machek
  0 siblings, 2 replies; 5+ messages in thread
From: Dan Murphy @ 2019-08-29 19:18 UTC (permalink / raw)
  To: jacek.anaszewski, pavel; +Cc: linux-leds, linux-kernel, 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 <pavel@ucw.cz>
Signed-off-by: Dan Murphy <dmurphy@ti.com>
---
 drivers/leds/leds-lm3532.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/leds/leds-lm3532.c b/drivers/leds/leds-lm3532.c
index c5cfd8e3f15f..13b4265fb85a 100644
--- a/drivers/leds/leds-lm3532.c
+++ b/drivers/leds/leds-lm3532.c
@@ -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;
-- 
2.22.0.214.g8dca754b1e


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] leds: lm3532: Fix optional led-max-microamp prop error handling
  2019-08-29 19:18 [PATCH] leds: lm3532: Fix optional led-max-microamp prop error handling Dan Murphy
@ 2019-08-29 20:04 ` Jacek Anaszewski
  2019-08-29 21:22   ` Pavel Machek
  2019-08-29 21:23 ` Pavel Machek
  1 sibling, 1 reply; 5+ messages in thread
From: Jacek Anaszewski @ 2019-08-29 20:04 UTC (permalink / raw)
  To: Dan Murphy, pavel; +Cc: linux-leds, linux-kernel

Hi Dan,

Thanks for the update.

On 8/29/19 9:18 PM, Dan Murphy wrote:
> 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 <pavel@ucw.cz>
> Signed-off-by: Dan Murphy <dmurphy@ti.com>
> ---
>  drivers/leds/leds-lm3532.c | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/leds/leds-lm3532.c b/drivers/leds/leds-lm3532.c
> index c5cfd8e3f15f..13b4265fb85a 100644
> --- a/drivers/leds/leds-lm3532.c
> +++ b/drivers/leds/leds-lm3532.c
> @@ -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;

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

> +		}
>  
>  		if (led->mode == LM3532_BL_MODE_ALS) {
>  			led->mode = LM3532_ALS_CTRL;
> 

-- 
Best regards,
Jacek Anaszewski

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] leds: lm3532: Fix optional led-max-microamp prop error handling
  2019-08-29 20:04 ` Jacek Anaszewski
@ 2019-08-29 21:22   ` Pavel Machek
  2019-08-30 20:03     ` Jacek Anaszewski
  0 siblings, 1 reply; 5+ messages in thread
From: Pavel Machek @ 2019-08-29 21:22 UTC (permalink / raw)
  To: Jacek Anaszewski; +Cc: Dan Murphy, linux-leds, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1927 bytes --]

On Thu 2019-08-29 22:04:18, Jacek Anaszewski wrote:
> Hi Dan,
> 
> Thanks for the update.
> 
> On 8/29/19 9:18 PM, Dan Murphy wrote:
> > 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 <pavel@ucw.cz>
> > Signed-off-by: Dan Murphy <dmurphy@ti.com>
> > ---
> >  drivers/leds/leds-lm3532.c | 14 +++++++++-----
> >  1 file changed, 9 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/leds/leds-lm3532.c b/drivers/leds/leds-lm3532.c
> > index c5cfd8e3f15f..13b4265fb85a 100644
> > --- a/drivers/leds/leds-lm3532.c
> > +++ b/drivers/leds/leds-lm3532.c
> > @@ -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;
> 
> 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
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] leds: lm3532: Fix optional led-max-microamp prop error handling
  2019-08-29 19:18 [PATCH] leds: lm3532: Fix optional led-max-microamp prop error handling Dan Murphy
  2019-08-29 20:04 ` Jacek Anaszewski
@ 2019-08-29 21:23 ` Pavel Machek
  1 sibling, 0 replies; 5+ messages in thread
From: Pavel Machek @ 2019-08-29 21:23 UTC (permalink / raw)
  To: Dan Murphy; +Cc: jacek.anaszewski, linux-leds, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 491 bytes --]

On Thu 2019-08-29 14:18:36, Dan Murphy wrote:
> 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 <pavel@ucw.cz>
> Signed-off-by: Dan Murphy <dmurphy@ti.com>

Acked-by: Pavel Machek <pavel@ucw.cz>

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

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] leds: lm3532: Fix optional led-max-microamp prop error handling
  2019-08-29 21:22   ` Pavel Machek
@ 2019-08-30 20:03     ` Jacek Anaszewski
  0 siblings, 0 replies; 5+ messages in thread
From: Jacek Anaszewski @ 2019-08-30 20:03 UTC (permalink / raw)
  To: Pavel Machek; +Cc: Dan Murphy, linux-leds, linux-kernel

On 8/29/19 11:22 PM, Pavel Machek wrote:
> On Thu 2019-08-29 22:04:18, Jacek Anaszewski wrote:
>> Hi Dan,
>>
>> Thanks for the update.
>>
>> On 8/29/19 9:18 PM, Dan Murphy wrote:
>>> 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 <pavel@ucw.cz>
>>> Signed-off-by: Dan Murphy <dmurphy@ti.com>
>>> ---
>>>  drivers/leds/leds-lm3532.c | 14 +++++++++-----
>>>  1 file changed, 9 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/drivers/leds/leds-lm3532.c b/drivers/leds/leds-lm3532.c
>>> index c5cfd8e3f15f..13b4265fb85a 100644
>>> --- a/drivers/leds/leds-lm3532.c
>>> +++ b/drivers/leds/leds-lm3532.c
>>> @@ -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;
>>
>> 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)

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

-- 
Best regards,
Jacek Anaszewski

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-08-30 20:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-29 19:18 [PATCH] leds: lm3532: Fix optional led-max-microamp prop error handling Dan Murphy
2019-08-29 20:04 ` Jacek Anaszewski
2019-08-29 21:22   ` Pavel Machek
2019-08-30 20:03     ` Jacek Anaszewski
2019-08-29 21:23 ` Pavel Machek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).