usb: hub: avoid possible division by zero
PATCH 1/1 usb: hub: avoid possible division by zero
Avoid possible division by zero in led_work, if hdev->maxchild is 0.
See also:
http://buildbot.llvm.linuxfoundation.org/checker/scan-build-latest/report-b65939.html#EndPath
--- drivers/usb/core/hub.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/core/hub.c +2 -1
@@ -453,7 +453,8 @@ static void led_work (struct work_struct *work)unsigned changed =0 ;int cursor =-1 ; -if (hdev->state !=USB_STATE_CONFIGURED || hub->quiescing) +if (hdev->state !=USB_STATE_CONFIGURED || hub->quiescing + || hdev->maxchild ==0 )return ;for (i =0 ; i < hdev->maxchild; i++) {
Signature · 1 line
1.8.4.3
Greg Kroah-Hartman
maintainerQuoted 15 lines · Johannes Thumshirn
Avoid possible division by zero in
led_work, ifhdev->maxchildis 0.See also:
http://buildbot.llvm.linuxfoundation.org/checker/scan-build-latest/report-b65939.html#EndPathSigned-off-by Johannes Thumshirn <[email protected]>--- drivers/usb/core/hub.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/usb/core/hub.c +0
-0
drivers/usb/core/hub.c static void led_work (struct work_struct *work) · line 457
Quoted 6 lines
drivers/usb/core/hub.c +2
-1@@ -453,7 +453,8 @@ static void led_work (struct work_struct *work)unsigned changed =0 ;int cursor =-1 ; -if (hdev->state !=USB_STATE_CONFIGURED || hub->quiescing) +if (hdev->state !=USB_STATE_CONFIGURED || hub->quiescing + || hdev->maxchild ==0 )
And how can maxchild ever be equal to 0?
Look at where it is assigned (it comes from bNbrPorts in the descriptor), in hub_configure() and if it is set to 0, the creation of the structure fails and then this code will never run, right?
So I don't think this is needed, and your checker needs to be fixed.
sorry,
greg k-h
Quoted 25 lines · Greg Kroah-Hartman
Quoted 15 lines · Johannes Thumshirn
Avoid possible division by zero in
led_work, ifhdev->maxchildis 0.See also:
http://buildbot.llvm.linuxfoundation.org/checker/scan-build-latest/report-b65939.html#EndPathSigned-off-by Johannes Thumshirn <[email protected]>--- drivers/usb/core/hub.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/usb/core/hub.c +0
-0drivers/usb/core/hub.c static void led_work (struct work_struct *work) · line 457
Quoted 6 lines
drivers/usb/core/hub.c +2
-1@@ -453,7 +453,8 @@ static void led_work (struct work_struct *work)unsigned changed =0 ;int cursor =-1 ; -if (hdev->state !=USB_STATE_CONFIGURED || hub->quiescing) +if (hdev->state !=USB_STATE_CONFIGURED || hub->quiescing + || hdev->maxchild ==0 )And how can maxchild ever be equal to 0?
Quoted 7 lines
Look at where it is assigned (it comes from bNbrPorts in the descriptor), in
hub_configure()and if it is set to 0, the creation of the structure fails and then this code will never run, right?So I don't think this is needed, and your checker needs to be fixed.
sorry,
Args, sorry for the noise. Should've checked that better.