usb: dwc2: remove useless check of !chan
Subsystems (2)
PATCH 1/1 usb: dwc2: remove useless check of !chan
It looks a bit strange we check !chan after dereference of this pointer with "if (chan->ep_type != USB_ENDPOINT_XFER_CONTROL)".
In fact, when entering the dwc2_hcd_save_data_toggle(), the chan won't be NULL, because its caller or indirect caller has ensured this, specifically, it's checked with below line in dwc2_hc_n_intr()
if (!chan) {
dev_err(hsotg->dev, "## hc_ptr_array for channel is NULL ##\n");
return;
}This addresses the following issue reported by klocwork tool:
- Suspicious dereference of pointer 'chan' before NULL check at
line 518
--- drivers/usb/dwc2/hcd_intr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/dwc2/hcd_intr.c +1 -1
@@ -515,7 +515,7 @@ void dwc2_hcd_save_data_toggle(struct dwc2_hsotg *hsotg,u32 pid = (hctsiz &TSIZ_SC_MC_PID_MASK ) >>TSIZ_SC_MC_PID_SHIFT ;if (chan->ep_type !=USB_ENDPOINT_XFER_CONTROL ) { -if (WARN (!chan || !chan->qh, +if (WARN (!chan->qh,"chan->qh must be specified for non-control eps\n" ))return ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerQuoted 26 lines · Jisheng Zhang
It looks a bit strange we check !chan after dereference of this pointer with "if (
chan->ep_type!=USB_ENDPOINT_XFER_CONTROL)".In fact, when entering the
dwc2_hcd_save_data_toggle(), the chan won't be NULL, because its caller or indirect caller has ensured this, specifically, it's checked with below line indwc2_hc_n_intr()if (!chan) { dev_err(hsotg->dev, "## hc_ptr_array for channel is NULL ##\n"); return; }This addresses the following issue reported by klocwork tool:
- Suspicious dereference of pointer 'chan' before NULL check atline 518Signed-off-by Jisheng Zhang <[email protected]>--- drivers/usb/dwc2/hcd_intr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/usb/dwc2/hcd_intr.c +0
-0
drivers/usb/dwc2/hcd_intr.c void dwc2_hcd_save_data_toggle(struct dwc2_hsotg *hsotg, · line 520
Quoted 7 lines
drivers/usb/dwc2/hcd_intr.c +1
-1@@ -515,7 +515,7 @@ void dwc2_hcd_save_data_toggle(struct dwc2_hsotg *hsotg,u32 pid = (hctsiz &TSIZ_SC_MC_PID_MASK ) >>TSIZ_SC_MC_PID_SHIFT ;if (chan->ep_type !=USB_ENDPOINT_XFER_CONTROL ) { -if (WARN (!chan || !chan->qh, +if (WARN (!chan->qh,"chan->qh must be specified for non-control eps\n" ))return ;
Can this ever actually happen? If so, the machine just rebooted as almost all devices with this hardware in it run with panic-on-warn enabled. If not, can you fix this up to properly handle the error and return correctly and not crash?
thanks,
greg k-h
Quoted 29 lines · Greg Kroah-Hartman
Quoted 28 lines · Jisheng Zhang
It looks a bit strange we check !chan after dereference of this pointer with "if (
chan->ep_type!=USB_ENDPOINT_XFER_CONTROL)".In fact, when entering the
dwc2_hcd_save_data_toggle(), the chan won't be NULL, because its caller or indirect caller has ensured this, specifically, it's checked with below line indwc2_hc_n_intr()if (!chan) { dev_err(hsotg->dev, "## hc_ptr_array for channel is NULL ##\n"); return; }This addresses the following issue reported by klocwork tool:
- Suspicious dereference of pointer 'chan' before NULL check atline 518Signed-off-by Jisheng Zhang <[email protected]>--- drivers/usb/dwc2/hcd_intr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/usb/dwc2/hcd_intr.c +0
-0@@ -515,7 +515,7 @@ void dwc2_hcd_save_data_toggle(struct dwc2_hsotg *hsotg,u32 pid = (hctsiz &TSIZ_SC_MC_PID_MASK ) >>TSIZ_SC_MC_PID_SHIFT ;
Quoted 10 lines
drivers/usb/dwc2/hcd_intr.c void dwc2_hcd_save_data_toggle(struct dwc2_hsotg *hsotg, · line 520
Quoted 5 lines
drivers/usb/dwc2/hcd_intr.c +1
-1if (chan->ep_type !=USB_ENDPOINT_XFER_CONTROL ) { -if (WARN (!chan || !chan->qh, +if (WARN (!chan->qh,"chan->qh must be specified for non-control eps\n" ))return ;Can this ever actually happen? If so, the machine just rebooted as almost all devices with this hardware in it run with panic-on-warn enabled. If not, can you fix this up to properly handle the error and return correctly and not crash?
Good question! The WARN was introduced by below commit 62943b7dfa35 ("usb: dwc2: host: fix the data toggle error in full speed descriptor dma"
IMHO, it can't actually happen. And indeed, WARN() usage isn't suggested in drivers, let me remove the WARN usage in v2
Thanks for the kind review