[PATCH] virtio_console: clean up port name sysfs attribute

Goncalo Gomes posted 1 patch 6 days, 15 hours ago
drivers/char/virtio_console.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
[PATCH] virtio_console: clean up port name sysfs attribute
Posted by Goncalo Gomes 6 days, 15 hours ago
Fix issues flagged by checkpatch.pl:

Replace `sprintf` with `sysfs_emit` in the `name_show` callback.
sysfs.rst states that `show` methods should only use `sysfs_emit`
when formatting output for user space.

Rename `show_port_name` to `name_show` to follow the naming convention
for sysfs attribute callbacks, and replace the open-coded DEVICE_ATTR()
with DEVICE_ATTR_RO(name) which encodes both the mode and the expected
function name.

Also fix a missing blank line after a declaration in free_buf().

Signed-off-by: Goncalo Gomes <gomesgoncalo+linuxkernel@gmail.com>
---
 drivers/char/virtio_console.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 9a33217c68d9..56bf0f1b8a00 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -352,6 +352,7 @@ static void free_buf(struct port_buffer *buf, bool can_sleep)
 
 	for (i = 0; i < buf->sgpages; i++) {
 		struct page *page = sg_page(&buf->sg[i]);
+
 		if (!page)
 			break;
 		put_page(page);
@@ -1237,17 +1238,17 @@ static int init_port_console(struct port *port)
 	return 0;
 }
 
-static ssize_t show_port_name(struct device *dev,
-			      struct device_attribute *attr, char *buffer)
+static ssize_t name_show(struct device *dev,
+			 struct device_attribute *attr, char *buffer)
 {
 	struct port *port;
 
 	port = dev_get_drvdata(dev);
 
-	return sprintf(buffer, "%s\n", port->name);
+	return sysfs_emit(buffer, "%s\n", port->name);
 }
 
-static DEVICE_ATTR(name, S_IRUGO, show_port_name, NULL);
+static DEVICE_ATTR_RO(name);
 
 static struct attribute *port_sysfs_entries[] = {
 	&dev_attr_name.attr,
-- 
2.54.0
Re: [PATCH] virtio_console: clean up port name sysfs attribute
Posted by Greg KH 6 days, 15 hours ago
On Mon, Jun 01, 2026 at 03:25:08PM +0100, Goncalo Gomes wrote:
> Fix issues flagged by checkpatch.pl:

This is only needed for new code, or stuff in drivers/staging/  Stick to
there unless you know the maintainer will take such changes.

> Replace `sprintf` with `sysfs_emit` in the `name_show` callback.
> sysfs.rst states that `show` methods should only use `sysfs_emit`
> when formatting output for user space.
> 
> Rename `show_port_name` to `name_show` to follow the naming convention
> for sysfs attribute callbacks, and replace the open-coded DEVICE_ATTR()
> with DEVICE_ATTR_RO(name) which encodes both the mode and the expected
> function name.
> 
> Also fix a missing blank line after a declaration in free_buf().

You should have broken this up into multiple patches anyway :(

thanks,

greg k-h