Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

MIPS: Lasat: Convert to proc_fops / seq_file

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Cc: akpm@linux-foundation.org
Cc: linux-mips@linux-mips.org
Patchwork: http://patchwork.linux-mips.org/patch/725/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

authored by

Alexey Dobriyan and committed by
Ralf Baechle
c0b4abdd 137f6f3e

+68 -45
+68 -45
arch/mips/lasat/picvue_proc.c
··· 4 4 * Brian Murphy <brian.murphy@eicon.com> 5 5 * 6 6 */ 7 + #include <linux/bug.h> 7 8 #include <linux/kernel.h> 8 9 #include <linux/module.h> 9 10 #include <linux/init.h> 10 11 #include <linux/errno.h> 11 12 12 13 #include <linux/proc_fs.h> 14 + #include <linux/seq_file.h> 13 15 #include <linux/interrupt.h> 14 16 15 17 #include <linux/timer.h> ··· 40 38 41 39 static DECLARE_TASKLET(pvc_display_tasklet, &pvc_display, 0); 42 40 43 - static int pvc_proc_read_line(char *page, char **start, 44 - off_t off, int count, 45 - int *eof, void *data) 41 + static int pvc_line_proc_show(struct seq_file *m, void *v) 46 42 { 47 - char *origpage = page; 48 - int lineno = *(int *)data; 43 + int lineno = *(int *)m->private; 49 44 50 45 if (lineno < 0 || lineno > PVC_NLINES) { 51 46 printk(KERN_WARNING "proc_read_line: invalid lineno %d\n", lineno); ··· 50 51 } 51 52 52 53 mutex_lock(&pvc_mutex); 53 - page += sprintf(page, "%s\n", pvc_lines[lineno]); 54 + seq_printf(m, "%s\n", pvc_lines[lineno]); 54 55 mutex_unlock(&pvc_mutex); 55 56 56 - return page - origpage; 57 + return 0; 57 58 } 58 59 59 - static int pvc_proc_write_line(struct file *file, const char *buffer, 60 - unsigned long count, void *data) 60 + static int pvc_line_proc_open(struct inode *inode, struct file *file) 61 61 { 62 - int origcount = count; 63 - int lineno = *(int *)data; 62 + return single_open(file, pvc_line_proc_show, PDE(inode)->data); 63 + } 64 64 65 - if (lineno < 0 || lineno > PVC_NLINES) { 66 - printk(KERN_WARNING "proc_write_line: invalid lineno %d\n", 67 - lineno); 68 - return origcount; 69 - } 65 + static ssize_t pvc_line_proc_write(struct file *file, const char __user *buf, 66 + size_t count, loff_t *pos) 67 + { 68 + int lineno = *(int *)PDE(file->f_path.dentry->d_inode)->data; 69 + char kbuf[PVC_LINELEN]; 70 + size_t len; 70 71 71 - if (count > PVC_LINELEN) 72 - count = PVC_LINELEN; 72 + BUG_ON(lineno < 0 || lineno > PVC_NLINES); 73 73 74 - if (buffer[count-1] == '\n') 75 - count--; 74 + len = min(count, sizeof(kbuf) - 1); 75 + if (copy_from_user(kbuf, buf, len)) 76 + return -EFAULT; 77 + kbuf[len] = '\0'; 78 + 79 + if (len > 0 && kbuf[len - 1] == '\n') 80 + len--; 76 81 77 82 mutex_lock(&pvc_mutex); 78 - strncpy(pvc_lines[lineno], buffer, count); 79 - pvc_lines[lineno][count] = '\0'; 83 + strncpy(pvc_lines[lineno], kbuf, len); 84 + pvc_lines[lineno][len] = '\0'; 80 85 mutex_unlock(&pvc_mutex); 81 86 82 87 tasklet_schedule(&pvc_display_tasklet); 83 88 84 - return origcount; 89 + return count; 85 90 } 86 91 87 - static int pvc_proc_write_scroll(struct file *file, const char *buffer, 88 - unsigned long count, void *data) 92 + static const struct file_operations pvc_line_proc_fops = { 93 + .owner = THIS_MODULE, 94 + .open = pvc_line_proc_open, 95 + .read = seq_read, 96 + .llseek = seq_lseek, 97 + .release = single_release, 98 + .write = pvc_line_proc_write, 99 + }; 100 + 101 + static ssize_t pvc_scroll_proc_write(struct file *file, const char __user *buf, 102 + size_t count, loff_t *pos) 89 103 { 90 - int origcount = count; 91 - int cmd = simple_strtol(buffer, NULL, 10); 104 + char kbuf[42]; 105 + size_t len; 106 + int cmd; 107 + 108 + len = min(count, sizeof(kbuf) - 1); 109 + if (copy_from_user(kbuf, buf, len)) 110 + return -EFAULT; 111 + kbuf[len] = '\0'; 112 + 113 + cmd = simple_strtol(kbuf, NULL, 10); 92 114 93 115 mutex_lock(&pvc_mutex); 94 116 if (scroll_interval != 0) ··· 130 110 } 131 111 mutex_unlock(&pvc_mutex); 132 112 133 - return origcount; 113 + return count; 134 114 } 135 115 136 - static int pvc_proc_read_scroll(char *page, char **start, 137 - off_t off, int count, 138 - int *eof, void *data) 116 + static int pvc_scroll_proc_show(struct seq_file *m, void *v) 139 117 { 140 - char *origpage = page; 141 - 142 118 mutex_lock(&pvc_mutex); 143 - page += sprintf(page, "%d\n", scroll_dir * scroll_interval); 119 + seq_printf(m, "%d\n", scroll_dir * scroll_interval); 144 120 mutex_unlock(&pvc_mutex); 145 121 146 - return page - origpage; 122 + return 0; 147 123 } 148 124 125 + static int pvc_scroll_proc_open(struct inode *inode, struct file *file) 126 + { 127 + return single_open(file, pvc_scroll_proc_show, NULL); 128 + } 129 + 130 + static const struct file_operations pvc_scroll_proc_fops = { 131 + .owner = THIS_MODULE, 132 + .open = pvc_scroll_proc_open, 133 + .read = seq_read, 134 + .llseek = seq_lseek, 135 + .release = single_release, 136 + .write = pvc_scroll_proc_write, 137 + }; 149 138 150 139 void pvc_proc_timerfunc(unsigned long data) 151 140 { ··· 192 163 pvc_linedata[i] = i; 193 164 } 194 165 for (i = 0; i < PVC_NLINES; i++) { 195 - proc_entry = create_proc_entry(pvc_linename[i], 0644, 196 - pvc_display_dir); 166 + proc_entry = proc_create_data(pvc_linename[i], 0644, pvc_display_dir, 167 + &pvc_line_proc_fops, &pvc_linedata[i]); 197 168 if (proc_entry == NULL) 198 169 goto error; 199 - 200 - proc_entry->read_proc = pvc_proc_read_line; 201 - proc_entry->write_proc = pvc_proc_write_line; 202 - proc_entry->data = &pvc_linedata[i]; 203 170 } 204 - proc_entry = create_proc_entry("scroll", 0644, pvc_display_dir); 171 + proc_entry = proc_create("scroll", 0644, pvc_display_dir, 172 + &pvc_scroll_proc_fops); 205 173 if (proc_entry == NULL) 206 174 goto error; 207 - 208 - proc_entry->write_proc = pvc_proc_write_scroll; 209 - proc_entry->read_proc = pvc_proc_read_scroll; 210 175 211 176 init_timer(&timer); 212 177 timer.function = pvc_proc_timerfunc;