public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: musb: Fix signed integer overflow
@ 2025-05-10 21:12 Siddarth Gundu
  2025-05-11  5:52 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Siddarth Gundu @ 2025-05-10 21:12 UTC (permalink / raw)
  To: b-liu, gregkh, linux-usb, linux-kernel; +Cc: skhan, Siddarth Gundu

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)
 #define CPPI_EOP_SET	((u32)(1 << 30))
 #define CPPI_OWN_SET	((u32)(1 << 29))	/* owned by cppi */
 #define CPPI_EOQ_MASK	((u32)(1 << 28))
@@ -48,7 +48,7 @@ struct cppi_rx_stateram {
 #define CPPI_RECV_PKTLEN_MASK 0xFFFF
 #define CPPI_BUFFER_LEN_MASK 0xFFFF
 
-#define CPPI_TEAR_READY ((u32)(1 << 31))
+#define CPPI_TEAR_READY ((u32)1 << 31)
 
 /* CPPI data structure definitions */
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] usb: musb: Fix signed integer overflow
  2025-05-10 21:12 [PATCH] usb: musb: Fix signed integer overflow Siddarth Gundu
@ 2025-05-11  5:52 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2025-05-11  5:52 UTC (permalink / raw)
  To: Siddarth Gundu; +Cc: b-liu, linux-usb, linux-kernel, skhan

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-05-11  5:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-10 21:12 [PATCH] usb: musb: Fix signed integer overflow Siddarth Gundu
2025-05-11  5:52 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox