From a5e5a27ea06db54b4669d141f954f6108fa2c947 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 21 Nov 2025 09:11:21 -0400 Subject: [PATCH] MT#55283 use seq_printf for /status Change-Id: I71cd6e34e590da6b6c9b339191642a2a565dcb4e --- kernel-module/xt_RTPENGINE.c | 61 +++++++++++++++++------------------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/kernel-module/xt_RTPENGINE.c b/kernel-module/xt_RTPENGINE.c index 93347efc8..2a0f8b330 100644 --- a/kernel-module/xt_RTPENGINE.c +++ b/kernel-module/xt_RTPENGINE.c @@ -232,7 +232,7 @@ static ssize_t proc_control_write(struct file *, const char __user *, size_t, lo static int proc_control_open(struct inode *, struct file *); static int proc_control_close(struct inode *, struct file *); -static ssize_t proc_status(struct file *, char __user *, size_t, loff_t *); +static int proc_status_open(struct inode *i, struct file *f); static ssize_t proc_main_control_write(struct file *, const char __user *, size_t, loff_t *); @@ -240,6 +240,7 @@ static int proc_generic_open_modref(struct inode *, struct file *); static int proc_generic_open_stream_modref(struct inode *inode, struct file *file); static int proc_generic_close_modref(struct inode *, struct file *); static int proc_generic_seqrelease_modref(struct inode *inode, struct file *file); +static int proc_generic_singlerelease_modref(struct inode *inode, struct file *file); static int proc_list_open(struct inode *, struct file *); @@ -648,9 +649,10 @@ static const struct PROC_OP_STRUCT proc_main_control_ops = { static const struct PROC_OP_STRUCT proc_status_ops = { PROC_OWNER - .PROC_READ = proc_status, - .PROC_OPEN = proc_generic_open_modref, - .PROC_RELEASE = proc_generic_close_modref, + .PROC_OPEN = proc_status_open, + .PROC_READ = seq_read, + .PROC_LSEEK = seq_lseek, + .PROC_RELEASE = proc_generic_singlerelease_modref, }; static const struct PROC_OP_STRUCT proc_list_ops = { @@ -1312,50 +1314,39 @@ static struct rtpengine_table *get_table(unsigned int id) { -static ssize_t proc_status(struct file *f, char __user *b, size_t l, loff_t *o) { - struct inode *inode; - char buf[256]; - struct rtpengine_table *t; - int len = 0; - unsigned long flags; - uint32_t id; - - if (*o > 0) - return 0; - if (*o < 0) - return -EINVAL; - if (l < sizeof(buf)) - return -EINVAL; - - inode = f->f_path.dentry->d_inode; - id = (uint32_t) (unsigned long) PDE_DATA(inode); - t = get_table(id); +static int proc_status_show(struct seq_file *m, void *v) { + struct inode *inode = m->private; + uint32_t id = (uint32_t) (unsigned long) PDE_DATA(inode); + struct rtpengine_table *t = get_table(id); if (!t) return -ENOENT; + unsigned long flags; + read_lock_irqsave(&t->target_lock, flags); - len += sprintf(buf + len, "Refcount: %u\n", atomic_read(&t->refcnt) - 1); - len += sprintf(buf + len, "Control PID: %u\n", t->pid); - len += sprintf(buf + len, "Targets: %u\n", t->num_targets); + seq_printf(m, "Refcount: %u\n", atomic_read(&t->refcnt) - 1); + seq_printf(m, "Control PID: %u\n", t->pid); + seq_printf(m, "Targets: %u\n", t->num_targets); read_unlock_irqrestore(&t->target_lock, flags); // unlocked/unsafe read - len += sprintf(buf + len, "Players: %u\n", t->num_play_streams); - len += sprintf(buf + len, "PStreams: %u\n", t->num_packet_streams); - len += sprintf(buf + len, "Memory pins: %u\n", t->nshms); - len += sprintf(buf + len, "Memory: %lu\n",t->shm_total); + seq_printf(m, "Players: %u\n", t->num_play_streams); + seq_printf(m, "PStreams: %u\n", t->num_packet_streams); + seq_printf(m, "Memory pins: %u\n", t->nshms); + seq_printf(m, "Memory: %lu\n",t->shm_total); table_put(t); - if (copy_to_user(b, buf, len)) - return -EFAULT; - *o += len; + return 0; +} - return len; +static int proc_status_open(struct inode *i, struct file *f) { + return single_open(f, proc_status_show, i); } + static int proc_main_list_open(struct inode *i, struct file *f) { int err; if ((err = proc_generic_open_modref(i, f))) @@ -2818,6 +2809,10 @@ static int proc_generic_seqrelease_modref(struct inode *inode, struct file *file proc_generic_close_modref(inode, file); return seq_release(inode, file); } +static int proc_generic_singlerelease_modref(struct inode *inode, struct file *file) { + proc_generic_close_modref(inode, file); + return single_release(inode, file); +} static ssize_t proc_main_control_write(struct file *file, const char __user *buf, size_t buflen, loff_t *off) { char b[30];