From daeb43133eeb489512dcc38ea4aef651a4bd2898 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Tue, 4 Jan 2011 02:34:35 +0100 Subject: tty: tiny_tty: Use seq_file instead read_proc --- tty/tiny_tty.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/tty/tiny_tty.c b/tty/tiny_tty.c index 966104d..456423d 100644 --- a/tty/tiny_tty.c +++ b/tty/tiny_tty.c @@ -23,6 +23,7 @@ #include #include #include +#include #include @@ -354,34 +355,21 @@ static int tiny_tiocmset(struct tty_struct *tty, struct file *file, return 0; } -static int tiny_read_proc(char *page, char **start, off_t off, int count, - int *eof, void *data) +static int tiny_proc_show(struct seq_file *m, void *v) { struct tiny_serial *tiny; - off_t begin = 0; - int length = 0; int i; - length += sprintf(page, "tinyserinfo:1.0 driver:%s\n", DRIVER_VERSION); - for (i = 0; i < TINY_TTY_MINORS && length < PAGE_SIZE; ++i) { + seq_printf(m, "tinyserinfo:1.0 driver:%s\n", DRIVER_VERSION); + for (i = 0; i < TINY_TTY_MINORS; ++i) { tiny = tiny_table[i]; if (tiny == NULL) continue; - length += sprintf(page+length, "%d\n", i); - if ((length + begin) > (off + count)) - goto done; - if ((length + begin) < off) { - begin += length; - length = 0; - } + seq_printf(m, "%d\n", i); } - *eof = 1; -done: - if (off >= (length + begin)) - return 0; - *start = page + (off-begin); - return (count < begin+length-off) ? count : begin + length-off; + + return 0; } #define tiny_ioctl tiny_ioctl_tiocgserial @@ -505,9 +493,18 @@ static int tiny_ioctl(struct tty_struct *tty, struct file *file, return -ENOIOCTLCMD; } +static int tiny_proc_open(struct inode *inode, struct file *file) +{ + return single_open(file, tiny_proc_show, NULL); +} + + static const struct file_operations serial_proc_fops = { .owner = THIS_MODULE, - .read = tiny_read_proc, + .open = tiny_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, }; static struct tty_operations serial_ops = { @@ -516,9 +513,7 @@ static struct tty_operations serial_ops = { .write = tiny_write, .write_room = tiny_write_room, .set_termios = tiny_set_termios, -#ifdef CONFIG_PROC_FS .proc_fops = &serial_proc_fops, -#endif .tiocmget = tiny_tiocmget, .tiocmset = tiny_tiocmset, .ioctl = tiny_ioctl, -- cgit v1.2.1-18-gbd029