All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jernej Škrabec" <jernej.skrabec@gmail.com>
To: Samuel Holland <samuel@sholland.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	linux-leds@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Pavel Machek <pavel@ucw.cz>, Lee Jones <lee@kernel.org>,
	Chen-Yu Tsai <wens@csie.org>
Subject: Re: [PATCH v1 1/1] leds: sun50i-a100: Use match_string() helper to simplify the code
Date: Fri, 26 Apr 2024 17:37:42 +0200	[thread overview]
Message-ID: <3557566.iIbC2pHGDl@jernej-laptop> (raw)
In-Reply-To: <20240426152515.872917-1-andriy.shevchenko@linux.intel.com>

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





WARNING: multiple messages have this Message-ID (diff)
From: "Jernej Škrabec" <jernej.skrabec@gmail.com>
To: Samuel Holland <samuel@sholland.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	linux-leds@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Pavel Machek <pavel@ucw.cz>, Lee Jones <lee@kernel.org>,
	Chen-Yu Tsai <wens@csie.org>
Subject: Re: [PATCH v1 1/1] leds: sun50i-a100: Use match_string() helper to simplify the code
Date: Fri, 26 Apr 2024 17:37:42 +0200	[thread overview]
Message-ID: <3557566.iIbC2pHGDl@jernej-laptop> (raw)
In-Reply-To: <20240426152515.872917-1-andriy.shevchenko@linux.intel.com>

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

  reply	other threads:[~2024-04-26 15:37 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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:25 ` Andy Shevchenko
2024-04-26 15:37 ` Jernej Škrabec [this message]
2024-04-26 15:37   ` Jernej Škrabec
2024-04-26 15:45   ` Andy Shevchenko
2024-04-26 15:45     ` Andy Shevchenko
2024-04-26 15:55     ` Jernej Škrabec
2024-04-26 15:55       ` Jernej Škrabec
2024-04-26 16:33       ` Andy Shevchenko
2024-04-26 16:33         ` Andy Shevchenko
2024-05-02 17:06 ` (subset) " Lee Jones
2024-05-02 17:06   ` Lee Jones

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=3557566.iIbC2pHGDl@jernej-laptop \
    --to=jernej.skrabec@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=lee@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=pavel@ucw.cz \
    --cc=samuel@sholland.org \
    --cc=wens@csie.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.