Skip to contentSkip to conversation

usb: core: handle port status errors in disable_show()

PATCH In review Karl Mehltretter 2 participants 3 messages Aug 10 – Sep 12 USB

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 usb: core: handle port status errors in disable_show()

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

---
Changes in v2:
- Simplify error handling (Alan Stern).

v1: https://lore.kernel.org/r/[email protected]/

 drivers/usb/core/port.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/usb/core/port.c +3 -2
index b4452b665f59..6503668f303b 100644
@@ -96,8 +96,9 @@ static ssize_t disable_show(struct device *dev,
 		goto out_hdev_lock;
 	}
 
-	usb_hub_port_status(hub, port1, &portstatus, &unused);
-	disabled = !usb_port_is_power_on(hub, portstatus);
+	rc = usb_hub_port_status(hub, port1, &portstatus, &unused);
+	if (rc >= 0)
+		disabled = !usb_port_is_power_on(hub, portstatus);
 
  out_hdev_lock:
 	usb_unlock_device(hdev);
Signature · 1 line
2.39.5 (Apple Git-154)
Acked-by on v2 1/1
#1 lore raw
Quoted 10 lines · Karl Mehltretter

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

---

Quoted 27 lines

Changes in v2:
- Simplify error handling (Alan Stern).

v1: https://lore.kernel.org/r/[email protected]/

 drivers/usb/core/port.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/usb/core/port.c +3 -2
index b4452b665f59..6503668f303b 100644
@@ -96,8 +96,9 @@ static ssize_t disable_show(struct device *dev,
 		goto out_hdev_lock;
 	}
 
-	usb_hub_port_status(hub, port1, &portstatus, &unused);
-	disabled = !usb_port_is_power_on(hub, portstatus);
+	rc = usb_hub_port_status(hub, port1, &portstatus, &unused);
+	if (rc >= 0)
+		disabled = !usb_port_is_power_on(hub, portstatus);
 
  out_hdev_lock:
 	usb_unlock_device(hdev);
Signature · 1 line
2.39.5 (Apple Git-154)
#2 lore raw
In reply to Karl Mehltretter
Quoted 6 lines · Karl Mehltretter

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.

Quoted 8 lines
Fixes f061f43d7418c ("usb: hub: port: add sysfs entry to switch port power")
Assisted-by Claude:claude-fable-5

---
Changes in v2:
- Simplify error handling (Alan Stern).

v1: https://lore.kernel.org/r/[email protected]/

Friendly ping. Alan Stern has given his Acked-by for this v2.

Thanks,
Karl