All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <garsilva@embeddedor.com>
To: mathias.nyman@intel.com, gregkh@linuxfoundation.org
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	Peter Senna Tschudin <peter.senna@gmail.com>,
	"Gustavo A. R. Silva" <garsilva@embeddedor.com>
Subject: [PATCH] usb: host: add cast to avoid potential integer overflow
Date: Thu, 16 Feb 2017 18:16:40 -0600	[thread overview]
Message-ID: <20170217001640.GA9137@embeddedgus> (raw)

The type of variable 'sel' is unsigned int. Such variable is being used
multiple times in a context that expects an expression of type unsigned
long long. So, to avoid any potential integer overflow, a cast to type
unsigned long long is added.

Addresses-Coverity-ID: 703408
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
 drivers/usb/host/xhci.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 50aee8b..8094d9a 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -4298,23 +4298,23 @@ static unsigned long long xhci_calculate_intel_u1_timeout(
 	ep_type = usb_endpoint_type(desc);
 	switch (ep_type) {
 	case USB_ENDPOINT_XFER_CONTROL:
-		timeout_ns = udev->u1_params.sel * 3;
+		timeout_ns = (unsigned long long)udev->u1_params.sel * 3;
 		break;
 	case USB_ENDPOINT_XFER_BULK:
-		timeout_ns = udev->u1_params.sel * 5;
+		timeout_ns = (unsigned long long)udev->u1_params.sel * 5;
 		break;
 	case USB_ENDPOINT_XFER_INT:
 		intr_type = usb_endpoint_interrupt_type(desc);
 		if (intr_type == USB_ENDPOINT_INTR_NOTIFICATION) {
-			timeout_ns = udev->u1_params.sel * 3;
+			timeout_ns = (unsigned long long)udev->u1_params.sel * 3;
 			break;
 		}
 		/* Otherwise the calculation is the same as isoc eps */
 	case USB_ENDPOINT_XFER_ISOC:
 		timeout_ns = xhci_service_interval_to_ns(desc);
 		timeout_ns = DIV_ROUND_UP_ULL(timeout_ns * 105, 100);
-		if (timeout_ns < udev->u1_params.sel * 2)
-			timeout_ns = udev->u1_params.sel * 2;
+		if (timeout_ns < (unsigned long long)udev->u1_params.sel * 2)
+			timeout_ns = (unsigned long long)udev->u1_params.sel * 2;
 		break;
 	default:
 		return 0;
-- 
2.5.0

             reply	other threads:[~2017-02-17  0:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-17  0:16 Gustavo A. R. Silva [this message]
2017-02-20 12:40 ` [PATCH] usb: host: add cast to avoid potential integer overflow David Laight

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=20170217001640.GA9137@embeddedgus \
    --to=garsilva@embeddedor.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=peter.senna@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.