Skip to contentSkip to conversation

ipmi: msghandler: Fix a signedness bug

PATCH In review Dan Carpenter 2 participants 2 messages Sep 18, 2020

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

PATCH 1/1 ipmi: msghandler: Fix a signedness bug

The type for the completion codes should be unsigned char instead of char. If it is declared as a normal char then the conditions in __get_device_id() are impossible because the IPMI_DEVICE_IN_FW_UPDATE_ERR error codes are higher than 127.

    drivers/char/ipmi/ipmi_msghandler.c:2449 __get_device_id()
    warn: impossible condition '(bmc->cc = 209) => ((-128)-127 = 209)'
Fixes f8910ffa81b0 ("ipmi:msghandler: retry to get device id on an error")
---
 drivers/char/ipmi/ipmi_msghandler.c | 2 +-
 drivers/char/ipmi/ipmi_si_intf.c    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/char/ipmi/ipmi_msghandler.c +1 -1
index 555c3b1e4926..8774a3b8ff95 100644
@@ -319,7 +319,7 @@ struct bmc_device {
 	int                    dyn_guid_set;
 	struct kref	       usecount;
 	struct work_struct     remove_work;
-	char		       cc; /* completion code */
+	unsigned char	       cc; /* completion code */
 };
 #define to_bmc_device(x) container_of((x), struct bmc_device, pdev.dev)
 
drivers/char/ipmi/ipmi_si_intf.c +1 -1
index 164f85007080..0b3dbc7e39fd 100644
@@ -1344,7 +1344,7 @@ static int try_get_dev_id(struct smi_info *smi_info)
 			resp + 2, resp_len - 2, &smi_info->device_id);
 	if (rv) {
 		/* record completion code */
-		char cc = *(resp + 2);
+		unsigned char cc = *(resp + 2);
 
 		if ((cc = IPMI_DEVICE_IN_FW_UPDATE_ERR
 		    || cc = IPMI_DEVICE_IN_INIT_ERR
Signature · 1 line
2.28.0
#1 lore raw
Quoted 7 lines · Dan Carpenter

The type for the completion codes should be unsigned char instead of char. If it is declared as a normal char then the conditions in __get_device_id() are impossible because the IPMI_DEVICE_IN_FW_UPDATE_ERR error codes are higher than 127.

    drivers/char/ipmi/ipmi_msghandler.c:2449 __get_device_id()
    warn: impossible condition '(bmc->cc = 209) => ((-128)-127 = 209)'

Dang, I should have spotted that. Thanks, it's applied.

-corey

Quoted 37 lines
Fixes f8910ffa81b0 ("ipmi:msghandler: retry to get device id on an error")
---
 drivers/char/ipmi/ipmi_msghandler.c | 2 +-
 drivers/char/ipmi/ipmi_si_intf.c    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/char/ipmi/ipmi_msghandler.c +1 -1
index 555c3b1e4926..8774a3b8ff95 100644
@@ -319,7 +319,7 @@ struct bmc_device {
 	int                    dyn_guid_set;
 	struct kref	       usecount;
 	struct work_struct     remove_work;
-	char		       cc; /* completion code */
+	unsigned char	       cc; /* completion code */
 };
 #define to_bmc_device(x) container_of((x), struct bmc_device, pdev.dev)
 
drivers/char/ipmi/ipmi_si_intf.c +1 -1
index 164f85007080..0b3dbc7e39fd 100644
@@ -1344,7 +1344,7 @@ static int try_get_dev_id(struct smi_info *smi_info)
 			resp + 2, resp_len - 2, &smi_info->device_id);
 	if (rv) {
 		/* record completion code */
-		char cc = *(resp + 2);
+		unsigned char cc = *(resp + 2);
 
 		if ((cc = IPMI_DEVICE_IN_FW_UPDATE_ERR
 		    || cc = IPMI_DEVICE_IN_INIT_ERR
Signature · 1 line
2.28.0