diff mbox series

[2/2] usbip: vhci-hcd: zero sysfs output if port is not running

Message ID 20250610131717.2316278-2-dmantipov@yandex.ru
State New
Headers show
Series None | expand

Commit Message

Dmitry Antipov June 10, 2025, 1:17 p.m. UTC
In 'status_show()', do not emit the header if no data was appended
after (i.e. by 'status_show_not_ready()' or 'status_show_vhci()'),
which makes sense if backed port is not actually running.

Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
 drivers/usb/usbip/vhci_sysfs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/usb/usbip/vhci_sysfs.c b/drivers/usb/usbip/vhci_sysfs.c
index 8c8e90646e6b..9aa54d1d6e4a 100644
--- a/drivers/usb/usbip/vhci_sysfs.c
+++ b/drivers/usb/usbip/vhci_sysfs.c
@@ -151,11 +151,12 @@  static int status_name_to_id(const char *name)
 static ssize_t status_show(struct device *dev,
 			   struct device_attribute *attr, char *out)
 {
-	char *s = out;
+	char *r, *s = out;
 	int pdev_nr;
 
 	out += sprintf(out,
 		       "hub port sta spd dev      sockfd local_busid\n");
+	r = out;
 
 	pdev_nr = status_name_to_id(attr->attr.name);
 	if (pdev_nr < 0)
@@ -163,7 +164,8 @@  static ssize_t status_show(struct device *dev,
 	else
 		out += status_show_vhci(pdev_nr, out);
 
-	return out - s;
+	/* Do not emit the header if no data was appended after. */
+	return r == out ? 0 : out - s;
 }
 
 static ssize_t nports_show(struct device *dev, struct device_attribute *attr,