misc: rtsx: improve status check
PATCH 1/1 misc: rtsx: improve status check
From: Tom Rix <[email protected]>
clang static analysis flags this error
rtsx_usb.c:505:10: warning: The left operand of '&'
is a garbage value
if (val & cd_mask[card])
~~~ ^
val is set when rtsx_usb_get_card_status() is successful. The problem is how it checks its callers returns.
/* usb_control_msg may return positive when success */ if (ret < 0) return ret;
This is correct for the usb_control_msg() the call. However, the call to rtsx_usb_get_status_with_bulk is only successful when 0 is returned.
So make status checking block specific.
--- drivers/misc/cardreader/rtsx_usb.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/misc/cardreader/rtsx_usb.c +6 -5
@@ -304,14 +304,15 @@ int rtsx_usb_get_card_status(struct rtsx_ucr *ucr, u16 *status) *status = *buf;kfree (buf); + +/* usb_control_msg may return positive when success */ +if (ret <0 ) +return ret; }else { ret =rtsx_usb_get_status_with_bulk (ucr, status); +if (ret) +return ret; } - -/* usb_control_msg may return positive when success */ -if (ret <0 ) -return ret; -return 0 ; }EXPORT_SYMBOL_GPL (rtsx_usb_get_card_status);
Signature · 1 line
2.18.1
Greg KH
maintainerQuoted 33 lines · On Wed, Aug 26, 2020 at 06:53:37AM -0700, [email protected] wrote:
From: Tom Rix <[email protected]>
clang static analysis flags this error
rtsx_usb.c:505:10: warning: The left operand of '&'
is a garbage value
if (val & cd_mask[card])
~~~ ^val is set when
rtsx_usb_get_card_status()is successful. The problem is how it checks its callers returns./* usb_control_msg may return positive when success */ if (ret < 0) return ret;This is correct for the
usb_control_msg()the call. However, the call tortsx_usb_get_status_with_bulkis only successful when 0 is returned.So make status checking block specific.
Fixes 730876be2566 ("mfd: Add realtek USB card reader driver")Signed-off-by Tom Rix <[email protected]>--- drivers/misc/cardreader/rtsx_usb.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)drivers/misc/cardreader/rtsx_usb.c +0
-0
drivers/misc/cardreader/rtsx_usb.c int rtsx_usb_get_card_status(struct rtsx_ucr *ucr, u16 *status) · line 308
Quoted 5 lines
drivers/misc/cardreader/rtsx_usb.c +2
-0@@ -304,14 +304,15 @@ int rtsx_usb_get_card_status(struct rtsx_ucr *ucr, u16 *status) *status = *buf;kfree (buf); + +/* usb_control_msg may return positive when success */
it _WILL_ return positive. it will return negative for an error. It will never return 0.
drivers/misc/cardreader/rtsx_usb.c int rtsx_usb_get_card_status(struct rtsx_ucr *ucr, u16 *status) · line 314
Quoted 12 lines
drivers/misc/cardreader/rtsx_usb.c +4
-5+if (ret <0 ) +return ret; }else { ret =rtsx_usb_get_status_with_bulk (ucr, status); +if (ret) +return ret; } - -/* usb_control_msg may return positive when success */ -if (ret <0 ) -return ret; -
I fail to see how this code is incorrect today.
Well, I do see a bug in here, but you aren't fixing it (short read is not checked), see the recent linux-usb@vger mail thread about that problem that we will be fixing tree-wide over time soon...
How can your move of these lines modify anything?
thanks,
greg k-h