linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] virtio: virtconsole: Use seq_file for debugfs operations
@ 2018-07-12 21:39 Tuomas Tynkkynen
  2018-07-13  4:48 ` Amit Shah
  0 siblings, 1 reply; 2+ messages in thread
From: Tuomas Tynkkynen @ 2018-07-12 21:39 UTC (permalink / raw)
  To: Michael S . Tsirkin
  Cc: Amit Shah, Arnd Bergmann, Greg Kroah-Hartman, virtualization,
	linux-kernel, Tuomas Tynkkynen

Simplifies the code and is more conventional to what's used in the rest
of the kernel for debugfs ops.

Signed-off-by: Tuomas Tynkkynen <tuomas@tuxera.com>
---
 drivers/char/virtio_console.c | 60 ++++++++++++++++---------------------------
 1 file changed, 22 insertions(+), 38 deletions(-)

diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 21085515814f..f95f980d108d 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -1310,51 +1310,35 @@ static const struct attribute_group port_attribute_group = {
 	.attrs = port_sysfs_entries,
 };
 
-static ssize_t debugfs_read(struct file *filp, char __user *ubuf,
-			    size_t count, loff_t *offp)
+static int debugfs_show(struct seq_file *s, void *data)
 {
-	struct port *port;
-	char *buf;
-	ssize_t ret, out_offset, out_count;
+	struct port *port = s->private;
+
+	seq_printf(s, "name: %s\n", port->name ? port->name : "");
+	seq_printf(s, "guest_connected: %d\n", port->guest_connected);
+	seq_printf(s, "host_connected: %d\n", port->host_connected);
+	seq_printf(s, "outvq_full: %d\n", port->outvq_full);
+	seq_printf(s, "bytes_sent: %lu\n", port->stats.bytes_sent);
+	seq_printf(s, "bytes_received: %lu\n", port->stats.bytes_received);
+	seq_printf(s, "bytes_discarded: %lu\n", port->stats.bytes_discarded);
+	seq_printf(s, "is_console: %s\n",
+		   is_console_port(port) ? "yes" : "no");
+	seq_printf(s, "console_vtermno: %u\n", port->cons.vtermno);
 
-	out_count = 1024;
-	buf = kmalloc(out_count, GFP_KERNEL);
-	if (!buf)
-		return -ENOMEM;
+	return 0;
+}
 
-	port = filp->private_data;
-	out_offset = 0;
-	out_offset += snprintf(buf + out_offset, out_count,
-			       "name: %s\n", port->name ? port->name : "");
-	out_offset += snprintf(buf + out_offset, out_count - out_offset,
-			       "guest_connected: %d\n", port->guest_connected);
-	out_offset += snprintf(buf + out_offset, out_count - out_offset,
-			       "host_connected: %d\n", port->host_connected);
-	out_offset += snprintf(buf + out_offset, out_count - out_offset,
-			       "outvq_full: %d\n", port->outvq_full);
-	out_offset += snprintf(buf + out_offset, out_count - out_offset,
-			       "bytes_sent: %lu\n", port->stats.bytes_sent);
-	out_offset += snprintf(buf + out_offset, out_count - out_offset,
-			       "bytes_received: %lu\n",
-			       port->stats.bytes_received);
-	out_offset += snprintf(buf + out_offset, out_count - out_offset,
-			       "bytes_discarded: %lu\n",
-			       port->stats.bytes_discarded);
-	out_offset += snprintf(buf + out_offset, out_count - out_offset,
-			       "is_console: %s\n",
-			       is_console_port(port) ? "yes" : "no");
-	out_offset += snprintf(buf + out_offset, out_count - out_offset,
-			       "console_vtermno: %u\n", port->cons.vtermno);
-
-	ret = simple_read_from_buffer(ubuf, count, offp, buf, out_offset);
-	kfree(buf);
-	return ret;
+static int debugfs_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, debugfs_show, inode->i_private);
 }
 
 static const struct file_operations port_debugfs_ops = {
 	.owner = THIS_MODULE,
-	.open  = simple_open,
-	.read  = debugfs_read,
+	.open = debugfs_open,
+	.read = seq_read,
+	.llseek = seq_lseek,
+	.release = single_release,
 };
 
 static void set_console_size(struct port *port, u16 rows, u16 cols)
-- 
2.16.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/3] virtio: virtconsole: Use seq_file for debugfs operations
  2018-07-12 21:39 [PATCH 1/3] virtio: virtconsole: Use seq_file for debugfs operations Tuomas Tynkkynen
@ 2018-07-13  4:48 ` Amit Shah
  0 siblings, 0 replies; 2+ messages in thread
From: Amit Shah @ 2018-07-13  4:48 UTC (permalink / raw)
  To: Tuomas Tynkkynen, Michael S . Tsirkin
  Cc: Amit Shah, Arnd Bergmann, Greg Kroah-Hartman, virtualization,
	linux-kernel



Am 12. Juli 2018 23:39:56 MESZ schrieb Tuomas Tynkkynen <tuomas@tuxera.com>:
>Simplifies the code and is more conventional to what's used in the rest
>of the kernel for debugfs ops.
>
>Signed-off-by: Tuomas Tynkkynen <tuomas@tuxera.com>

Looks good, thanks.

Reviewed-by: Amit Shah <amit@kernel.org>


                Amit

-- 
http://amitshah.net

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-07-13  4:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-12 21:39 [PATCH 1/3] virtio: virtconsole: Use seq_file for debugfs operations Tuomas Tynkkynen
2018-07-13  4:48 ` Amit Shah

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).