Commit ad147d01 authored by David Howells's avatar David Howells Committed by Al Viro

procfs: Clean up huge if-statement in __proc_file_read()

Switch huge if-statement in __proc_file_read() around.  This then puts the
single line loop break immediately after the if-statement and allows us to
de-indent the huge comment and make it take fewer lines.  The code following
the if-statement then follows naturally from the call to dp->read_proc().
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
parent f805442e
...@@ -71,9 +71,10 @@ __proc_file_read(struct file *file, char __user *buf, size_t nbytes, ...@@ -71,9 +71,10 @@ __proc_file_read(struct file *file, char __user *buf, size_t nbytes,
count = min_t(size_t, PROC_BLOCK_SIZE, nbytes); count = min_t(size_t, PROC_BLOCK_SIZE, nbytes);
start = NULL; start = NULL;
if (dp->read_proc) { if (!dp->read_proc)
/* break;
* How to be a proc read function
/* How to be a proc read function
* ------------------------------ * ------------------------------
* Prototype: * Prototype:
* int f(char *buffer, char **start, off_t offset, * int f(char *buffer, char **start, off_t offset,
...@@ -81,48 +82,43 @@ __proc_file_read(struct file *file, char __user *buf, size_t nbytes, ...@@ -81,48 +82,43 @@ __proc_file_read(struct file *file, char __user *buf, size_t nbytes,
* *
* Assume that the buffer is "count" bytes in size. * Assume that the buffer is "count" bytes in size.
* *
* If you know you have supplied all the data you * If you know you have supplied all the data you have, set
* have, set *peof. * *peof.
* *
* You have three ways to return data: * You have three ways to return data:
* 0) Leave *start = NULL. (This is the default.) *
* Put the data of the requested offset at that * 0) Leave *start = NULL. (This is the default.) Put the
* offset within the buffer. Return the number (n) * data of the requested offset at that offset within the
* of bytes there are from the beginning of the * buffer. Return the number (n) of bytes there are from
* buffer up to the last byte of data. If the * the beginning of the buffer up to the last byte of data.
* number of supplied bytes (= n - offset) is * If the number of supplied bytes (= n - offset) is greater
* greater than zero and you didn't signal eof * than zero and you didn't signal eof and the reader is
* and the reader is prepared to take more data * prepared to take more data you will be called again with
* you will be called again with the requested * the requested offset advanced by the number of bytes
* offset advanced by the number of bytes * absorbed. This interface is useful for files no larger
* absorbed. This interface is useful for files * than the buffer.
* no larger than the buffer. *
* 1) Set *start = an unsigned long value less than * 1) Set *start = an unsigned long value less than the buffer
* the buffer address but greater than zero. * address but greater than zero. Put the data of the
* Put the data of the requested offset at the * requested offset at the beginning of the buffer. Return
* beginning of the buffer. Return the number of * the number of bytes of data placed there. If this number
* bytes of data placed there. If this number is * is greater than zero and you didn't signal eof and the
* greater than zero and you didn't signal eof * reader is prepared to take more data you will be called
* and the reader is prepared to take more data * again with the requested offset advanced by *start. This
* you will be called again with the requested * interface is useful when you have a large file consisting
* offset advanced by *start. This interface is * of a series of blocks which you want to count and return
* useful when you have a large file consisting * as wholes.
* of a series of blocks which you want to count
* and return as wholes.
* (Hack by Paul.Russell@rustcorp.com.au) * (Hack by Paul.Russell@rustcorp.com.au)
* 2) Set *start = an address within the buffer. *
* Put the data of the requested offset at *start. * 2) Set *start = an address within the buffer. Put the data
* Return the number of bytes of data placed there. * of the requested offset at *start. Return the number of
* If this number is greater than zero and you * bytes of data placed there. If this number is greater
* didn't signal eof and the reader is prepared to * than zero and you didn't signal eof and the reader is
* take more data you will be called again with the * prepared to take more data you will be called again with
* requested offset advanced by the number of bytes * the requested offset advanced by the number of bytes
* absorbed. * absorbed.
*/ */
n = dp->read_proc(page, &start, *ppos, n = dp->read_proc(page, &start, *ppos, count, &eof, dp->data);
count, &eof, dp->data);
} else
break;
if (n == 0) /* end of file */ if (n == 0) /* end of file */
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment