public inbox for linux-leds@vger.kernel.org
 help / color / mirror / Atom feed
From: Jacek Anaszewski <jacek.anaszewski@gmail.com>
To: Pavel Machek <pavel@ucw.cz>
Cc: Dan Murphy <dmurphy@ti.com>,
	linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] leds: lm3532: Fix optional led-max-microamp prop error handling
Date: Fri, 30 Aug 2019 22:03:37 +0200	[thread overview]
Message-ID: <5afc6d1e-3cec-7d80-0911-9c42f973dae2@gmail.com> (raw)
In-Reply-To: <20190829212247.GB32254@amd>

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

  reply	other threads:[~2019-08-30 20:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2019-08-29 21:23 ` Pavel Machek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5afc6d1e-3cec-7d80-0911-9c42f973dae2@gmail.com \
    --to=jacek.anaszewski@gmail.com \
    --cc=dmurphy@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@ucw.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox