diff mbox series

xhci: Fix bcdUSB initialization

Message ID 20250227193400.109593-1-abhishektamboli9@gmail.com
State New
Headers show
Series xhci: Fix bcdUSB initialization | expand

Commit Message

Abhishek Tamboli Feb. 27, 2025, 7:34 p.m. UTC
Initialize bcdUSB to 0 to prevent undefined behaviour
if accessed without being explicitly set.

Fix the following smatch error:
drivers/usb/host/xhci-hub.c:71 xhci_create_usb3x_bos_desc()
error: uninitialized symbol 'bcdUSB'

Signed-off-by: Abhishek Tamboli <abhishektamboli9@gmail.com>
---
 drivers/usb/host/xhci-hub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--
2.34.1

Comments

Greg KH Feb. 27, 2025, 7:36 p.m. UTC | #1
On Fri, Feb 28, 2025 at 01:04:00AM +0530, Abhishek Tamboli wrote:
> Initialize bcdUSB to 0 to prevent undefined behaviour
> if accessed without being explicitly set.

Is it actually accessed without being set?  If so, please explain it and
also how the compiler is somehow missing this already?

thanks,

greg k-h
Abhishek Tamboli Feb. 27, 2025, 8:11 p.m. UTC | #2
Hi Greg,
Thanks for the review.
> On Fri, Feb 28, 2025 at 01:04:00AM +0530, Abhishek Tamboli wrote:
> > Initialize bcdUSB to 0 to prevent undefined behaviour
> > if accessed without being explicitly set.
> 
> Is it actually accessed without being set?  If so, please explain it and
> also how the compiler is somehow missing this already?
I added bcdUSB = 0 based on a Smatch warning about potential uninitialized access. 
However, given that bcdUSB is always set in the first loop iteration, 
this might be a false positive.

Regards,
Abhishek
Dan Carpenter Feb. 27, 2025, 8:16 p.m. UTC | #3
On Thu, Feb 27, 2025 at 11:36:24AM -0800, Greg KH wrote:
> On Fri, Feb 28, 2025 at 01:04:00AM +0530, Abhishek Tamboli wrote:
> > Initialize bcdUSB to 0 to prevent undefined behaviour
> > if accessed without being explicitly set.
> 
> Is it actually accessed without being set?  If so, please explain it and
> also how the compiler is somehow missing this already?
> 

This is a Smatch warning, not a compiler warning.

regards,
dan carpenter
diff mbox series

Patch

diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 9693464c0520..5715a8bdda7f 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -39,7 +39,7 @@  static int xhci_create_usb3x_bos_desc(struct xhci_hcd *xhci, char *buf,
 	struct usb_ss_cap_descriptor	*ss_cap;
 	struct usb_ssp_cap_descriptor	*ssp_cap;
 	struct xhci_port_cap		*port_cap = NULL;
-	u16				bcdUSB;
+	u16				bcdUSB = 0;
 	u32				reg;
 	u32				min_rate = 0;
 	u8				min_ssid;