From: Rui Miguel Silva <rui.silva@linaro.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Alan Stern <stern@rowland.harvard.edu>
Cc: linux-usb@vger.kernel.org, Rui Miguel Silva <rui.silva@linaro.org>
Subject: [PATCH 4/5] usb: isp1760: do not shift in uninitialized slot
Date: Thu, 19 Aug 2021 19:09:28 +0100 [thread overview]
Message-ID: <20210819180929.1327349-5-rui.silva@linaro.org> (raw)
In-Reply-To: <20210819180929.1327349-1-rui.silva@linaro.org>
Even though it is not expected, and would trigger a WARN_ON, killing a
transfer in a uninitialized slot this sequence is warned by clang
analyzer, twice:
drivers/usb/isp1760/isp1760-hcd.c:1976:18: warning: The result of the left shift is undefined because the right operand is negative [clang-analyzer-core.UndefinedBinaryOperatorResult]
skip_map |= (1 << qh->slot);
drivers/usb/isp1760/isp1760-hcd.c:1983:18: warning: The result of the left shift is undefined because the right operand is negative [clang-analyzer-core.UndefinedBinaryOperatorResult]
skip_map |= (1 << qh->slot);
Only set skip map if slot is active.
Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
---
drivers/usb/isp1760/isp1760-hcd.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/drivers/usb/isp1760/isp1760-hcd.c b/drivers/usb/isp1760/isp1760-hcd.c
index aed2714ce0cf..bf8ab3fe2e5a 100644
--- a/drivers/usb/isp1760/isp1760-hcd.c
+++ b/drivers/usb/isp1760/isp1760-hcd.c
@@ -1974,16 +1974,20 @@ static void kill_transfer(struct usb_hcd *hcd, struct urb *urb,
/* We need to forcefully reclaim the slot since some transfers never
return, e.g. interrupt transfers and NAKed bulk transfers. */
if (usb_pipecontrol(urb->pipe) || usb_pipebulk(urb->pipe)) {
- skip_map = isp1760_hcd_read(hcd, HC_ATL_PTD_SKIPMAP);
- skip_map |= (1 << qh->slot);
- isp1760_hcd_write(hcd, HC_ATL_PTD_SKIPMAP, skip_map);
- ndelay(100);
+ if (qh->slot != -1) {
+ skip_map = isp1760_hcd_read(hcd, HC_ATL_PTD_SKIPMAP);
+ skip_map |= (1 << qh->slot);
+ isp1760_hcd_write(hcd, HC_ATL_PTD_SKIPMAP, skip_map);
+ ndelay(100);
+ }
priv->atl_slots[qh->slot].qh = NULL;
priv->atl_slots[qh->slot].qtd = NULL;
} else {
- skip_map = isp1760_hcd_read(hcd, HC_INT_PTD_SKIPMAP);
- skip_map |= (1 << qh->slot);
- isp1760_hcd_write(hcd, HC_INT_PTD_SKIPMAP, skip_map);
+ if (qh->slot != -1) {
+ skip_map = isp1760_hcd_read(hcd, HC_INT_PTD_SKIPMAP);
+ skip_map |= (1 << qh->slot);
+ isp1760_hcd_write(hcd, HC_INT_PTD_SKIPMAP, skip_map);
+ }
priv->int_slots[qh->slot].qh = NULL;
priv->int_slots[qh->slot].qtd = NULL;
}
--
2.33.0
next prev parent reply other threads:[~2021-08-19 18:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-19 18:09 [PATCH 0/5] usb: isp1760: clang analyzer fixes Rui Miguel Silva
2021-08-19 18:09 ` [PATCH 1/5] usb: isp1760: ignore return value for bus change pattern Rui Miguel Silva
2021-08-19 18:09 ` [PATCH 2/5] usb: isp1760: check maxpacketsize before using it Rui Miguel Silva
2021-08-19 18:09 ` [PATCH 3/5] usb: isp1760: do not reset retval Rui Miguel Silva
2021-08-19 18:09 ` Rui Miguel Silva [this message]
2021-08-19 18:09 ` [PATCH 5/5] usb: isp1760: clean never read udc_enabled warning Rui Miguel Silva
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=20210819180929.1327349-5-rui.silva@linaro.org \
--to=rui.silva@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-usb@vger.kernel.org \
--cc=stern@rowland.harvard.edu \
/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).