From cdd1fe09cbc7c02186f6fca173b11a64b2e4d277 Mon Sep 17 00:00:00 2001 From: Tomasz Maciej Nowak Date: Fri, 13 May 2022 15:39:09 +0200 Subject: [PATCH 05/13] Kernel 3.10 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=3cb5bf1bf947d325fcf6e9458952b51cfd7e6677 --- vtunerc_main.c | 98 +++++++++++++++++++++++--------------------------- 1 file changed, 44 insertions(+), 54 deletions(-) diff --git a/vtunerc_main.c b/vtunerc_main.c index 38cb40290bc8..7cc870b0d988 100644 --- a/vtunerc_main.c +++ b/vtunerc_main.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "demux.h" #include "dmxdev.h" @@ -176,64 +177,53 @@ static char *get_fe_name(struct dvb_frontend_info *feinfo) return feinfo ? feinfo->name : "(not set)"; } -/** - * @brief procfs file handler - * @param buffer: - * @param start: - * @param offset: - * @param size: - * @param eof: - * @param data: - * @return =0: success
- * <0: if any error occur - */ -#define MAXBUF 512 -int vtunerc_read_proc(char *buffer, char **start, off_t offset, int size, - int *eof, void *data) +static int vtunerc_read_proc(struct seq_file *seq, void *v) { - char outbuf[MAXBUF] = "[ vtunerc driver, version " - VTUNERC_MODULE_VERSION " ]\n"; - int blen, i, pcnt; - struct vtunerc_ctx *ctx = (struct vtunerc_ctx *)data; - - blen = strlen(outbuf); - sprintf(outbuf+blen, " sessions: %u\n", ctx->stat_ctrl_sess); - blen = strlen(outbuf); - sprintf(outbuf+blen, " TS data : %u\n", ctx->stat_wr_data); - blen = strlen(outbuf); - sprintf(outbuf+blen, " PID tab :"); - pcnt = 0; - for (i = 0; i < MAX_PIDTAB_LEN; i++) { - blen = strlen(outbuf); - if (ctx->pidtab[i] != PID_UNKNOWN) { - sprintf(outbuf+blen, " %x", ctx->pidtab[i]); + int i, pcnt = 0; + struct vtunerc_ctx *ctx = (struct vtunerc_ctx *)seq->private; + seq_printf(seq, "[ vtunerc driver, version " + VTUNERC_MODULE_VERSION " ]\n"); + seq_printf(seq, " sessions: %u\n", ctx->stat_ctrl_sess); + seq_printf(seq, " TS data : %u\n", ctx->stat_wr_data); + seq_printf(seq, " PID tab :"); + for (i = 0; i < MAX_PIDTAB_LEN; i++) + if (ctx->pidtab[i] != PID_UNKNOWN) { + seq_printf(seq, " %x", ctx->pidtab[i]); pcnt++; - } - } - blen = strlen(outbuf); - sprintf(outbuf+blen, " (len=%d)\n", pcnt); - blen = strlen(outbuf); - sprintf(outbuf+blen, " FE type : %s\n", get_fe_name(ctx->feinfo)); - - blen = strlen(outbuf); - sprintf(outbuf+blen, " msg xchg: %d/%d\n", ctx->ctrldev_request.type, ctx->ctrldev_response.type); - - blen = strlen(outbuf); - - if (size < blen) - return -EINVAL; - - if (offset != 0) - return 0; + } + seq_printf(seq, " (len=%d)\n", pcnt); + seq_printf(seq, " FE type : %s\n", get_fe_name(ctx->feinfo)); + seq_printf(seq, " msg xchg: %d/%d\n", ctx->ctrldev_request.type, ctx->ctrldev_response.type); + return 0; +} - strcpy(buffer, outbuf); +static int vtunerc_proc_open(struct inode *inode, struct file *file) +{ + int ret; + struct vtunerc_ctx *ctx = PDE_DATA(inode); + + if (!try_module_get(THIS_MODULE)) + return -ENODEV; + ret = single_open(file, vtunerc_read_proc, ctx); + if (ret) + module_put(THIS_MODULE); + return ret; +} - /* signal EOF */ - *eof = 1; +static int vtuner_proc_release(struct inode *inode, struct file *file) +{ + int ret = single_release(inode, file); + module_put(THIS_MODULE); + return ret; +} - return blen; +static const struct file_operations vtunerc_read_proc_fops = { + .open = vtunerc_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = vtuner_proc_release, + }; -} #endif static char *my_strdup(const char *s) @@ -346,8 +336,8 @@ static int __init vtunerc_init(void) sprintf(procfilename, VTUNERC_PROC_FILENAME, ctx->idx); ctx->procname = my_strdup(procfilename); - if (create_proc_read_entry(ctx->procname, 0, NULL, - vtunerc_read_proc, + if (proc_create_data(ctx->procname, 0, NULL, + &vtunerc_read_proc_fops, ctx) == 0) printk(KERN_WARNING "vtunerc%d: Unable to register '%s' proc file\n", -- 2.36.1