Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp90617imm; Thu, 12 Jul 2018 14:50:26 -0700 (PDT) X-Google-Smtp-Source: AAOMgpehgpfu0zCUJmGKMF2tRvMNIH6I1vpyAjdZZi2A6jatB5lprUBd/6eyuIMNpPzjCJyHXGjT X-Received: by 2002:a65:64d7:: with SMTP id t23-v6mr3667167pgv.207.1531432225936; Thu, 12 Jul 2018 14:50:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531432225; cv=none; d=google.com; s=arc-20160816; b=SNQ+9qx2XZp9WRj+9AxRWnXkONPgKg83hDAY6N1If/AIitJsUAzxUZPZSZW4Dyquqe 7t2Qnhhpi/q6dz+o5glCALAbB5EslkoNk00s2txlI6algBDT0SufQCXmwPkCyf/aY3/9 AxqGc+mMfK5U1WuLN4231UZOgN0PEoryeu2jLsJuWoNezq76PAgomewUI+9AFzuuvJrU uzCglvUtbICFn7xA+osMUMsRp+NPOj6l3ahQd5o+R/Mo2IHftV8z3NQPOEwKXRukcWRN baUq0StU5cwm8pEjMVZC/T4XvTMy1SDpPF7lVHfrvmNPIdXoC183cqPJxwEjnA9x1Bw8 G9Sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=Q66GlWi/pI5Y9g4lbMwylraG0c0k69hWhLbgFKAj7B0=; b=LRCFa2O92P+DhgTYSoAIV42jBmehQjnb7syHmCyDRHOkDjLmnxO8rQ3Klo78x4RYgP Zbvxyq820cQhBu3J6n+44LOnxU8VqHXpH+yY4m/CoV1K9EYKHyd2KY4/LYSm/U1OSwcb liiAFpQZHzf1FqOccdQf6wHqQeGOpAqWdPHX8Hz4sKPellgJ5EmYcJUHGW8SHiB0aPqI Alsrg68wRZ0Lywq+ANh14N0eVYb7nXI1byyBgMgdLueVfG+ZaxClOUKseyRhx02ikMi8 uPPdGR6/e539uXi5c6BiFTKgZ1zF12LgqXqK7Ewn9pm7nBPE/ecmtyTZz2MUu/G6b58N U2VA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a24-v6si1707516pgh.357.2018.07.12.14.50.10; Thu, 12 Jul 2018 14:50:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732331AbeGLWAj (ORCPT + 99 others); Thu, 12 Jul 2018 18:00:39 -0400 Received: from mx2.mpynet.fi ([82.197.21.85]:23596 "EHLO mx2.mpynet.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726550AbeGLWAj (ORCPT ); Thu, 12 Jul 2018 18:00:39 -0400 X-Greylist: delayed 536 seconds by postgrey-1.27 at vger.kernel.org; Thu, 12 Jul 2018 18:00:37 EDT From: Tuomas Tynkkynen To: "Michael S . Tsirkin" CC: Amit Shah , Arnd Bergmann , Greg Kroah-Hartman , , , Tuomas Tynkkynen Subject: [PATCH 1/3] virtio: virtconsole: Use seq_file for debugfs operations Date: Fri, 13 Jul 2018 00:39:56 +0300 Message-ID: <20180712213956.21516-1-tuomas@tuxera.com> X-Mailer: git-send-email 2.16.3 MIME-Version: 1.0 Content-Type: text/plain X-ClientProxiedBy: tuxera-exch.ad.tuxera.com (10.20.48.11) To tuxera-exch.ad.tuxera.com (10.20.48.11) Received-SPF: none Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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