NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

kern/52791: Duplicate test in XHCI's TT hub handling



>Number:         52791
>Category:       kern
>Synopsis:       Duplicate test in XHCI's TT hub handling
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Dec 07 22:00:00 +0000 2017
>Originator:     Robert Sprowson
>Release:        
>Organization:
>Environment:
>Description:
When checking the conditions for turning on TT hub support, a check is made whether dev->ud_myhub is NULL before proceeding to picking the pointer for the ud_depth member.
In the same expression it's checked again before picking the ud_speed member.
There's no need to check it twice, C will evaluate the expression in the order it's written.

See patch against src/sys/dev/usb/xhci.c (same construct twice).
>How-To-Repeat:

>Fix:
--- xhci.1.77.c	2017-11-17 08:22:02.0 +0000
+++ xhci.c	2017-12-07 21:49:29.0 +0000
@@ -3179,8 +3179,7 @@
 	 */
 	if (dev->ud_myhsport != NULL &&
 	    dev->ud_myhub != NULL && dev->ud_myhub->ud_depth != 0 &&
-	    (dev->ud_myhub != NULL &&
-	     dev->ud_myhub->ud_speed == USB_SPEED_HIGH) &&
+	    dev->ud_myhub->ud_speed == USB_SPEED_HIGH &&
 	    (speed == USB_SPEED_LOW || speed == USB_SPEED_FULL)) {
 		ttportnum = dev->ud_myhsport->up_portno;
 		tthubslot = dev->ud_myhsport->up_parent->ud_addr;
@@ -3221,8 +3220,7 @@
 	else if (!ishub &&
 	     (speed == USB_SPEED_LOW || speed == USB_SPEED_FULL) &&
 	     dev->ud_myhub != NULL && dev->ud_myhub->ud_depth != 0 &&
-	     (dev->ud_myhub != NULL &&
-	      dev->ud_myhub->ud_speed == USB_SPEED_HIGH) &&
+	     dev->ud_myhub->ud_speed == USB_SPEED_HIGH &&
 	     dev->ud_myhsport != NULL &&
 	     IS_TTHUB(&dev->ud_myhsport->up_parent->ud_ddesc))
 		usemtt = true;



Home | Main Index | Thread Index | Old Index