Skip to contentSkip to conversation

leds: sun50i-a100: Use match_string() helper to simplify the code

PATCH Applied Andy Shevchenko 3 participants 6 messages Apr 26, 2024 – May 2, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 leds: sun50i-a100: Use match_string() helper to simplify the code

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

---
 drivers/leds/leds-sun50i-a100.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/leds/leds-sun50i-a100.c +6 -8
index 62d21c3a3575..119eff9471f0 100644
@@ -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)
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
maintainer
#1 lore raw

Dne petek, 26. april 2024 ob 17:25:15 GMT +2 je Andy Shevchenko napisal(a):

Quoted 20 lines

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

---
 drivers/leds/leds-sun50i-a100.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/leds/leds-sun50i-a100.c +1 -1
index 62d21c3a3575..119eff9471f0 100644
@@ -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);

drivers/leds/leds-sun50i-a100.c static int sun50i_a100_ledc_parse_format(struct device *dev, · line 261

Quoted 10 lines
drivers/leds/leds-sun50i-a100.c +3 -6
 
-	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

Quoted 8 lines
drivers/leds/leds-sun50i-a100.c +2 -1
-	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 lore raw
Quoted 1 line · Jernej Škrabec

Dne petek, 26. april 2024 ob 17:25:15 GMT +2 je Andy Shevchenko napisal(a):

...

Quoted 4 lines

drivers/leds/leds-sun50i-a100.c static int sun50i_a100_ledc_parse_format(struct device *dev, · line 261

Quoted 1 line
drivers/leds/leds-sun50i-a100.c +1 -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()?

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

Quoted 1 line

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.

Quoted 1 line

This is clearly not the case here.

Is it a problem?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer Reviewed-by
#3 lore raw

Dne petek, 26. april 2024 ob 17:45:14 GMT +2 je Andy Shevchenko napisal(a):

Quoted 14 lines · Jernej Škrabec
Quoted 1 line

Dne petek, 26. april 2024 ob 17:25:15 GMT +2 je Andy Shevchenko napisal(a):

...

Quoted 4 lines

drivers/leds/leds-sun50i-a100.c static int sun50i_a100_ledc_parse_format(struct device *dev, · line 261

Quoted 1 line
drivers/leds/leds-sun50i-a100.c +1 -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()?

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

Quoted 1 line

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

Quoted 7 lines

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.

Quoted 1 line

This is clearly not the case here.

Is it a problem?

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

Best regards,
Jernej

#4 lore raw
Quoted 3 lines · Jernej Škrabec

Dne petek, 26. april 2024 ob 17:45:14 GMT +2 je Andy Shevchenko napisal(a):

Quoted 2 lines · Jernej Škrabec
Quoted 1 line

Dne petek, 26. april 2024 ob 17:25:15 GMT +2 je Andy Shevchenko napisal(a):

...

Quoted 13 lines
Quoted 13 lines
Quoted 4 lines

drivers/leds/leds-sun50i-a100.c static int sun50i_a100_ledc_parse_format(struct device *dev, · line 261

Quoted 1 line
drivers/leds/leds-sun50i-a100.c +1 -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()?

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

Quoted 1 line

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.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

This is clearly not the case here.

Is it a problem?

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

No problem.

Quoted 1 line

Thank you for the review!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer Applied
#5 lore raw

Re: (subset) [PATCH v1 1/1] leds: sun50i-a100: Use match_string() helper to simplify the code

In reply to Andy Shevchenko
Quoted 4 lines · Andy Shevchenko

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 [李琼斯]