usb: misc: usbio: Handle negative error code from usb_control_msg()
Subsystems (2)
PATCH 1/1 usb: misc: usbio: Handle negative error code from usb_control_msg()
The sizeof(*cpkt) is unsigned, so comparing "ret < sizeof(*cpkt)" promotes "ret" to unsigned and negative error codes from usb_control_msg() are not caught. Cast the sizeof to int so the error handling works.
---
found by smatch:
- drivers/usb/misc/usbio.c:187 usbio_ctrl_msg() warn: error code type promoted to positive: 'ret'
drivers/usb/misc/usbio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/misc/usbio.c +1 -1
@@ -184,7 +184,7 @@ static int usbio_ctrl_msg(struct usbio_device *usbio, u8 type, u8 cmd,dev_dbg (usbio->dev,"control in %d hdr %*phN data %*phN\n" , ret, (int )sizeof (*cpkt), cpkt, (int )cpkt->len, cpkt->data); -if (ret <sizeof (*cpkt)) { +if (ret < (int )sizeof (*cpkt)) {dev_err (usbio->dev,"USB control in failed: %d\n" , ret);return (ret <0 ) ? ret : -EPROTO ; }
Signature · 1 line
2.53.0
Greg KH
maintainerQuoted 19 lines · Serhat Kumral
The
sizeof(*cpkt)is unsigned, so comparing "ret <sizeof(*cpkt)" promotes "ret" to unsigned and negative error codes fromusb_control_msg()are not caught. Cast the sizeof to int so the error handling works.Fixes 121a0f839dbb ("usb: misc: Add Intel USBIO bridge driver")Assisted-by LLMSigned-off-by Serhat Kumral <[email protected]>---
found by smatch:
-drivers/usb/misc/usbio.c:187usbio_ctrl_msg()warn: error code type promoted to positive: 'ret'drivers/usb/misc/usbio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/usb/misc/usbio.c +0
-0
drivers/usb/misc/usbio.c static int usbio_ctrl_msg(struct usbio_device *usbio, u8 type, u8 cmd, · line 187
Quoted 5 lines
drivers/usb/misc/usbio.c +1
-1@@ -184,7 +184,7 @@ static int usbio_ctrl_msg(struct usbio_device *usbio, u8 type, u8 cmd,dev_dbg (usbio->dev,"control in %d hdr %*phN data %*phN\n" , ret, (int )sizeof (*cpkt), cpkt, (int )cpkt->len, cpkt->data); -if (ret <sizeof (*cpkt)) { +if (ret < (int )sizeof (*cpkt)) {
Ick, really? There's no compiler check for this type of thing?
This whole function needs to be rewritten to use the "modern" control message functions. I gave it a go once, but it quickly got messy as this is an abused function and it really should be massivly cleaned up.
Do you have the hardware for this to test changes?
thanks,
greg k-h
Quoted 7 lines · Greg KH
Ick, really? There's no compiler check for this type of thing?
This whole function needs to be rewritten to use the "modern" control message functions. I gave it a go once, but it quickly got messy as this is an abused function and it really should be massivly cleaned up.
Do you have the hardware for this to test changes?
Unfortunately I don't have the hardware. I relied on static analysis and tried to keep things quite simple
thanks,
Serhat