summarylogtreecommitdiffstats
path: root/kernel-3.10.patch
blob: cfbe3e52b1351faf5c620a1838c549c0419bf0af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
https://lore.kernel.org/patchwork/cover/372524
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=3cb5bf1bf947d325fcf6e9458952b51cfd7e6677
--- a/vtunerc_main.c
+++ b/vtunerc_main.c
@@ -22,6 +22,7 @@
 #include <linux/i2c.h>
 #include <asm/uaccess.h>
 #include <linux/delay.h>
+#include <linux/seq_file.h>

 #include "demux.h"
 #include "dmxdev.h"
@@ -176,64 +177,53 @@ static char *get_fe_name(struct dvb_frontend_info *feinfo)
 	return (feinfo && feinfo->name) ? feinfo->name : "(not set)";
 }

-/**
- * @brief  procfs file handler
- * @param  buffer:
- * @param  start:
- * @param  offset:
- * @param  size:
- * @param  eof:
- * @param  data:
- * @return =0: success <br/>
- *         <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",
--- a/vtunerc_priv.h
+++ b/vtunerc_priv.h
@@ -20,6 +20,7 @@
 #include <linux/module.h>	/* Specifically, a module */
 #include <linux/kernel.h>	/* We're doing kernel work */
 #include <linux/cdev.h>
+#include <linux/version.h>

 #include "demux.h"
 #include "dmxdev.h"
@@ -108,4 +109,12 @@ if (ctx->config && (ctx->config->debug))				\
 	printk(KERN_DEBUG "vtunerc%d: " fmt, ctx->idx, ##arg);	\
 } while (0)

+/* backward compatibility stuff */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
+static inline void *PDE_DATA(const struct inode *inode)
+{
+	return PROC_I(inode)->pde->data;
+}
+#endif
+
 #endif