[PATCH] usb: core: handle port status errors in disable_show()

Karl Mehltretter posted 1 patch 1 month, 3 weeks ago
There is a newer version of this series
drivers/usb/core/port.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH] usb: core: handle port status errors in disable_show()
Posted by Karl Mehltretter 1 month, 3 weeks ago
usb_hub_port_status() leaves its output arguments untouched when the
status request fails. disable_show() nevertheless uses portstatus, so a
sysfs read may report the wrong port state instead of an error.

Propagate the status request error.

Fixes: f061f43d7418c ("usb: hub: port: add sysfs entry to switch port power")
Assisted-by: Claude:claude-fable-5
Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
---
 drivers/usb/core/port.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
index b4452b665f591..0022473e526d7 100644
--- a/drivers/usb/core/port.c
+++ b/drivers/usb/core/port.c
@@ -96,7 +96,9 @@ static ssize_t disable_show(struct device *dev,
 		goto out_hdev_lock;
 	}
 
-	usb_hub_port_status(hub, port1, &portstatus, &unused);
+	rc = usb_hub_port_status(hub, port1, &portstatus, &unused);
+	if (rc < 0)
+		goto out_hdev_lock;
 	disabled = !usb_port_is_power_on(hub, portstatus);
 
  out_hdev_lock:
-- 
2.53.0
Re: [PATCH] usb: core: handle port status errors in disable_show()
Posted by Alan Stern 1 month, 3 weeks ago
On Sat, Aug 08, 2026 at 03:16:01PM +0200, Karl Mehltretter wrote:
> usb_hub_port_status() leaves its output arguments untouched when the
> status request fails. disable_show() nevertheless uses portstatus, so a
> sysfs read may report the wrong port state instead of an error.
> 
> Propagate the status request error.
> 
> Fixes: f061f43d7418c ("usb: hub: port: add sysfs entry to switch port power")
> Assisted-by: Claude:claude-fable-5
> Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
> ---
>  drivers/usb/core/port.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
> index b4452b665f591..0022473e526d7 100644
> --- a/drivers/usb/core/port.c
> +++ b/drivers/usb/core/port.c
> @@ -96,7 +96,9 @@ static ssize_t disable_show(struct device *dev,
>  		goto out_hdev_lock;
>  	}
>  
> -	usb_hub_port_status(hub, port1, &portstatus, &unused);
> +	rc = usb_hub_port_status(hub, port1, &portstatus, &unused);
> +	if (rc < 0)
> +		goto out_hdev_lock;
>  	disabled = !usb_port_is_power_on(hub, portstatus);
>  
>   out_hdev_lock:

It would be cleaner and simpler to do:

	if (rc >= 0)
		disabled = !usb_port_is_power_on(hub, portstatus);

Alan Stern