Skip to contentSkip to conversation

net: phy: bcm54140: fix less than zero comparison on an unsigned

PATCH Applied Colin King 4 participants 5 messages Apr 23, 2020

Subsystems (5)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 net: phy: bcm54140: fix less than zero comparison on an unsigned

From: Colin Ian King <[email protected]>

Currently the unsigned variable tmp is being checked for an negative error return from the call to bcm_phy_read_rdb and this can never be true since tmp is unsigned. Fix this by making tmp a plain int.

Addresses-Coverity: ("Unsigned compared against 0")

Fixes 4406d36dfdf1 ("net: phy: bcm54140: add hwmon support")
---
 drivers/net/phy/bcm54140.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/phy/bcm54140.c +4 -2
index aa854477e06a..7341f0126cc4 100644
@@ -191,7 +191,8 @@ static int bcm54140_hwmon_read_alarm(struct device *dev, unsigned int bit,
 static int bcm54140_hwmon_read_temp(struct device *dev, u32 attr, long *val)
 {
 	struct phy_device *phydev = dev_get_drvdata(dev);
-	u16 reg, tmp;
+	u16 reg;
+	int tmp;
 
 	switch (attr) {
 	case hwmon_temp_input:
@@ -224,7 +225,8 @@ static int bcm54140_hwmon_read_in(struct device *dev, u32 attr,
 				  int channel, long *val)
 {
 	struct phy_device *phydev = dev_get_drvdata(dev);
-	u16 bit, reg, tmp;
+	u16 bit, reg;
+	int tmp;
 
 	switch (attr) {
 	case hwmon_in_input:
Signature · 1 line
2.25.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Colin King

From: Colin Ian King <[email protected]>

Currently the unsigned variable tmp is being checked for an negative error return from the call to bcm_phy_read_rdb and this can never be true since tmp is unsigned. Fix this by making tmp a plain int.

Addresses-Coverity: ("Unsigned compared against 0")

I thought 0 was unsigned?

Quoted 2 lines
Fixes 4406d36dfdf1 ("net: phy: bcm54140: add hwmon support")

Andrew

#2 lore raw
Quoted 10 lines · Andrew Lunn
Quoted 7 lines · Colin King

From: Colin Ian King <[email protected]>

Currently the unsigned variable tmp is being checked for an negative error return from the call to bcm_phy_read_rdb and this can never be true since tmp is unsigned. Fix this by making tmp a plain int.

Addresses-Coverity: ("Unsigned compared against 0")

I thought 0 was unsigned?

yeah, misleading message from the static analyzer methinks

Quoted 8 lines
Quoted 3 lines
Fixes 4406d36dfdf1 ("net: phy: bcm54140: add hwmon support")

Andrew

Reviewed-by on v1 1/1
#3 lore raw
In reply to Colin King

Am 2020-04-23 16:10, schrieb Colin King:

Quoted 9 lines

From: Colin Ian King <[email protected]>

Currently the unsigned variable tmp is being checked for an negative error return from the call to bcm_phy_read_rdb and this can never be true since tmp is unsigned. Fix this by making tmp a plain int.

Addresses-Coverity: ("Unsigned compared against 0")

Fixes 4406d36dfdf1 ("net: phy: bcm54140: add hwmon support")

FWIW since Andrew already reviewed it:

-michael

maintainer Applied
#4 lore raw
In reply to Colin King

From: Colin King <[email protected]>
Date: Thu, 23 Apr 2020 15:10:16 +0100

Quoted 9 lines

From: Colin Ian King <[email protected]>

Currently the unsigned variable tmp is being checked for an negative error return from the call to bcm_phy_read_rdb and this can never be true since tmp is unsigned. Fix this by making tmp a plain int.

Addresses-Coverity: ("Unsigned compared against 0")

Fixes 4406d36dfdf1 ("net: phy: bcm54140: add hwmon support")

Applied.