Skip to content

Commit

Permalink
leds: sun50i-a100: Use match_string() helper to simplify the code
Browse files Browse the repository at this point in the history
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>
Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Link: https://lore.kernel.org/r/20240426152515.872917-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Lee Jones <lee@kernel.org>
  • Loading branch information
Andy Shevchenko authored and Lee Jones committed May 2, 2024
1 parent 974afcc commit 3b29c7b
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions drivers/leds/leds-sun50i-a100.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3b29c7b

Please sign in to comment.