linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: trix@redhat.com
To: arnd@arndb.de, gregkh@linuxfoundation.org,
	rikard.falkeborn@gmail.com, rogerable@realtek.com,
	lee.jones@linaro.org
Cc: linux-kernel@vger.kernel.org, Tom Rix <trix@redhat.com>
Subject: [PATCH] misc: rtsx: improve status check
Date: Wed, 26 Aug 2020 06:53:37 -0700	[thread overview]
Message-ID: <20200826135337.17105-1-trix@redhat.com> (raw)

From: Tom Rix <trix@redhat.com>

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.

Fixes: 730876be2566 ("mfd: Add realtek USB card reader driver")
Signed-off-by: Tom Rix <trix@redhat.com>
---
 drivers/misc/cardreader/rtsx_usb.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/misc/cardreader/rtsx_usb.c b/drivers/misc/cardreader/rtsx_usb.c
index 59eda55d92a3..bd392b0c66af 100644
--- a/drivers/misc/cardreader/rtsx_usb.c
+++ b/drivers/misc/cardreader/rtsx_usb.c
@@ -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);
-- 
2.18.1


             reply	other threads:[~2020-08-26 13:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-26 13:53 trix [this message]
2020-08-26 14:40 ` [PATCH] misc: rtsx: improve status check Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200826135337.17105-1-trix@redhat.com \
    --to=trix@redhat.com \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rikard.falkeborn@gmail.com \
    --cc=rogerable@realtek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).