linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/1] leds: sun50i-a100: Use match_string() helper to simplify the code
@ 2024-04-26 15:25 Andy Shevchenko
  2024-04-26 15:37 ` Jernej Škrabec
  2024-05-02 17:06 ` (subset) " Lee Jones
  0 siblings, 2 replies; 6+ messages in thread
From: Andy Shevchenko @ 2024-04-26 15:25 UTC (permalink / raw)
  To: Samuel Holland, Andy Shevchenko, linux-leds, linux-arm-kernel,
	linux-sunxi, linux-kernel
  Cc: Pavel Machek, Lee Jones, Chen-Yu Tsai, Jernej Skrabec

match_string() returns the array index of a matching string.
Use it instead of the open-coded implementation.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/leds/leds-sun50i-a100.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/leds/leds-sun50i-a100.c b/drivers/leds/leds-sun50i-a100.c
index 62d21c3a3575..119eff9471f0 100644
--- a/drivers/leds/leds-sun50i-a100.c
+++ b/drivers/leds/leds-sun50i-a100.c
@@ -252,18 +252,16 @@ static int sun50i_a100_ledc_parse_format(struct device *dev,
 					 struct sun50i_a100_ledc *priv)
 {
 	const char *format = "grb";
-	u32 i;
+	int i;
 
 	device_property_read_string(dev, "allwinner,pixel-format", &format);
 
-	for (i = 0; i < ARRAY_SIZE(sun50i_a100_ledc_formats); i++) {
-		if (!strcmp(format, sun50i_a100_ledc_formats[i])) {
-			priv->format = i;
-			return 0;
-		}
-	}
+	i = match_string(sun50i_a100_ledc_formats, ARRAY_SIZE(sun50i_a100_ledc_formats), format);
+	if (i < 0)
+		return dev_err_probe(dev, i, "Bad pixel format '%s'\n", format);
 
-	return dev_err_probe(dev, -EINVAL, "Bad pixel format '%s'\n", format);
+	priv->format = i;
+	return 0;
 }
 
 static void sun50i_a100_ledc_set_format(struct sun50i_a100_ledc *priv)
-- 
2.43.0.rc1.1336.g36b5255a03ac


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 1/1] leds: sun50i-a100: Use match_string() helper to simplify the code
  2024-04-26 15:25 [PATCH v1 1/1] leds: sun50i-a100: Use match_string() helper to simplify the code Andy Shevchenko
@ 2024-04-26 15:37 ` Jernej Škrabec
  2024-04-26 15:45   ` Andy Shevchenko
  2024-05-02 17:06 ` (subset) " Lee Jones
  1 sibling, 1 reply; 6+ messages in thread
From: Jernej Škrabec @ 2024-04-26 15:37 UTC (permalink / raw)
  To: Samuel Holland, Andy Shevchenko, linux-leds, linux-arm-kernel,
	linux-sunxi, linux-kernel, Andy Shevchenko
  Cc: Pavel Machek, Lee Jones, Chen-Yu Tsai

Dne petek, 26. april 2024 ob 17:25:15 GMT +2 je Andy Shevchenko napisal(a):
> match_string() returns the array index of a matching string.
> Use it instead of the open-coded implementation.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/leds/leds-sun50i-a100.c | 14 ++++++--------
>  1 file changed, 6 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/leds/leds-sun50i-a100.c b/drivers/leds/leds-sun50i-a100.c
> index 62d21c3a3575..119eff9471f0 100644
> --- a/drivers/leds/leds-sun50i-a100.c
> +++ b/drivers/leds/leds-sun50i-a100.c
> @@ -252,18 +252,16 @@ static int sun50i_a100_ledc_parse_format(struct device *dev,
>  					 struct sun50i_a100_ledc *priv)
>  {
>  	const char *format = "grb";
> -	u32 i;
> +	int i;
>  
>  	device_property_read_string(dev, "allwinner,pixel-format", &format);
>  
> -	for (i = 0; i < ARRAY_SIZE(sun50i_a100_ledc_formats); i++) {
> -		if (!strcmp(format, sun50i_a100_ledc_formats[i])) {
> -			priv->format = i;
> -			return 0;
> -		}
> -	}
> +	i = match_string(sun50i_a100_ledc_formats, ARRAY_SIZE(sun50i_a100_ledc_formats), format);
> +	if (i < 0)
> +		return dev_err_probe(dev, i, "Bad pixel format '%s'\n", format);

I know that old code used dev_err_probe() without reason, but could you change
it to ordinary dev_err()? dev_err_probe() is useful only when return code could
be -EPROBE_DEFER. This is clearly not the case here.

Best regards,
Jernej

>  
> -	return dev_err_probe(dev, -EINVAL, "Bad pixel format '%s'\n", format);
> +	priv->format = i;
> +	return 0;
>  }
>  
>  static void sun50i_a100_ledc_set_format(struct sun50i_a100_ledc *priv)
> 





_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 1/1] leds: sun50i-a100: Use match_string() helper to simplify the code
  2024-04-26 15:37 ` Jernej Škrabec
@ 2024-04-26 15:45   ` Andy Shevchenko
  2024-04-26 15:55     ` Jernej Škrabec
  0 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2024-04-26 15:45 UTC (permalink / raw)
  To: Jernej Škrabec
  Cc: Samuel Holland, linux-leds, linux-arm-kernel, linux-sunxi,
	linux-kernel, Pavel Machek, Lee Jones, Chen-Yu Tsai

On Fri, Apr 26, 2024 at 05:37:42PM +0200, Jernej Škrabec wrote:
> Dne petek, 26. april 2024 ob 17:25:15 GMT +2 je Andy Shevchenko napisal(a):

...

> > +		return dev_err_probe(dev, i, "Bad pixel format '%s'\n", format);
> 
> I know that old code used dev_err_probe() without reason, but could you change
> it to ordinary dev_err()?

First of all, it's out of scope of _this_ patch.

> dev_err_probe() is useful only when return code could be -EPROBE_DEFER.

This is simply not true. We are trying to have a uniform output in ->probe()
and even documentation for dev_err_probe() was changed long time ago to
encourage using it for non deferred probe cases.

> This is clearly not the case here.

Is it a problem?

-- 
With Best Regards,
Andy Shevchenko



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 1/1] leds: sun50i-a100: Use match_string() helper to simplify the code
  2024-04-26 15:45   ` Andy Shevchenko
@ 2024-04-26 15:55     ` Jernej Škrabec
  2024-04-26 16:33       ` Andy Shevchenko
  0 siblings, 1 reply; 6+ messages in thread
From: Jernej Škrabec @ 2024-04-26 15:55 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Samuel Holland, linux-leds, linux-arm-kernel, linux-sunxi,
	linux-kernel, Pavel Machek, Lee Jones, Chen-Yu Tsai

Dne petek, 26. april 2024 ob 17:45:14 GMT +2 je Andy Shevchenko napisal(a):
> On Fri, Apr 26, 2024 at 05:37:42PM +0200, Jernej Škrabec wrote:
> > Dne petek, 26. april 2024 ob 17:25:15 GMT +2 je Andy Shevchenko napisal(a):
> 
> ...
> 
> > > +		return dev_err_probe(dev, i, "Bad pixel format '%s'\n", format);
> > 
> > I know that old code used dev_err_probe() without reason, but could you change
> > it to ordinary dev_err()?
> 
> First of all, it's out of scope of _this_ patch.
> 
> > dev_err_probe() is useful only when return code could be -EPROBE_DEFER.
> 
> This is simply not true. We are trying to have a uniform output in ->probe()
> and even documentation for dev_err_probe() was changed long time ago to
> encourage using it for non deferred probe cases.
> 
> > This is clearly not the case here.
> 
> Is it a problem?

Sorry, I missed added note for non -EPROBE_DEFER cases.

Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com>

Best regards,
Jernej



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 1/1] leds: sun50i-a100: Use match_string() helper to simplify the code
  2024-04-26 15:55     ` Jernej Škrabec
@ 2024-04-26 16:33       ` Andy Shevchenko
  0 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2024-04-26 16:33 UTC (permalink / raw)
  To: Jernej Škrabec
  Cc: Samuel Holland, linux-leds, linux-arm-kernel, linux-sunxi,
	linux-kernel, Pavel Machek, Lee Jones, Chen-Yu Tsai

On Fri, Apr 26, 2024 at 05:55:22PM +0200, Jernej Škrabec wrote:
> Dne petek, 26. april 2024 ob 17:45:14 GMT +2 je Andy Shevchenko napisal(a):
> > On Fri, Apr 26, 2024 at 05:37:42PM +0200, Jernej Škrabec wrote:
> > > Dne petek, 26. april 2024 ob 17:25:15 GMT +2 je Andy Shevchenko napisal(a):

...

> > > > +		return dev_err_probe(dev, i, "Bad pixel format '%s'\n", format);
> > > 
> > > I know that old code used dev_err_probe() without reason, but could you change
> > > it to ordinary dev_err()?
> > 
> > First of all, it's out of scope of _this_ patch.
> > 
> > > dev_err_probe() is useful only when return code could be -EPROBE_DEFER.
> > 
> > This is simply not true. We are trying to have a uniform output in ->probe()
> > and even documentation for dev_err_probe() was changed long time ago to
> > encourage using it for non deferred probe cases.
> > 
> > > This is clearly not the case here.
> > 
> > Is it a problem?
> 
> Sorry, I missed added note for non -EPROBE_DEFER cases.

No problem.

> Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com>

Thank you for the review!

-- 
With Best Regards,
Andy Shevchenko



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: (subset) [PATCH v1 1/1] leds: sun50i-a100: Use match_string() helper to simplify the code
  2024-04-26 15:25 [PATCH v1 1/1] leds: sun50i-a100: Use match_string() helper to simplify the code Andy Shevchenko
  2024-04-26 15:37 ` Jernej Škrabec
@ 2024-05-02 17:06 ` Lee Jones
  1 sibling, 0 replies; 6+ messages in thread
From: Lee Jones @ 2024-05-02 17:06 UTC (permalink / raw)
  To: Samuel Holland, linux-leds, linux-arm-kernel, linux-sunxi,
	linux-kernel, Andy Shevchenko
  Cc: Pavel Machek, Lee Jones, Chen-Yu Tsai, Jernej Skrabec

On Fri, 26 Apr 2024 18:25:15 +0300, Andy Shevchenko wrote:
> match_string() returns the array index of a matching string.
> Use it instead of the open-coded implementation.
> 
> 

Applied, thanks!

[1/1] leds: sun50i-a100: Use match_string() helper to simplify the code
      commit: 3b29c7b9f701e5afbe6b536eb2744acb25cf5bfd

--
Lee Jones [李琼斯]


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2024-05-02 17:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-26 15:25 [PATCH v1 1/1] leds: sun50i-a100: Use match_string() helper to simplify the code Andy Shevchenko
2024-04-26 15:37 ` Jernej Škrabec
2024-04-26 15:45   ` Andy Shevchenko
2024-04-26 15:55     ` Jernej Škrabec
2024-04-26 16:33       ` Andy Shevchenko
2024-05-02 17:06 ` (subset) " Lee Jones

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).