public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Siddarth Gundu <siddarthsgml@gmail.com>
Cc: b-liu@ti.com, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org, skhan@linuxfoundation.org
Subject: Re: [PATCH] usb: musb: Fix signed integer overflow
Date: Sun, 11 May 2025 07:52:10 +0200	[thread overview]
Message-ID: <2025051109-corner-womanless-e400@gregkh> (raw)
In-Reply-To: <20250510211217.122790-1-siddarthsgml@gmail.com>

On Sun, May 11, 2025 at 02:42:17AM +0530, Siddarth Gundu wrote:
> Shifting 1 << 31 on a 32-bit int causes signed integer overflow, which
> leads to undefined behavior.
> 
> Cast 1 to u32 before performing the shift, eliminating the
> undefined behavior.
> 
> Signed-off-by: Siddarth Gundu <siddarthsgml@gmail.com>
> ---
>  drivers/usb/musb/cppi_dma.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/musb/cppi_dma.h b/drivers/usb/musb/cppi_dma.h
> index 3606be897cb2..33bf5f83f08d 100644
> --- a/drivers/usb/musb/cppi_dma.h
> +++ b/drivers/usb/musb/cppi_dma.h
> @@ -38,7 +38,7 @@ struct cppi_rx_stateram {
>  };
>  
>  /* hw_options bits in CPPI buffer descriptors */
> -#define CPPI_SOP_SET	((u32)(1 << 31))
> +#define CPPI_SOP_SET	((u32)1 << 31)

Why not just use the proper BIT() macro instead?

And does this actually overflow and cause problems?  What is the result
of the original code where it is an issue in the driver?  Have you
tested it?  Is the assembly output actually different?

thanks,

greg k-h

      reply	other threads:[~2025-05-11  5:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-10 21:12 [PATCH] usb: musb: Fix signed integer overflow Siddarth Gundu
2025-05-11  5:52 ` Greg KH [this message]

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=2025051109-corner-womanless-e400@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=b-liu@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=siddarthsgml@gmail.com \
    --cc=skhan@linuxfoundation.org \
    /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