Skip to contentSkip to conversation

can: kvaser_pciefd: remove redundant negative check on trigger

PATCH In review Colin King 4 participants 8 messages Jul 25, 2019 – Aug 6, 2019

Subsystems (4)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 can: kvaser_pciefd: remove redundant negative check on trigger

From: Colin Ian King <[email protected]>

The check to see if trigger is less than zero is always false, trigger is always in the range 0..255. Hence the check is redundant and can be removed.

Addresses-Coverity: ("Logically dead code")

---
 drivers/net/can/kvaser_pciefd.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/net/can/kvaser_pciefd.c +0 -3
index 3af747cbbde4..68e00aad0810 100644
@@ -652,9 +652,6 @@ static void kvaser_pciefd_pwm_stop(struct kvaser_pciefd_can *can)
 	top = (pwm_ctrl >> KVASER_PCIEFD_KCAN_PWM_TOP_SHIFT) & 0xff;
 
 	trigger = (100 * top + 50) / 100;
-	if (trigger < 0)
-		trigger = 0;
-
 	pwm_ctrl = trigger & 0xff;
 	pwm_ctrl |= (top & 0xff) << KVASER_PCIEFD_KCAN_PWM_TOP_SHIFT;
 	iowrite32(pwm_ctrl, can->reg_base + KVASER_PCIEFD_KCAN_PWM_REG);
Signature · 1 line
2.20.1
#1 lore raw

Am 25.07.2019 13:25, schrieb Colin King:

Quoted 17 lines

From: Colin Ian King <[email protected]>

The check to see if trigger is less than zero is always false, trigger is always in the range 0..255. Hence the check is redundant and can be removed.

Addresses-Coverity: ("Logically dead code")

---
 drivers/net/can/kvaser_pciefd.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/net/can/kvaser_pciefd.c +0 -0
index 3af747cbbde4..68e00aad0810 100644

drivers/net/can/kvaser_pciefd.c static void kvaser_pciefd_pwm_stop(struct kvaser_pciefd_can *can) · line 657

Quoted 6 lines
drivers/net/can/kvaser_pciefd.c +0 -3
@@ -652,9 +652,6 @@ static void kvaser_pciefd_pwm_stop(struct kvaser_pciefd_can *can)
 	top = (pwm_ctrl >> KVASER_PCIEFD_KCAN_PWM_TOP_SHIFT) & 0xff;
 
 	trigger = (100 * top + 50) / 100;
-	if (trigger < 0)
-		trigger = 0;
-

to be fair i do not understand the calculation here here. (100*top+50)/100 = top+50/100

but seems to be int so it should be =top

did i missunderstand something here ?

re,
wh

Quoted 3 lines
drivers/net/can/kvaser_pciefd.c +0 -0
 	pwm_ctrl = trigger & 0xff;
 	pwm_ctrl |= (top & 0xff) << KVASER_PCIEFD_KCAN_PWM_TOP_SHIFT;
 	iowrite32(pwm_ctrl, can->reg_base + KVASER_PCIEFD_KCAN_PWM_REG);
#2 lore raw
Quoted 22 lines · walter harms

Am 25.07.2019 13:25, schrieb Colin King:

Quoted 19 lines

From: Colin Ian King <[email protected]>

The check to see if trigger is less than zero is always false, trigger is always in the range 0..255. Hence the check is redundant and can be removed.

Addresses-Coverity: ("Logically dead code")

---
 drivers/net/can/kvaser_pciefd.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/net/can/kvaser_pciefd.c +0 -0
index 3af747cbbde4..68e00aad0810 100644
@@ -652,9 +652,6 @@ static void kvaser_pciefd_pwm_stop(struct kvaser_pciefd_can *can)
 	top = (pwm_ctrl >> KVASER_PCIEFD_KCAN_PWM_TOP_SHIFT) & 0xff;
 
Quoted 8 lines

drivers/net/can/kvaser_pciefd.c static void kvaser_pciefd_pwm_stop(struct kvaser_pciefd_can *can) · line 657

Quoted 4 lines
drivers/net/can/kvaser_pciefd.c +0 -3
 	trigger = (100 * top + 50) / 100;
-	if (trigger < 0)
-		trigger = 0;
-

to be fair i do not understand the calculation here here. (100*top+50)/100 = top+50/100

but seems to be int so it should be =top

Indeed it does not do anything, that does look like an unintentional bug. Good catch.

Quoted 10 lines
	did i missunderstand something here ?

	re,
	 wh
Quoted 3 lines
drivers/net/can/kvaser_pciefd.c +0 -0
 	pwm_ctrl = trigger & 0xff;
 	pwm_ctrl |= (top & 0xff) << KVASER_PCIEFD_KCAN_PWM_TOP_SHIFT;
 	iowrite32(pwm_ctrl, can->reg_base + KVASER_PCIEFD_KCAN_PWM_REG);
#3 lore raw
In reply to Colin King

Adding the Author(s) to Cc.

Quoted 18 lines · Colin King

From: Colin Ian King <[email protected]>

The check to see if trigger is less than zero is always false, trigger is always in the range 0..255. Hence the check is redundant and can be removed.

Addresses-Coverity: ("Logically dead code")

---
 drivers/net/can/kvaser_pciefd.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/net/can/kvaser_pciefd.c +0 -0
index 3af747cbbde4..68e00aad0810 100644

drivers/net/can/kvaser_pciefd.c static void kvaser_pciefd_pwm_stop(struct kvaser_pciefd_can *can) · line 657

Quoted 9 lines
drivers/net/can/kvaser_pciefd.c +0 -3
@@ -652,9 +652,6 @@ static void kvaser_pciefd_pwm_stop(struct kvaser_pciefd_can *can)
 	top = (pwm_ctrl >> KVASER_PCIEFD_KCAN_PWM_TOP_SHIFT) & 0xff;
 
 	trigger = (100 * top + 50) / 100;
-	if (trigger < 0)
-		trigger = 0;
-
 	pwm_ctrl = trigger & 0xff;
 	pwm_ctrl |= (top & 0xff) << KVASER_PCIEFD_KCAN_PWM_TOP_SHIFT;
 	iowrite32(pwm_ctrl, can->reg_base + KVASER_PCIEFD_KCAN_PWM_REG);

regards,
Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
#4 lore raw
In reply to Colin King
Quoted 15 lines · Marc Kleine-Budde

Adding the Author(s) to Cc.

Quoted 12 lines · Colin King

From: Colin Ian King <[email protected]>

The check to see if trigger is less than zero is always false, trigger is always in the range 0..255. Hence the check is redundant and can be removed.

Addresses-Coverity: ("Logically dead code")

---
 drivers/net/can/kvaser_pciefd.c | 3 ---
 1 file changed, 3 deletions(-)
Quoted 8 lines

drivers/net/can/kvaser_pciefd.c static void kvaser_pciefd_pwm_stop(struct kvaser_pciefd_can *can) · line 654

Quoted 8 lines
drivers/net/can/kvaser_pciefd.c +0 -0
index 3af747cbbde4..68e00aad0810 100644
@@ -652,9 +652,6 @@ static void kvaser_pciefd_pwm_stop(struct kvaser_pciefd_can *can)
 	top = (pwm_ctrl >> KVASER_PCIEFD_KCAN_PWM_TOP_SHIFT) & 0xff;
 
 	trigger = (100 * top + 50) / 100;

As Walter pointed out the above code makes no sense in the first place.

Quoted 3 lines

drivers/net/can/kvaser_pciefd.c static void kvaser_pciefd_pwm_stop(struct kvaser_pciefd_can *can) · line 657

Quoted 3 lines
drivers/net/can/kvaser_pciefd.c +0 -3
-	if (trigger < 0)
-		trigger = 0;
-

Can someone have a deeper look at this code section and decide what to do with this finding.

Quoted 4 lines

drivers/net/can/kvaser_pciefd.c static void kvaser_pciefd_pwm_stop(struct kvaser_pciefd_can *can) · line 657

Quoted 4 lines
drivers/net/can/kvaser_pciefd.c +0 -0
 	pwm_ctrl = trigger & 0xff;
 	pwm_ctrl |= (top & 0xff) << KVASER_PCIEFD_KCAN_PWM_TOP_SHIFT;
 	iowrite32(pwm_ctrl, can->reg_base + KVASER_PCIEFD_KCAN_PWM_REG);

regards,
Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
#5 lore raw
In reply to Colin King
Quoted 23 lines · On 2019-08-02 14:12,  Marc Kleine-Budde wrote:
Quoted 22 lines · Marc Kleine-Budde

Adding the Author(s) to Cc.

Quoted 19 lines · Colin King

From: Colin Ian King <[email protected]>

The check to see if trigger is less than zero is always false, trigger is always in the range 0..255. Hence the check is redundant and can be removed.

Addresses-Coverity: ("Logically dead code")

---
  drivers/net/can/kvaser_pciefd.c | 3 ---
  1 file changed, 3 deletions(-)
drivers/net/can/kvaser_pciefd.c +0 -0
index 3af747cbbde4..68e00aad0810 100644
@@ -652,9 +652,6 @@ static void kvaser_pciefd_pwm_stop(struct kvaser_pciefd_can *can)
  	top = (pwm_ctrl >> KVASER_PCIEFD_KCAN_PWM_TOP_SHIFT) & 0xff;
 
Quoted 8 lines
Quoted 1 line

drivers/net/can/kvaser_pciefd.c static void kvaser_pciefd_pwm_stop(struct kvaser_pciefd_can *can) · line 654

Quoted 1 line
drivers/net/can/kvaser_pciefd.c +0 -0
  	trigger = (100 * top + 50) / 100;

As Walter pointed out the above code makes no sense in the first place.

Quoted 3 lines

drivers/net/can/kvaser_pciefd.c static void kvaser_pciefd_pwm_stop(struct kvaser_pciefd_can *can) · line 657

Quoted 3 lines
drivers/net/can/kvaser_pciefd.c +0 -3
-	if (trigger < 0)
-		trigger = 0;
-

Can someone have a deeper look at this code section and decide what to do with this finding.

I will look at this at once and come back with a patch later today.

Quoted 6 lines
Quoted 4 lines

drivers/net/can/kvaser_pciefd.c static void kvaser_pciefd_pwm_stop(struct kvaser_pciefd_can *can) · line 657

Quoted 4 lines
drivers/net/can/kvaser_pciefd.c +0 -0
  	pwm_ctrl = trigger & 0xff;
  	pwm_ctrl |= (top & 0xff) << KVASER_PCIEFD_KCAN_PWM_TOP_SHIFT;
  	iowrite32(pwm_ctrl, can->reg_base + KVASER_PCIEFD_KCAN_PWM_REG);

regards,
Marc

regards,

Christer Beskow

#6 lore raw
In reply to Colin King

Den 2019-08-05 kl. 09:21, skrev Christer Beskow:

Quoted 28 lines · Marc Kleine-Budde
Quoted 27 lines · Marc Kleine-Budde
Quoted 15 lines

Adding the Author(s) to Cc.

Quoted 12 lines · Colin King

From: Colin Ian King <[email protected]>

The check to see if trigger is less than zero is always false, trigger is always in the range 0..255.  Hence the check is redundant and can be removed.

Addresses-Coverity: ("Logically dead code")

---
  drivers/net/can/kvaser_pciefd.c | 3 ---

  1 file changed, 3 deletions(-)
Quoted 9 lines

drivers/net/can/kvaser_pciefd.c static void kvaser_pciefd_pwm_stop(struct · line 654

Quoted 9 lines
drivers/net/can/kvaser_pciefd.c +0 -0
index 3af747cbbde4..68e00aad0810 100644
@@ -652,9 +652,6 @@ static void kvaser_pciefd_pwm_stop(struct 
 kvaser_pciefd_can *can)
       top = (pwm_ctrl >> KVASER_PCIEFD_KCAN_PWM_TOP_SHIFT) & 0xff;
         trigger = (100 * top + 50) / 100;

As Walter pointed out the above code makes no sense in the first place.

Quoted 12 lines
Quoted 5 lines
Quoted 3 lines

drivers/net/can/kvaser_pciefd.c static void kvaser_pciefd_pwm_stop(struct kvaser_pciefd_can *can) · line 657

Quoted 3 lines
drivers/net/can/kvaser_pciefd.c +0 -3
-    if (trigger < 0)
-        trigger = 0;
-

Can someone have a deeper look at this code section and decide what to do with this finding.

I will look at this at once and come back with a patch later today.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/can/kvaser_pciefd.c +0 -0
       pwm_ctrl = trigger & 0xff;
       pwm_ctrl |= (top & 0xff) << KVASER_PCIEFD_KCAN_PWM_TOP_SHIFT;
       iowrite32(pwm_ctrl, can->reg_base + KVASER_PCIEFD_KCAN_PWM_REG);

To set the duty cycle to zero (i.e. pwm_stop), the trigger value shall be equal to the top value.

This is achieved by reading the value of the top bit field from the pwm register and then writing back this value to the trigger and top bit fields.

The current code is, as you all pointed out, a bit cumbersome. I will send a new patch in a new thread.

regards

Christer

#7 lore raw
In reply to Colin King
Quoted 7 lines · Christer Beskow
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

      pwm_ctrl = trigger & 0xff;
      pwm_ctrl |= (top & 0xff) << KVASER_PCIEFD_KCAN_PWM_TOP_SHIFT; iowrite32(pwm_ctrl, can->reg_base + KVASER_PCIEFD_KCAN_PWM_REG);

To set the duty cycle to zero (i.e. pwm_stop), the trigger value shall be equal to the top value.

Quoted 6 lines

This is achieved by reading the value of the top bit field from the pwm register and then writing back this value to the trigger and top bit fields.

The current code is, as you all pointed out, a bit cumbersome. I will send a new patch in a new thread.

Thanks. Please include this description in the patch description.

regards,
Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |