Skip to contentSkip to conversation

cw1200: Fix a signedness bug in cw1200_load_firmware()

PATCH Superseded Dan Carpenter 2 participants 5 messages Sep 25, 2019 – Oct 2, 2019

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

PATCH 1/1 cw1200: Fix a signedness bug in cw1200_load_firmware()

The "priv->hw_type" is an enum and in this context GCC will treat it as an unsigned int so the error handling will never trigger.

Fixes a910e4a94f69 ("cw1200: add driver for the ST-E CW1100 & CW1200 WLAN chipsets")
---
 drivers/net/wireless/st/cw1200/fwio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/st/cw1200/fwio.c +1 -1
index 6574e78e05ea..da767c33dfbb 100644
@@ -321,7 +321,7 @@ int cw1200_load_firmware(struct cw1200_common *priv)
 	}
 
 	priv->hw_type = cw1200_get_hw_type(val32, &major_revision);
-	if (priv->hw_type < 0) {
+	if ((int)priv->hw_type < 0) {
 		pr_err("Can't deduce hardware type.\n");
 		ret = -ENOTSUPP;
 		goto out;
Signature · 1 line
2.20.1
#1 lore raw
Quoted 14 lines · Dan Carpenter

The "priv->hw_type" is an enum and in this context GCC will treat it as an unsigned int so the error handling will never trigger.

Fixes a910e4a94f69 ("cw1200: add driver for the ST-E CW1100 & CW1200 WLAN chipsets")
---
 drivers/net/wireless/st/cw1200/fwio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/st/cw1200/fwio.c +0 -0
index 6574e78e05ea..da767c33dfbb 100644

drivers/net/wireless/st/cw1200/fwio.c int cw1200_load_firmware(struct cw1200_common *priv) · line 327

Quoted 8 lines
drivers/net/wireless/st/cw1200/fwio.c +1 -1
@@ -321,7 +321,7 @@ int cw1200_load_firmware(struct cw1200_common *priv)
 	}
 
 	priv->hw_type = cw1200_get_hw_type(val32, &major_revision);
-	if (priv->hw_type < 0) {
+	if ((int)priv->hw_type < 0) {
 		pr_err("Can't deduce hardware type.\n");
 		ret = -ENOTSUPP;
 		goto out;

Isn't there any cleaner way to fix this? Like having 'int ret' variable and assign to priv->hw_type after the error handling?

Signature · 1 line
Kalle Valo
#2 lore raw

PATCH v2 1/1 cw1200: Fix a signedness bug in cw1200_load_firmware()

The "priv->hw_type" is an enum and in this context GCC will treat it as an unsigned int so the error handling will never trigger.

Fixes a910e4a94f69 ("cw1200: add driver for the ST-E CW1100 & CW1200 WLAN chipsets")

---
v2: better style and preserve the error code.

 drivers/net/wireless/st/cw1200/fwio.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/wireless/st/cw1200/fwio.c +3 -3
index 6574e78e05ea..2a03dc533b6a 100644
@@ -320,12 +320,12 @@ int cw1200_load_firmware(struct cw1200_common *priv)
 		goto out;
 	}
 
-	priv->hw_type = cw1200_get_hw_type(val32, &major_revision);
-	if (priv->hw_type < 0) {
+	ret = cw1200_get_hw_type(val32, &major_revision);
+	if (ret < 0) {
 		pr_err("Can't deduce hardware type.\n");
-		ret = -ENOTSUPP;
 		goto out;
 	}
+	priv->hw_type = ret;
 
 	/* Set DPLL Reg value, and read back to confirm writes work */
 	ret = cw1200_reg_write_32(priv, ST90TDS_TSET_GEN_R_W_REG_ID,
Signature · 1 line
2.20.1
#3 lore raw
Quoted 18 lines · Dan Carpenter

The "priv->hw_type" is an enum and in this context GCC will treat it as an unsigned int so the error handling will never trigger.

Fixes a910e4a94f69 ("cw1200: add driver for the ST-E CW1100 & CW1200 WLAN chipsets")

---
v2: better style and preserve the error code.

 drivers/net/wireless/st/cw1200/fwio.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/wireless/st/cw1200/fwio.c +0 -0
index 6574e78e05ea..2a03dc533b6a 100644
@@ -320,12 +320,12 @@ int cw1200_load_firmware(struct cw1200_common *priv)
 		goto out;
 	}

drivers/net/wireless/st/cw1200/fwio.c int cw1200_load_firmware(struct cw1200_common *priv) · line 328

Quoted 10 lines
drivers/net/wireless/st/cw1200/fwio.c +3 -3
 
-	priv->hw_type = cw1200_get_hw_type(val32, &major_revision);
-	if (priv->hw_type < 0) {
+	ret = cw1200_get_hw_type(val32, &major_revision);
+	if (ret < 0) {
 		pr_err("Can't deduce hardware type.\n");
-		ret = -ENOTSUPP;
 		goto out;
 	}
+	priv->hw_type = ret;

Thanks, this is indeed much better.

Signature · 1 line
https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#4 lore raw
In reply to Dan Carpenter
Quoted 5 lines · Dan Carpenter

The "priv->hw_type" is an enum and in this context GCC will treat it as an unsigned int so the error handling will never trigger.

Fixes a910e4a94f69 ("cw1200: add driver for the ST-E CW1100 & CW1200 WLAN chipsets")

Patch applied to wireless-drivers-next.git, thanks.

4a50d454502f cw1200: Fix a signedness bug in cw1200_load_firmware()

Signature · 3 lines
https://patchwork.kernel.org/patch/11168561/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches