Re: [PATCH v8 1/5] usb: phy: add usb phy notify port status API

Alan Stern
2023-07-24T14:18:57Z

On Mon, Jul 24, 2023 at 06:34:48PM +0800, Stanley Chang wrote:

> --- a/drivers/usb/core/hub.c
> +++ b/drivers/usb/core/hub.c
> @@ -614,6 +614,30 @@ static int hub_ext_port_status(struct usb_hub *hub, int port1, int type,
> ret = 0;
> }
> mutex_unlock(&hub->status_mutex);
> +
> + /*
> + * There is no need to lock status_mutex here, because status_mutex
> + * protects hub->status, and the phy driver only checks the port
> + * status without changing the status.
> + */
> + if (!ret) {
> + struct usb_device *hdev = hub->hdev;
> +
> + /*
> + * Applies to roothub only. That is, when hdev->parent is
> + * empty. Only roothub will be notified of port state
> + * changes, since the USB PHY only cares about changes at
> + * the next level.
> + */
> + if (hdev && !hdev->parent) {

hdev can never be NULL, so you don't need to test it. Also, there
is an is_root_hub() routine you can call here -- it's an inline defined
in usb.h. If you use that then you won't have to explain it in the
comment.

To be fair, there are plenty of other places in the driver that test
!hdev->parent (or !udev->parent) with no explanation.

Alan Stern