aboutsummaryrefslogtreecommitdiffstats
path: root/net/x25
diff options
context:
space:
mode:
authorLi Zefan <lizf@cn.fujitsu.com>2010-02-08 18:20:42 -0500
committerDavid S. Miller <davem@davemloft.net>2010-02-10 14:12:10 -0500
commit4f134204f740d9fbf992843a6615175f5105f49e (patch)
treea70badf71b7d5b27a7cf28b20b24b8146e10694a /net/x25
parent27b5b8657a2aa761f76e45fa60c20b7bafc249dc (diff)
net: x25: use seq_list_foo() helpers
Simplify seq_file code. Signed-off-by: Li Zefan <lizf@cn.fujitsu.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/x25')
-rw-r--r--net/x25/x25_proc.c84
1 files changed, 8 insertions, 76 deletions
diff --git a/net/x25/x25_proc.c b/net/x25/x25_proc.c
index c4cd3226a053..7ff373792324 100644
--- a/net/x25/x25_proc.c
+++ b/net/x25/x25_proc.c
@@ -25,49 +25,17 @@
25#include <net/x25.h> 25#include <net/x25.h>
26 26
27#ifdef CONFIG_PROC_FS 27#ifdef CONFIG_PROC_FS
28static __inline__ struct x25_route *x25_get_route_idx(loff_t pos)
29{
30 struct list_head *route_entry;
31 struct x25_route *rt = NULL;
32
33 list_for_each(route_entry, &x25_route_list) {
34 rt = list_entry(route_entry, struct x25_route, node);
35 if (!pos--)
36 goto found;
37 }
38 rt = NULL;
39found:
40 return rt;
41}
42 28
43static void *x25_seq_route_start(struct seq_file *seq, loff_t *pos) 29static void *x25_seq_route_start(struct seq_file *seq, loff_t *pos)
44 __acquires(x25_route_list_lock) 30 __acquires(x25_route_list_lock)
45{ 31{
46 loff_t l = *pos;
47
48 read_lock_bh(&x25_route_list_lock); 32 read_lock_bh(&x25_route_list_lock);
49 return l ? x25_get_route_idx(--l) : SEQ_START_TOKEN; 33 return seq_list_start_head(&x25_route_list, *pos);
50} 34}
51 35
52static void *x25_seq_route_next(struct seq_file *seq, void *v, loff_t *pos) 36static void *x25_seq_route_next(struct seq_file *seq, void *v, loff_t *pos)
53{ 37{
54 struct x25_route *rt; 38 return seq_list_next(v, &x25_route_list, pos);
55
56 ++*pos;
57 if (v == SEQ_START_TOKEN) {
58 rt = NULL;
59 if (!list_empty(&x25_route_list))
60 rt = list_entry(x25_route_list.next,
61 struct x25_route, node);
62 goto out;
63 }
64 rt = v;
65 if (rt->node.next != &x25_route_list)
66 rt = list_entry(rt->node.next, struct x25_route, node);
67 else
68 rt = NULL;
69out:
70 return rt;
71} 39}
72 40
73static void x25_seq_route_stop(struct seq_file *seq, void *v) 41static void x25_seq_route_stop(struct seq_file *seq, void *v)
@@ -78,9 +46,9 @@ static void x25_seq_route_stop(struct seq_file *seq, void *v)
78 46
79static int x25_seq_route_show(struct seq_file *seq, void *v) 47static int x25_seq_route_show(struct seq_file *seq, void *v)
80{ 48{
81 struct x25_route *rt; 49 struct x25_route *rt = list_entry(v, struct x25_route, node);
82 50
83 if (v == SEQ_START_TOKEN) { 51 if (v == &x25_route_list) {
84 seq_puts(seq, "Address Digits Device\n"); 52 seq_puts(seq, "Address Digits Device\n");
85 goto out; 53 goto out;
86 } 54 }
@@ -146,51 +114,16 @@ out:
146 return 0; 114 return 0;
147} 115}
148 116
149static __inline__ struct x25_forward *x25_get_forward_idx(loff_t pos)
150{
151 struct x25_forward *f;
152 struct list_head *entry;
153
154 list_for_each(entry, &x25_forward_list) {
155 f = list_entry(entry, struct x25_forward, node);
156 if (!pos--)
157 goto found;
158 }
159
160 f = NULL;
161found:
162 return f;
163}
164
165static void *x25_seq_forward_start(struct seq_file *seq, loff_t *pos) 117static void *x25_seq_forward_start(struct seq_file *seq, loff_t *pos)
166 __acquires(x25_forward_list_lock) 118 __acquires(x25_forward_list_lock)
167{ 119{
168 loff_t l = *pos;
169
170 read_lock_bh(&x25_forward_list_lock); 120 read_lock_bh(&x25_forward_list_lock);
171 return l ? x25_get_forward_idx(--l) : SEQ_START_TOKEN; 121 return seq_list_start_head(&x25_forward_list, *pos);
172} 122}
173 123
174static void *x25_seq_forward_next(struct seq_file *seq, void *v, loff_t *pos) 124static void *x25_seq_forward_next(struct seq_file *seq, void *v, loff_t *pos)
175{ 125{
176 struct x25_forward *f; 126 return seq_list_next(v, &x25_forward_list, pos);
177
178 ++*pos;
179 if (v == SEQ_START_TOKEN) {
180 f = NULL;
181 if (!list_empty(&x25_forward_list))
182 f = list_entry(x25_forward_list.next,
183 struct x25_forward, node);
184 goto out;
185 }
186 f = v;
187 if (f->node.next != &x25_forward_list)
188 f = list_entry(f->node.next, struct x25_forward, node);
189 else
190 f = NULL;
191out:
192 return f;
193
194} 127}
195 128
196static void x25_seq_forward_stop(struct seq_file *seq, void *v) 129static void x25_seq_forward_stop(struct seq_file *seq, void *v)
@@ -201,9 +134,9 @@ static void x25_seq_forward_stop(struct seq_file *seq, void *v)
201 134
202static int x25_seq_forward_show(struct seq_file *seq, void *v) 135static int x25_seq_forward_show(struct seq_file *seq, void *v)
203{ 136{
204 struct x25_forward *f; 137 struct x25_forward *f = list_entry(v, struct x25_forward, node);
205 138
206 if (v == SEQ_START_TOKEN) { 139 if (v == &x25_forward_list) {
207 seq_printf(seq, "lci dev1 dev2\n"); 140 seq_printf(seq, "lci dev1 dev2\n");
208 goto out; 141 goto out;
209 } 142 }
@@ -212,7 +145,6 @@ static int x25_seq_forward_show(struct seq_file *seq, void *v)
212 145
213 seq_printf(seq, "%d %-10s %-10s\n", 146 seq_printf(seq, "%d %-10s %-10s\n",
214 f->lci, f->dev1->name, f->dev2->name); 147 f->lci, f->dev1->name, f->dev2->name);
215
216out: 148out:
217 return 0; 149 return 0;
218} 150}