drivers/usb/host/xhci-hub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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(-)
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;
--
2.34.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. > > 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> > --- The concern here would be that xhci->num_port_caps is <= 0. That's probably not possible so it's likely a false positive. regards, dan carpenter
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
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
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
© 2016 - 2025 Red Hat, Inc.