Skip to contentSkip to conversation

Staging: leds: replace divide condition 'shift / 16' with 'shift >= 16'

PATCH In review Dipendra Khadka 3 participants 6 messages Sep 22, 2024 – Oct 17, 2024 LED

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Staging: leds: replace divide condition 'shift / 16' with 'shift >= 16'

Smatch reported following:
'''
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' '''
Replacing 'shift / 16' with 'shift >= 16'.

---
 drivers/leds/leds-bcm6328.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/leds/leds-bcm6328.c +2 -2
index 246f1296ab09..13f535ccba0b 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
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Dipendra Khadka

Smatch reported following:
'''
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' '''
Replacing 'shift / 16' with 'shift >= 16'.

BR,
Pavel

Signature · 1 line
People of Russia, stop Putin before his war on Ukraine escalates.
maintainer
#2 lore raw
In reply to Dipendra Khadka

Staging! Why Staging?

Quoted 6 lines · Dipendra Khadka

Smatch reported following:
'''
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' '''
Replacing 'shift / 16' with 'shift >= 16'.

More info please.

- What is the current problem you're attempting to solve?
- How does this patch help with that?
- What are the consequences for not applying this fix?

Quoted 31 lines
---
 drivers/leds/leds-bcm6328.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/leds/leds-bcm6328.c +2 -2
index 246f1296ab09..13f535ccba0b 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
Signature · 1 line
Lee Jones [李琼斯]
Reviewed-by
#3 lore raw

Hi!

Quoted 11 lines

Staging! Why Staging?

Quoted 6 lines · Dipendra Khadka

Smatch reported following:
'''
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' '''
Replacing 'shift / 16' with 'shift >= 16'.

Quoted 5 lines

More info please.

- What is the current problem you're attempting to solve?
- How does this patch help with that?
- What are the consequences for not applying this fix?

Take a look at patch. Doing shift / 16 when testing on >= 16 is just ugly. It is simple cleanup.

Best regards,
Pavel

Quoted 23 lines
Quoted 22 lines
drivers/leds/leds-bcm6328.c +2 -2
@@ -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
Signature · 1 line
People of Russia, stop Putin before his war on Ukraine escalates.
maintainer
#4 lore raw
Quoted 13 lines · Pavel Machek

Hi!

Quoted 11 lines

Staging! Why Staging?

Quoted 6 lines · Dipendra Khadka

Smatch reported following:
'''
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' '''
Replacing 'shift / 16' with 'shift >= 16'.

Quoted 8 lines
Quoted 5 lines

More info please.

- What is the current problem you're attempting to solve?
- How does this patch help with that?
- What are the consequences for not applying this fix?

Take a look at patch. Doing shift / 16 when testing on >= 16 is just ugly. It is simple cleanup.

You missed the point of the comments.

Copying / pasting the warning into the subject-line and commit message without any additional wordage is sub-optimal. Please improve the commit message.

Signature · 1 line
Lee Jones [李琼斯]
#5 lore raw

Hi,

Quoted 22 lines · Lee Jones
Quoted 19 lines · Pavel Machek

Hi!

Quoted 16 lines

Staging! Why Staging?

Quoted 6 lines · Dipendra Khadka

Smatch reported following:
'''
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' '''
Replacing 'shift / 16' with 'shift >= 16'.

More info please.

- What is the current problem you're attempting to solve?
- How does this patch help with that?
- What are the consequences for not applying this fix?

Quoted 9 lines
Quoted 2 lines

Take a look at patch. Doing shift / 16 when testing on >= 16 is just ugly. It is simple cleanup.

You missed the point of the comments.

Copying / pasting the warning into the subject-line and commit message without any additional wordage is sub-optimal. Please improve the commit message.

Sure, I will send a v2 for this.

Quoted 2 lines

--
Lee Jones [李琼斯]

Best regards,
Dipendra Khadka