Merge branch 'for-6.9/amd-sfh' into for-linus
[sfrench/cifs-2.6.git] / drivers / usb / core / hub.c
index ffd7c99e24a3624fba07e8277866a5526c6695eb..e38a4124f6102a5ff2a47107a8286815cfc5c8e2 100644 (file)
@@ -2053,9 +2053,19 @@ static void update_port_device_state(struct usb_device *udev)
 
        if (udev->parent) {
                hub = usb_hub_to_struct_hub(udev->parent);
-               port_dev = hub->ports[udev->portnum - 1];
-               WRITE_ONCE(port_dev->state, udev->state);
-               sysfs_notify_dirent(port_dev->state_kn);
+
+               /*
+                * The Link Layer Validation System Driver (lvstest)
+                * has a test step to unbind the hub before running the
+                * rest of the procedure. This triggers hub_disconnect
+                * which will set the hub's maxchild to 0, further
+                * resulting in usb_hub_to_struct_hub returning NULL.
+                */
+               if (hub) {
+                       port_dev = hub->ports[udev->portnum - 1];
+                       WRITE_ONCE(port_dev->state, udev->state);
+                       sysfs_notify_dirent(port_dev->state_kn);
+               }
        }
 }
 
@@ -2388,17 +2398,25 @@ static int usb_enumerate_device_otg(struct usb_device *udev)
                        }
                } else if (desc->bLength == sizeof
                                (struct usb_otg_descriptor)) {
-                       /* Set a_alt_hnp_support for legacy otg device */
-                       err = usb_control_msg(udev,
-                               usb_sndctrlpipe(udev, 0),
-                               USB_REQ_SET_FEATURE, 0,
-                               USB_DEVICE_A_ALT_HNP_SUPPORT,
-                               0, NULL, 0,
-                               USB_CTRL_SET_TIMEOUT);
-                       if (err < 0)
-                               dev_err(&udev->dev,
-                                       "set a_alt_hnp_support failed: %d\n",
-                                       err);
+                       /*
+                        * We are operating on a legacy OTP device
+                        * These should be told that they are operating
+                        * on the wrong port if we have another port that does
+                        * support HNP
+                        */
+                       if (bus->otg_port != 0) {
+                               /* Set a_alt_hnp_support for legacy otg device */
+                               err = usb_control_msg(udev,
+                                       usb_sndctrlpipe(udev, 0),
+                                       USB_REQ_SET_FEATURE, 0,
+                                       USB_DEVICE_A_ALT_HNP_SUPPORT,
+                                       0, NULL, 0,
+                                       USB_CTRL_SET_TIMEOUT);
+                               if (err < 0)
+                                       dev_err(&udev->dev,
+                                               "set a_alt_hnp_support failed: %d\n",
+                                               err);
+                       }
                }
        }
 #endif