Skip to contentSkip to conversation

leds: bcm6328: Replace divide condition with comparison for shift value

PATCH Applied Dipendra Khadka 3 participants 3 messages Oct 19, 2024 – Nov 23, 2024 LED

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 leds: bcm6328: Replace divide condition with comparison for shift value

Fixes the following Smatch warnings:
drivers/leds/leds-bcm6328.c:116 bcm6328_led_mode() warn: replace divide condition 'shift / 16' with 'shift >= 16' drivers/leds/leds-bcm6328.c:360 bcm6328_led() warn: replace divide condition 'shift / 16' with 'shift >= 16'

---
v2:
- Changed the patch subject as suggested
- Changed the patch description
v1: https://lore.kernel.org/all/[email protected]/

 drivers/leds/leds-bcm6328.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/leds/leds-bcm6328.c +2 -2
index 29f5bad61796..592bbf4b7e35 100644
@@ -113,7 +113,7 @@ static void bcm6328_led_mode(struct bcm6328_led *led, unsigned long value)
 	unsigned long val, shift;
 
 	shift = bcm6328_pin2shift(led->pin);
-	if (shift / 16)
+	if (shift >= 16)
 		mode = led->mem + BCM6328_REG_MODE_HI;
 	else
 		mode = led->mem + BCM6328_REG_MODE_LO;
@@ -357,7 +357,7 @@ static int bcm6328_led(struct device *dev, struct device_node *nc, u32 reg,
 		break;
 	case LEDS_DEFSTATE_KEEP:
 		shift = bcm6328_pin2shift(led->pin);
-		if (shift / 16)
+		if (shift >= 16)
 			mode = mem + BCM6328_REG_MODE_HI;
 		else
 			mode = mem + BCM6328_REG_MODE_LO;
Signature · 1 line
2.43.0
maintainer Applied
#1 lore raw

Re: (subset) [PATCH v2] leds: bcm6328: Replace divide condition with comparison for shift value

Quoted 5 lines · Dipendra Khadka

Fixes the following Smatch warnings:
drivers/leds/leds-bcm6328.c:116 bcm6328_led_mode() warn: replace divide condition 'shift / 16' with 'shift >= 16' drivers/leds/leds-bcm6328.c:360 bcm6328_led() warn: replace divide condition 'shift / 16' with 'shift >= 16'

Applied, thanks!

[1/1] leds: bcm6328: Replace divide condition with comparison for shift value

      commit: 5f57672cf4629542b525cfef027e293656915368

--
Lee Jones [李琼斯]

#2 lore raw
In reply to Dipendra Khadka

Sat, Oct 19, 2024 at 07:33:01AM +0000, Dipendra Khadka kirjoitti:

Quoted 3 lines

Fixes the following Smatch warnings:
drivers/leds/leds-bcm6328.c:116 bcm6328_led_mode() warn: replace divide condition 'shift / 16' with 'shift >= 16' drivers/leds/leds-bcm6328.c:360 bcm6328_led() warn: replace divide condition 'shift / 16' with 'shift >= 16'

As discussed with Dan (author of smatch), these warnings make no much sense as "division" by power-of-two numbers in modern world (ISAs, compilers, etc) most unlikely become a real division instruction with all bad consequences. Even though, some ISAs can optimize cases where foo / 16; foo % 16 goes together and this change may break that.

So, please, consider not to send such changes in the future because at least they are just noise, at most might add a (micro-)rgressions.

https://lore.kernel.org/linux-gpio/[email protected]/
https://lore.kernel.org/all/[email protected]/

Signature · 2 lines
With Best Regards,
Andy Shevchenko