diff options
author | David Howells <dhowells@redhat.com> | 2013-04-04 11:32:28 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2013-04-09 15:16:50 -0400 |
commit | ad147d011f4e9d4e4309f7974fd19c7f875ccb14 (patch) | |
tree | 97b2b327e036c0001e6a597da1f7802a226f1453 /fs/proc | |
parent | f805442e130c6eeb6c25bc5c3b3cefc27ab6dcec (diff) |
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: David Howells <dhowells@redhat.com>
Diffstat (limited to 'fs/proc')
-rw-r--r-- | fs/proc/generic.c | 98 |
1 files changed, 47 insertions, 51 deletions
diff --git a/fs/proc/generic.c b/fs/proc/generic.c index 5453f1c0b70c..a6a1cb5d589d 100644 --- a/fs/proc/generic.c +++ b/fs/proc/generic.c | |||
@@ -71,59 +71,55 @@ __proc_file_read(struct file *file, char __user *buf, size_t nbytes, | |||
71 | count = min_t(size_t, PROC_BLOCK_SIZE, nbytes); | 71 | count = min_t(size_t, PROC_BLOCK_SIZE, nbytes); |
72 | 72 | ||
73 | start = NULL; | 73 | start = NULL; |
74 | if (dp->read_proc) { | 74 | if (!dp->read_proc) |
75 | /* | ||
76 | * How to be a proc read function | ||
77 | * ------------------------------ | ||
78 | * Prototype: | ||
79 | * int f(char *buffer, char **start, off_t offset, | ||
80 | * int count, int *peof, void *dat) | ||
81 | * | ||
82 | * Assume that the buffer is "count" bytes in size. | ||
83 | * | ||
84 | * If you know you have supplied all the data you | ||
85 | * have, set *peof. | ||
86 | * | ||
87 | * You have three ways to return data: | ||
88 | * 0) Leave *start = NULL. (This is the default.) | ||
89 | * Put the data of the requested offset at that | ||
90 | * offset within the buffer. Return the number (n) | ||
91 | * of bytes there are from the beginning of the | ||
92 | * buffer up to the last byte of data. If the | ||
93 | * number of supplied bytes (= n - offset) is | ||
94 | * greater than zero and you didn't signal eof | ||
95 | * and the reader is prepared to take more data | ||
96 | * you will be called again with the requested | ||
97 | * offset advanced by the number of bytes | ||
98 | * absorbed. This interface is useful for files | ||
99 | * no larger than the buffer. | ||
100 | * 1) Set *start = an unsigned long value less than | ||
101 | * the buffer address but greater than zero. | ||
102 | * Put the data of the requested offset at the | ||
103 | * beginning of the buffer. Return the number of | ||
104 | * bytes of data placed there. If this number is | ||
105 | * greater than zero and you didn't signal eof | ||
106 | * and the reader is prepared to take more data | ||
107 | * you will be called again with the requested | ||
108 | * offset advanced by *start. This interface is | ||
109 | * useful when you have a large file consisting | ||
110 | * of a series of blocks which you want to count | ||
111 | * and return as wholes. | ||
112 | * (Hack by Paul.Russell@rustcorp.com.au) | ||
113 | * 2) Set *start = an address within the buffer. | ||
114 | * Put the data of the requested offset at *start. | ||
115 | * Return the number of bytes of data placed there. | ||
116 | * If this number is greater than zero and you | ||
117 | * didn't signal eof and the reader is prepared to | ||
118 | * take more data you will be called again with the | ||
119 | * requested offset advanced by the number of bytes | ||
120 | * absorbed. | ||
121 | */ | ||
122 | n = dp->read_proc(page, &start, *ppos, | ||
123 | count, &eof, dp->data); | ||
124 | } else | ||
125 | break; | 75 | break; |
126 | 76 | ||
77 | /* How to be a proc read function | ||
78 | * ------------------------------ | ||
79 | * Prototype: | ||
80 | * int f(char *buffer, char **start, off_t offset, | ||
81 | * int count, int *peof, void *dat) | ||
82 | * | ||
83 | * Assume that the buffer is "count" bytes in size. | ||
84 | * | ||
85 | * If you know you have supplied all the data you have, set | ||
86 | * *peof. | ||
87 | * | ||
88 | * You have three ways to return data: | ||
89 | * | ||
90 | * 0) Leave *start = NULL. (This is the default.) Put the | ||
91 | * data of the requested offset at that offset within the | ||
92 | * buffer. Return the number (n) of bytes there are from | ||
93 | * the beginning of the buffer up to the last byte of data. | ||
94 | * If the number of supplied bytes (= n - offset) is greater | ||
95 | * than zero and you didn't signal eof and the reader is | ||
96 | * prepared to take more data you will be called again with | ||
97 | * the requested offset advanced by the number of bytes | ||
98 | * absorbed. This interface is useful for files no larger | ||
99 | * than the buffer. | ||
100 | * | ||
101 | * 1) Set *start = an unsigned long value less than the buffer | ||
102 | * address but greater than zero. Put the data of the | ||
103 | * requested offset at the beginning of the buffer. Return | ||
104 | * the number of bytes of data placed there. If this number | ||
105 | * is greater than zero and you didn't signal eof and the | ||
106 | * reader is prepared to take more data you will be called | ||
107 | * again with the requested offset advanced by *start. This | ||
108 | * interface is useful when you have a large file consisting | ||
109 | * of a series of blocks which you want to count and return | ||
110 | * as wholes. | ||
111 | * (Hack by Paul.Russell@rustcorp.com.au) | ||
112 | * | ||
113 | * 2) Set *start = an address within the buffer. Put the data | ||
114 | * of the requested offset at *start. Return the number of | ||
115 | * bytes of data placed there. If this number is greater | ||
116 | * than zero and you didn't signal eof and the reader is | ||
117 | * prepared to take more data you will be called again with | ||
118 | * the requested offset advanced by the number of bytes | ||
119 | * absorbed. | ||
120 | */ | ||
121 | n = dp->read_proc(page, &start, *ppos, count, &eof, dp->data); | ||
122 | |||
127 | if (n == 0) /* end of file */ | 123 | if (n == 0) /* end of file */ |
128 | break; | 124 | break; |
129 | if (n < 0) { /* error */ | 125 | if (n < 0) { /* error */ |