From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Khalid Masum <khalid.masum.92@gmail.com>
Cc: Alan Stern <stern@rowland.harvard.edu>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] usb: ehci: Prevent possible modulo by zero
Date: Wed, 24 Aug 2022 07:56:04 +0200 [thread overview]
Message-ID: <YwW9dBW/0TKHPnC1@kroah.com> (raw)
In-Reply-To: <20220823182758.13401-3-khalid.masum.92@gmail.com>
On Wed, Aug 24, 2022 at 12:27:58AM +0600, Khalid Masum wrote:
> usb_maxpacket() returns 0 if it fails to fetch the endpoint. This
> value is later used for calculating modulo. Which can cause modulo
> by zero in qtd_fill.
>
> Prevent this breakage by returning if maxpacket is found to be 0.
>
> Fixes coverity warning: 1487371 ("Division or modulo by zero")
Odd tag format, is that in the documentation?
> Fixes: 9841f37a1cca ("usb: ehci: Add support for SINGLE_STEP_SET_FEATURE test of EHSET")
> Signed-off-by: Khalid Masum <khalid.masum.92@gmail.com>
> ---
> drivers/usb/host/ehci-q.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
> index eb31d13e9ecd..cf2585e9a09f 100644
> --- a/drivers/usb/host/ehci-q.c
> +++ b/drivers/usb/host/ehci-q.c
> @@ -1221,6 +1221,8 @@ static int ehci_submit_single_step_set_feature(
> token |= (1 /* "in" */ << 8); /*This is IN stage*/
>
> maxpacket = usb_maxpacket(urb->dev, urb->pipe);
> + if (unlikely(!maxpacket))
You only ever use likely/unlikely if you can document how it matters
with a benchmark or other way to notice the difference. Otherwise let
the compiler and the CPU do their magic, they know how to do this better
than us.
> + return -1;
A real error number should be returned here if this was valid.
But as Alan said, coverity is often wrong, and unless you can prove
otherwise, this patch isn't valid.
thanks,
greg k-h
next prev parent reply other threads:[~2022-08-24 5:56 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-23 18:27 [PATCH 0/2] usb: ehci: Prevent possible modulo by zero Khalid Masum
2022-08-23 18:27 ` [PATCH 1/2] " Khalid Masum
2022-08-23 20:21 ` Alan Stern
2022-08-24 11:15 ` Khalid Masum
2022-08-24 14:38 ` Alan Stern
2022-08-24 18:07 ` Khalid Masum
2022-08-23 18:27 ` [PATCH 2/2] " Khalid Masum
2022-08-24 5:56 ` Greg Kroah-Hartman [this message]
2022-08-24 11:22 ` Khalid Masum
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=YwW9dBW/0TKHPnC1@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=khalid.masum.92@gmail.com \
--cc=linux-kernel@vger.kernel.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