Received: from milmhbs1.lsil.com (147.145.21.209) by coscas01.lsi.com
 (172.21.36.60) with Microsoft SMTP Server id 8.1.393.1; Thu, 26 Nov 2009
 23:56:00 -0700
Received: from mail1.lsil.com (mail1.lsil.com [147.145.40.21])	by
 milmhbs1.lsil.com (8.12.11/8.12.11) with ESMTP id nAR6twef031978	for
 <andy.sharp@lsi.com>; Thu, 26 Nov 2009 22:56:00 -0800
Received: from psmtp.com (na3sys009amx212.postini.com [74.125.149.52])	by
 mail1.lsil.com (8.12.11/8.12.11) with SMTP id nAR6tnED005473	for
 <andy.sharp@lsi.com>; Thu, 26 Nov 2009 22:55:56 -0800 (PST)
Received: from source ([78.24.191.182]) by na3sys009amx212.postini.com
 ([74.125.148.14]) with SMTP;	Thu, 26 Nov 2009 22:55:57 PST
Received: from localhost.localdomain ([127.0.0.1]:38642 "EHLO
        eddie.linux-mips.org" rhost-flags-OK-OK-OK-FAIL)        by
 eddie.linux-mips.org with ESMTP id S1491926AbZK0Gzd (ORCPT
        <rfc822;andy.sharp@lsi.com>); Fri, 27 Nov 2009 07:55:33 +0100
Received: with ECARTIS (v1.0.0; list linux-mips); Fri, 27 Nov 2009 07:55:15
 +0100 (CET)
Received: from mail-ew0-f223.google.com ([209.85.219.223]:49360 "EHLO
        mail-ew0-f223.google.com" rhost-flags-OK-OK-OK-OK)        by
 eddie.linux-mips.org with ESMTP id S1491944AbZK0GzM (ORCPT
        <rfc822;linux-mips@linux-mips.org>); Fri, 27 Nov 2009 07:55:12 +0100
Received: by ewy23 with SMTP id 23so1451047ewy.24        for <multiple
 recipients>; Thu, 26 Nov 2009 22:55:05 -0800 (PST)
Received: by 10.213.100.161 with SMTP id y33mr791889ebn.2.1259304905149;
        Thu, 26 Nov 2009 22:55:05 -0800 (PST)
Received: from x200.malnet.ru ([213.171.34.231])        by mx.google.com with
 ESMTPS id 28sm778695eye.3.2009.11.26.22.55.04        (version=TLSv1/SSLv3
 cipher=RC4-MD5);        Thu, 26 Nov 2009 22:55:04 -0800 (PST)
From: Alexey Dobriyan <adobriyan@gmail.com>
To: "ralf@linux-mips.org" <ralf@linux-mips.org>
CC: "akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"linux-mips@linux-mips.org" <linux-mips@linux-mips.org>
Sender: "linux-mips-bounce@linux-mips.org" <linux-mips-bounce@linux-mips.org>
Date: Thu, 26 Nov 2009 23:55:03 -0700
Subject: [PATCH] mips lasat: convert to proc_fops/seq_file
Thread-Topic: [PATCH] mips lasat: convert to proc_fops/seq_file
Thread-Index: AcpvLq3rLpgtUhBETR+fGvLBTKFqIQ==
Message-ID: <20091127065502.GE26327@x200.malnet.ru>
Accept-Language: en-US
Content-Language: en-US
X-MS-Exchange-Organization-AuthAs: Anonymous
X-MS-Exchange-Organization-AuthSource: coscas01.lsi.com
X-MS-Has-Attach:
X-Auto-Response-Suppress: All
X-MS-TNEF-Correlator:
x-scanned-by: MIMEDefang 2.39
errors-to: linux-mips-bounce@linux-mips.org
x-pstn-levels: (S:76.34060/99.90000 CV:99.9000 FC:95.5390 LC:95.5390
 R:95.9108 P:95.9108 M:97.0282 C:98.6951 )
x-pstn-settings: 3 (1.0000:1.0000) s cv gt3 gt2 gt1 r p m c 
x-pstn-addresses: from <adobriyan@gmail.com> [22/1] 
x-pstn-neptune: 1/1/1.00/76
domainkey-signature: a=rsa-sha1; c=nofws;        d=gmail.com; s=gamma;
        h=date:from:to:cc:subject:message-id:mime-version:content-type
         :content-disposition:user-agent;
        b=pRxvAVDgvy/aQc3prQcFpH/ol56cfzqDnEcECCp2fBFM58ILjRtKvwI8RLLw/DjeyJ
         ut3ZAK7hfhhoyoB5lVSEDLaXtW1QPhtqkyjfpGq4YI4qNdzcSkd7YjGKfHTisVLNk5Lm
         Cw9I94p+tLihm3tzABXuJOLWTsGmftaLwgMV0=
dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed;        d=gmail.com;
 s=gamma;
        h=domainkey-signature:received:received:date:from:to:cc:subject
         :message-id:mime-version:content-type:content-disposition:user-agent;
        bh=ch7RgbAWX+BlFXw2IGnDKO7wu72PvcxCIJ8kaIJBY5w=;
        b=Pzg2n1iZi0lbp3mqbODdVwMjAhxeLml8OEAgkgAAOkCS1u7m06StYEzyQCp0YTlgiH
         w726N3lK6naVP0yTpWlraWCv5dV0UneL3lY2t1f8olSt+0Vfi0zjhTn7ZMcK9T2/gKcw
         0kNsU4zWdIW52ctcJL5ctsFhBekSL7IgLeo14=
user-agent: Mutt/1.5.20 (2009-06-14)
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 arch/mips/lasat/picvue_proc.c |  106 ++++++++++++++++++++++++++-----------=
-----
 1 file changed, 66 insertions(+), 40 deletions(-)

--- a/arch/mips/lasat/picvue_proc.c
+++ b/arch/mips/lasat/picvue_proc.c
@@ -10,6 +10,7 @@
 #include <linux/errno.h>
=20
 #include <linux/proc_fs.h>
+#include <linux/seq_file.h>
 #include <linux/interrupt.h>
=20
 #include <linux/timer.h>
@@ -38,12 +39,9 @@ static void pvc_display(unsigned long data)
=20
 static DECLARE_TASKLET(pvc_display_tasklet, &pvc_display, 0);
=20
-static int pvc_proc_read_line(char *page, char **start,
-			     off_t off, int count,
-			     int *eof, void *data)
+static int pvc_line_proc_show(struct seq_file *m, void *v)
 {
-	char *origpage =3D page;
-	int lineno =3D *(int *)data;
+	int lineno =3D *(int *)m->private;
=20
 	if (lineno < 0 || lineno > PVC_NLINES) {
 		printk(KERN_WARNING "proc_read_line: invalid lineno %d\n", lineno);
@@ -51,17 +49,23 @@ static int pvc_proc_read_line(char *page, char **start,
 	}
=20
 	mutex_lock(&pvc_mutex);
-	page +=3D sprintf(page, "%s\n", pvc_lines[lineno]);
+	seq_printf(m, "%s\n", pvc_lines[lineno]);
 	mutex_unlock(&pvc_mutex);
=20
-	return page - origpage;
+	return 0;
+}
+
+static int pvc_line_proc_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, pvc_line_proc_show, PDE(inode)->data);
 }
=20
-static int pvc_proc_write_line(struct file *file, const char *buffer,
-			   unsigned long count, void *data)
+static ssize_t pvc_line_proc_write(struct file *file, const char __user *b=
uf,
+				   size_t count, loff_t *pos)
 {
-	int origcount =3D count;
-	int lineno =3D *(int *)data;
+	int lineno =3D *(int *)PDE(file->f_path.dentry->d_inode)->data;
+	char kbuf[PVC_LINELEN];
+	size_t len;
=20
 	if (lineno < 0 || lineno > PVC_NLINES) {
 		printk(KERN_WARNING "proc_write_line: invalid lineno %d\n",
@@ -69,27 +73,46 @@ static int pvc_proc_write_line(struct file *file, const=
 char *buffer,
 		return origcount;
 	}
=20
-	if (count > PVC_LINELEN)
-		count =3D PVC_LINELEN;
+	len =3D min(count, sizeof(kbuf) - 1);
+	if (copy_from_user(kbuf, buf, len))
+		return -EFAULT;
+	kbuf[len] =3D '\0';
=20
-	if (buffer[count-1] =3D=3D '\n')
-		count--;
+	if (len > 0 && kbuf[len - 1] =3D=3D '\n')
+		len--;
=20
 	mutex_lock(&pvc_mutex);
-	strncpy(pvc_lines[lineno], buffer, count);
-	pvc_lines[lineno][count] =3D '\0';
+	strncpy(pvc_lines[lineno], kbuf, len);
+	pvc_lines[lineno][len] =3D '\0';
 	mutex_unlock(&pvc_mutex);
=20
 	tasklet_schedule(&pvc_display_tasklet);
=20
-	return origcount;
+	return count;
 }
=20
-static int pvc_proc_write_scroll(struct file *file, const char *buffer,
-			   unsigned long count, void *data)
+static const struct file_operations pvc_line_proc_fops =3D {
+	.owner		=3D THIS_MODULE,
+	.open		=3D pvc_line_proc_open,
+	.read		=3D seq_read,
+	.llseek		=3D seq_lseek,
+	.release	=3D single_release,
+	.write		=3D pvc_line_proc_write,
+};
+
+static ssize_t pvc_scroll_proc_write(struct file *file, const char __user =
*buf,
+				     size_t count, loff_t *pos)
 {
-	int origcount =3D count;
-	int cmd =3D simple_strtol(buffer, NULL, 10);
+	char kbuf[42];
+	size_t len;
+	int cmd;
+
+	len =3D min(count, sizeof(kbuf) - 1);
+	if (copy_from_user(kbuf, buf, len))
+		return -EFAULT;
+	kbuf[len] =3D '\0';
+
+	cmd =3D simple_strtol(kbuf, NULL, 10);
=20
 	mutex_lock(&pvc_mutex);
 	if (scroll_interval !=3D 0)
@@ -110,22 +133,31 @@ static int pvc_proc_write_scroll(struct file *file, c=
onst char *buffer,
 	}
 	mutex_unlock(&pvc_mutex);
=20
-	return origcount;
+	return count;
 }
=20
-static int pvc_proc_read_scroll(char *page, char **start,
-			     off_t off, int count,
-			     int *eof, void *data)
+static int pvc_scroll_proc_show(struct seq_file *m, void *v)
 {
-	char *origpage =3D page;
-
 	mutex_lock(&pvc_mutex);
-	page +=3D sprintf(page, "%d\n", scroll_dir * scroll_interval);
+	seq_printf(m, "%d\n", scroll_dir * scroll_interval);
 	mutex_unlock(&pvc_mutex);
=20
-	return page - origpage;
+	return 0;
+}
+
+static int pvc_scroll_proc_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, pvc_scroll_proc_show, NULL);
 }
=20
+static const struct file_operations pvc_scroll_proc_fops =3D {
+	.owner		=3D THIS_MODULE,
+	.open		=3D pvc_scroll_proc_open,
+	.read		=3D seq_read,
+	.llseek		=3D seq_lseek,
+	.release	=3D single_release,
+	.write		=3D pvc_scroll_proc_write,
+};
=20
 void pvc_proc_timerfunc(unsigned long data)
 {
@@ -163,22 +195,16 @@ static int __init pvc_proc_init(void)
 		pvc_linedata[i] =3D i;
 	}
 	for (i =3D 0; i < PVC_NLINES; i++) {
-		proc_entry =3D create_proc_entry(pvc_linename[i], 0644,
-					       pvc_display_dir);
+		proc_entry =3D proc_create_data(pvc_linename[i], 0644, pvc_display_dir,
+					&pvc_line_proc_fops, &pvc_linedata[i]);
 		if (proc_entry =3D=3D NULL)
 			goto error;
-
-		proc_entry->read_proc =3D pvc_proc_read_line;
-		proc_entry->write_proc =3D pvc_proc_write_line;
-		proc_entry->data =3D &pvc_linedata[i];
 	}
-	proc_entry =3D create_proc_entry("scroll", 0644, pvc_display_dir);
+	proc_entry =3D proc_create("scroll", 0644, pvc_display_dir,
+				 &pvc_scroll_proc_fops);
 	if (proc_entry =3D=3D NULL)
 		goto error;
=20
-	proc_entry->write_proc =3D pvc_proc_write_scroll;
-	proc_entry->read_proc =3D pvc_proc_read_scroll;
-
 	init_timer(&timer);
 	timer.function =3D pvc_proc_timerfunc;
=20

