net: simplify seq_file code, revised
Subsystems (8)
cover net: simplify seq_file code, revised
This patchset introduces seq_hlist_foo() helpers, and convert net/* to seq_hlist_foo() and seq_list_foo().
Changelog:
- Add kerneldoc in patch 1/13
- Fix compile warning in patch 11/13
- Fix a bug in patch 12/13
--- fs/seq_file.c | 60 ++++++++++++++++++++- include/linux/seq_file.h | 11 ++++ include/net/sock.h | 5 ++ net/appletalk/atalk_proc.c | 30 +---------- net/atm/proc.c | 2 +- net/atm/resources.c | 28 +++-------- net/ax25/af_ax25.c | 18 +----- net/ax25/ax25_uid.c | 25 ++-------- net/ipx/ipx_proc.c | 90 ++++---------------------------- net/irda/irlan/irlan_common.c | 28 ++--------- net/key/af_key.c | 20 +------ net/netrom/af_netrom.c | 21 +------- net/netrom/nr_route.c | 53 +++---------------- net/packet/af_packet.c | 20 +------ net/rose/af_rose.c | 22 +------- net/x25/x25_proc.c | 114 ++++------------------------------------- 16 files changed, 139 insertions(+), 408 deletions(-)
PATCH 1/13 seq_file: Add helpers for iteration over a hlist
Some places in kernel need to iterate over a hlist in seq_file, so provide some common helpers.
--- fs/seq_file.c | 60 +++++++++++++++++++++++++++++++++++++++++++-- include/linux/seq_file.h | 11 ++++++++ 2 files changed, 68 insertions(+), 3 deletions(-)
fs/seq_file.c +57 -3
@@ -674,7 +674,6 @@ struct list_head *seq_list_start(struct list_head *head, loff_t pos)return NULL ; } -EXPORT_SYMBOL (seq_list_start);struct list_head *seq_list_start_head (struct list_head *head,loff_t pos)
@@ -684,7 +683,6 @@ struct list_head *seq_list_start_head(struct list_head *head, loff_t pos)return seq_list_start (head, pos -1 ); } -EXPORT_SYMBOL (seq_list_start_head);struct list_head *seq_list_next (void *v,struct list_head *head,loff_t *ppos)
@@ -695,5 +693,61 @@ struct list_head *seq_list_next(void *v, struct list_head *head, loff_t *ppos) ++*ppos;return lh == head ?NULL : lh; } -EXPORT_SYMBOL (seq_list_next); + +/** +* seq_hlist_start - start an iteration of a hlist +* @head: the head of the hlist +* @pos: the start position of the sequence +* +* Called at seq_file->op->start(). +*/ +struct hlist_node *seq_hlist_start (struct hlist_head *head,loff_t pos) +{ +struct hlist_node *node; + +hlist_for_each (node, head) +if (pos-- ==0 ) +return node; +return NULL ; +} +EXPORT_SYMBOL (seq_hlist_start); + +/** +* seq_hlist_start_head - start an iteration of a hlist +* @head: the head of the hlist +* @pos: the start position of the sequence +* +* Called at seq_file->op->start(). Call this function if you want to +* print a header at the top of the output. +*/ +struct hlist_node *seq_hlist_start_head (struct hlist_head *head,loff_t pos) +{ +if (!pos) +return SEQ_START_TOKEN ; + +return seq_hlist_start (head, pos -1 ); +} +EXPORT_SYMBOL (seq_hlist_start_head); + +/** +* seq_hlist_next - move to the next position of the hlist +* @v: the current iterator +* @head: the head of the hlist +* @pos: the current posision +* +* Called at seq_file->op->next(). +*/ +struct hlist_node *seq_hlist_next (void *v,struct hlist_head *head, +loff_t *ppos) +{ +struct hlist_node *node = v; + + ++*ppos; +if (v ==SEQ_START_TOKEN ) +return head->first; +else +return node->next; +} +EXPORT_SYMBOL (seq_hlist_next); +
include/linux/seq_file.h +11 -0
@@ -135,4 +135,15 @@ extern struct list_head *seq_list_start_head(struct list_head *head,extern struct list_head *seq_list_next (void *v,struct list_head *head,loff_t *ppos); +/* +* Helpers for iteration over hlist_head-s in seq_files +*/ + +extern struct hlist_node *seq_hlist_start (struct hlist_head *head, +loff_t pos); +extern struct hlist_node *seq_hlist_start_head (struct hlist_head *head, +loff_t pos); +extern struct hlist_node *seq_hlist_next (void *v,struct hlist_head *head, +loff_t *ppos); +#endif
Signature · 1 line
1.6.3
PATCH 2/13 net: add a wrapper sk_entry()
In reply to Li Zefan--- include/net/sock.h | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
include/net/sock.h +5 -0
@@ -317,6 +317,11 @@ struct sock {/* * Hashed lists helper routines */ +static inline struct sock *sk_entry (const struct hlist_node *node) +{ + return hlist_entry(node, struct sock, sk_node); +} +static inline struct sock *__sk_head (const struct hlist_head *head) { return hlist_entry(head->first, struct sock, sk_node);
Signature · 1 line
1.6.3
PATCH 3/13 net: x25: use seq_hlist_foo() helpers
In reply to Li ZefanSimplify seq_file code.
--- net/x25/x25_proc.c | 30 +++--------------------------- 1 files changed, 3 insertions(+), 27 deletions(-)
net/x25/x25_proc.c +3 -27
@@ -93,40 +93,16 @@ out:return 0 ; } -static __inline__struct sock *x25_get_socket_idx (loff_t pos) -{ -struct sock *s; -struct hlist_node *node; - -sk_for_each (s, node, &x25_list) -if (!pos--) - goto found; - s =NULL ; -found: -return s; -} -static void *x25_seq_socket_start (struct seq_file *seq,loff_t *pos)__acquires (x25_list_lock) { -loff_t l = *pos; -read_lock_bh (&x25_list_lock); -return l ?x25_get_socket_idx (--l) :SEQ_START_TOKEN ; +return seq_hlist_start_head (&x25_list, *pos); }static void *x25_seq_socket_next (struct seq_file *seq,void *v,loff_t *pos) { -struct sock *s; - - ++*pos; -if (v ==SEQ_START_TOKEN ) { - s =sk_head (&x25_list); - goto out; - } - s =sk_next (v); -out: -return s; +return seq_hlist_next (v, &x25_list, pos); }static void x25_seq_socket_stop (struct seq_file *seq,void *v)
@@ -148,7 +124,7 @@ static int x25_seq_socket_show(struct seq_file *seq, void *v) goto out; } - s = v; + s =sk_entry (v); x25 =x25_sk (s);if (!x25->neighbour || (dev = x25->neighbour->dev) ==NULL )
Signature · 1 line
1.6.3
PATCH 4/13 net: rose: use seq_hlist_foo() helpers
In reply to Li ZefanSimplify seq_file code.
--- net/rose/af_rose.c | 22 +++------------------- 1 files changed, 3 insertions(+), 19 deletions(-)
net/rose/af_rose.c +3 -19
@@ -1404,29 +1404,13 @@ static int rose_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)static void *rose_info_start (struct seq_file *seq,loff_t *pos)__acquires (rose_list_lock) { -int i; -struct sock *s; -struct hlist_node *node; -spin_lock_bh (&rose_list_lock); -if (*pos ==0 ) -return SEQ_START_TOKEN ; - - i =1 ; -sk_for_each (s, node, &rose_list) { -if (i == *pos) -return s; - ++i; - } -return NULL ; +return seq_hlist_start_head (&rose_list, *pos); }static void *rose_info_next (struct seq_file *seq,void *v,loff_t *pos) { - ++*pos; - -return (v ==SEQ_START_TOKEN ) ?sk_head (&rose_list) - :sk_next ((struct sock *)v); +return seq_hlist_next (v, &rose_list, pos); }static void rose_info_stop (struct seq_file *seq,void *v)
@@ -1444,7 +1428,7 @@ static int rose_info_show(struct seq_file *seq, void *v) "dest_addr dest_call src_addr src_call dev lci neigh st vs vr va t t1 t2 t3 hb idle Snd-Q Rcv-Q inode\n"); else { -struct sock *s = v; +struct sock *s =sk_entry (v);struct rose_sock *rose =rose_sk (s);const char *devname, *callsign;const struct net_device *dev = rose->device;
Signature · 1 line
1.6.3
PATCH 5/13 net: packet: use seq_hlist_foo() helpers
In reply to Li ZefanSimplify seq_file code.
--- net/packet/af_packet.c | 20 +++----------------- 1 files changed, 3 insertions(+), 17 deletions(-)
net/packet/af_packet.c +3 -17
@@ -2374,33 +2374,19 @@ static struct notifier_block packet_netdev_notifier = { };#ifdef CONFIG_PROC_FS -static inline struct sock *packet_seq_idx (struct net *net,loff_t off) -{ -struct sock *s; -struct hlist_node *node; - -sk_for_each (s, node, &net->packet.sklist) { -if (!off--) -return s; - } -return NULL ; -}static void *packet_seq_start (struct seq_file *seq,loff_t *pos) __acquires(seq_file_net(seq)->packet.sklist_lock) {struct net *net =seq_file_net (seq);read_lock (&net->packet.sklist_lock); -return *pos ?packet_seq_idx (net, *pos -1 ) :SEQ_START_TOKEN ; +return seq_hlist_start_head (&net->packet.sklist, *pos); }static void *packet_seq_next (struct seq_file *seq,void *v,loff_t *pos) {struct net *net =seq_file_net (seq); - ++*pos; -return (v ==SEQ_START_TOKEN ) - ?sk_head (&net->packet.sklist) - :sk_next ((struct sock *)v) ; +return seq_hlist_next (v, &net->packet.sklist, pos); }static void packet_seq_stop (struct seq_file *seq,void *v)
@@ -2415,7 +2401,7 @@ static int packet_seq_show(struct seq_file *seq, void *v)if (v ==SEQ_START_TOKEN )seq_puts (seq,"sk RefCnt Type Proto Iface R Rmem User Inode\n" );else { -struct sock *s = v; +struct sock *s =sk_entry (v);const struct packet_sock *po =pkt_sk (s); seq_printf(seq,
Signature · 1 line
1.6.3
PATCH 6/13 net: netrom: use seq_hlist_foo() helpers
In reply to Li ZefanSimplify seq_file code.
--- net/netrom/af_netrom.c | 21 ++---------------- net/netrom/nr_route.c | 53 ++++++++--------------------------------------- 2 files changed, 12 insertions(+), 62 deletions(-)
net/netrom/af_netrom.c +3 -18
@@ -1267,28 +1267,13 @@ static int nr_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)static void *nr_info_start (struct seq_file *seq,loff_t *pos) { -struct sock *s; -struct hlist_node *node; -int i =1 ; -spin_lock_bh (&nr_list_lock); -if (*pos ==0 ) -return SEQ_START_TOKEN ; - -sk_for_each (s, node, &nr_list) { -if (i == *pos) -return s; - ++i; - } -return NULL ; +return seq_hlist_start_head (&nr_list, *pos); }static void *nr_info_next (struct seq_file *seq,void *v,loff_t *pos) { - ++*pos; - -return (v ==SEQ_START_TOKEN ) ?sk_head (&nr_list) - :sk_next ((struct sock *)v); +return seq_hlist_next (v, &nr_list, pos); }static void nr_info_stop (struct seq_file *seq,void *v)
@@ -1298,7 +1283,7 @@ static void nr_info_stop(struct seq_file *seq, void *v)static int nr_info_show (struct seq_file *seq,void *v) { -struct sock *s = v; +struct sock *s =sk_entry (v);struct net_device *dev;struct nr_sock *nr;const char *devname;
net/netrom/nr_route.c +9 -44
88 lines not on this page · raw message
Signature · 1 line
1.6.3
PATCH 7/13 net: ax25: use seq_hlist_foo() helpers
In reply to Li ZefanSimplify seq_file code.
--- net/ax25/af_ax25.c | 18 +++--------------- net/ax25/ax25_uid.c | 25 ++++--------------------- 2 files changed, 7 insertions(+), 36 deletions(-)
net/ax25/af_ax25.c +3 -15
@@ -1863,25 +1863,13 @@ static int ax25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)static void *ax25_info_start (struct seq_file *seq,loff_t *pos)__acquires (ax25_list_lock) { -struct ax25_cb *ax25; -struct hlist_node *node; -int i =0 ; -spin_lock_bh (&ax25_list_lock); -ax25_for_each (ax25, node, &ax25_list) { -if (i == *pos) -return ax25; - ++i; - } -return NULL ; +return seq_hlist_start (&ax25_list, *pos); }static void *ax25_info_next (struct seq_file *seq,void *v,loff_t *pos) { - ++*pos; - -return hlist_entry ( ((struct ax25_cb *)v)->ax25_node.next, - struct ax25_cb, ax25_node); +return seq_hlist_next (v, &ax25_list, pos); }static void ax25_info_stop (struct seq_file *seq,void *v)
@@ -1892,7 +1880,7 @@ static void ax25_info_stop(struct seq_file *seq, void *v)static int ax25_info_show (struct seq_file *seq,void *v) { -ax25_cb *ax25 = v; + ax25_cb *ax25 = hlist_entry(v, struct ax25_cb, ax25_node);char buf[11 ];int k;
net/ax25/ax25_uid.c +4 -21
@@ -146,31 +146,13 @@ int ax25_uid_ioctl(int cmd, struct sockaddr_ax25 *sax)static void *ax25_uid_seq_start (struct seq_file *seq,loff_t *pos)__acquires (ax25_uid_lock) { -struct ax25_uid_assoc *pt; -struct hlist_node *node; -int i =1 ; -read_lock (&ax25_uid_lock); - -if (*pos ==0 ) -return SEQ_START_TOKEN ; - -ax25_uid_for_each (pt, node, &ax25_uid_list) { -if (i == *pos) -return pt; - ++i; - } -return NULL ; +return seq_hlist_start_head (&ax25_uid_list, *pos); }static void *ax25_uid_seq_next (struct seq_file *seq,void *v,loff_t *pos) { - ++*pos; -if (v ==SEQ_START_TOKEN ) -return ax25_uid_list.first; -else -return hlist_entry (((ax25_uid_assoc *)v)->uid_node.next, - ax25_uid_assoc, uid_node); +return seq_hlist_next (v, &ax25_uid_list, pos); }static void ax25_uid_seq_stop (struct seq_file *seq,void *v)
@@ -186,8 +168,9 @@ static int ax25_uid_seq_show(struct seq_file *seq, void *v)if (v ==SEQ_START_TOKEN )seq_printf (seq,"Policy: %d\n" , ax25_uid_policy);else { -struct ax25_uid_assoc *pt = v; +struct ax25_uid_assoc *pt; + pt = hlist_entry(v, struct ax25_uid_assoc, uid_node);seq_printf (seq,"%6d %s\n" , pt->uid,ax2asc (buf, &pt->call)); }return 0 ;
Signature · 1 line
1.6.3
PATCH 8/13 net: appletalk: use seq_hlist_foo() helpers
In reply to Li ZefanSimplify seq_file code.
--- net/appletalk/atalk_proc.c | 30 +++--------------------------- 1 files changed, 3 insertions(+), 27 deletions(-)
net/appletalk/atalk_proc.c +3 -27
@@ -144,40 +144,16 @@ out:return 0 ; } -static __inline__struct sock *atalk_get_socket_idx (loff_t pos) -{ -struct sock *s; -struct hlist_node *node; - -sk_for_each (s, node, &atalk_sockets) -if (!pos--) - goto found; - s =NULL ; -found: -return s; -} -static void *atalk_seq_socket_start (struct seq_file *seq,loff_t *pos)__acquires (atalk_sockets_lock) { -loff_t l = *pos; -read_lock_bh (&atalk_sockets_lock); -return l ?atalk_get_socket_idx (--l) :SEQ_START_TOKEN ; +return seq_hlist_start_head (&atalk_sockets, *pos); }static void *atalk_seq_socket_next (struct seq_file *seq,void *v,loff_t *pos) { -struct sock *i; - - ++*pos; -if (v ==SEQ_START_TOKEN ) { - i =sk_head (&atalk_sockets); - goto out; - } - i =sk_next (v); -out: -return i; +return seq_hlist_next (v, &atalk_sockets, pos); }static void atalk_seq_socket_stop (struct seq_file *seq,void *v)
@@ -197,7 +173,7 @@ static int atalk_seq_socket_show(struct seq_file *seq, void *v) goto out; } - s = v; + s =sk_entry (v); at =at_sk (s); seq_printf(seq, "%02X %04X:%02X:%02X %04X:%02X:%02X %08X:%08X "
Signature · 1 line
1.6.3
PATCH 9/13 net: af_key: use seq_hlist_foo() helpers
In reply to Li ZefanSimplify seq_file code.
--- net/key/af_key.c | 20 +++----------------- 1 files changed, 3 insertions(+), 17 deletions(-)
net/key/af_key.c +3 -17
@@ -3655,9 +3655,8 @@ static const struct net_proto_family pfkey_family_ops = {#ifdef CONFIG_PROC_FS static int pfkey_seq_show (struct seq_file *f,void *v) { -struct sock *s; +struct sock *s =sk_entry (v); - s = (struct sock *)v;if (v ==SEQ_START_TOKEN )seq_printf (f ,"sk RefCnt Rmem Wmem User Inode\n" );else
@@ -3676,19 +3675,9 @@ static void *pfkey_seq_start(struct seq_file *f, loff_t *ppos) {struct net *net =seq_file_net (f);struct netns_pfkey *net_pfkey =net_generic (net, pfkey_net_id); -struct sock *s; -struct hlist_node *node; -loff_t pos = *ppos;read_lock (&pfkey_table_lock); -if (pos ==0 ) -return SEQ_START_TOKEN ; - -sk_for_each (s, node, &net_pfkey->table) -if (pos-- ==1 ) -return s; - -return NULL ; +return seq_hlist_start_head (&net_pfkey->table, *ppos); }static void *pfkey_seq_next (struct seq_file *f,void *v,loff_t *ppos)
@@ -3696,10 +3685,7 @@ static void *pfkey_seq_next(struct seq_file *f, void *v, loff_t *ppos)struct net *net =seq_file_net (f);struct netns_pfkey *net_pfkey =net_generic (net, pfkey_net_id); - ++*ppos; -return (v ==SEQ_START_TOKEN ) ? -sk_head (&net_pfkey->table) : -sk_next ((struct sock *)v); +return seq_hlist_next (v, &net_pfkey->table, ppos); }static void pfkey_seq_stop (struct seq_file *f,void *v)
Signature · 1 line
1.6.3
PATCH 10/13 net: x25: use seq_list_foo() helpers
In reply to Li ZefanSimplify seq_file code.
--- net/x25/x25_proc.c | 84 +++++----------------------------------------------- 1 files changed, 8 insertions(+), 76 deletions(-)
net/x25/x25_proc.c +8 -76
@@ -25,49 +25,17 @@#include <net/x25.h> #ifdef CONFIG_PROC_FS -static __inline__struct x25_route *x25_get_route_idx (loff_t pos) -{ -struct list_head *route_entry; -struct x25_route *rt =NULL ; - -list_for_each (route_entry, &x25_route_list) { - rt = list_entry(route_entry, struct x25_route, node); -if (!pos--) - goto found; - } - rt =NULL ; -found: -return rt; -}static void *x25_seq_route_start (struct seq_file *seq,loff_t *pos)__acquires (x25_route_list_lock) { -loff_t l = *pos; -read_lock_bh (&x25_route_list_lock); -return l ?x25_get_route_idx (--l) :SEQ_START_TOKEN ; +return seq_list_start_head (&x25_route_list, *pos); }static void *x25_seq_route_next (struct seq_file *seq,void *v,loff_t *pos) { -struct x25_route *rt; - - ++*pos; -if (v ==SEQ_START_TOKEN ) { - rt =NULL ; -if (!list_empty (&x25_route_list)) - rt =list_entry (x25_route_list.next, - struct x25_route, node); - goto out; - } - rt = v; -if (rt->node.next != &x25_route_list) - rt = list_entry(rt->node.next, struct x25_route, node); -else - rt =NULL ; -out: -return rt; +return seq_list_next (v, &x25_route_list, pos); }static 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)static int x25_seq_route_show (struct seq_file *seq,void *v) { -struct x25_route *rt; + struct x25_route *rt = list_entry(v, struct x25_route, node); -if (v ==SEQ_START_TOKEN ) { +if (v == &x25_route_list) {seq_puts (seq,"Address Digits Device\n" ); goto out; }
@@ -146,51 +114,16 @@ out:return 0 ; } -static __inline__struct x25_forward *x25_get_forward_idx (loff_t pos) -{ -struct x25_forward *f; -struct list_head *entry; - -list_for_each (entry, &x25_forward_list) { - f = list_entry(entry, struct x25_forward, node); -if (!pos--) - goto found; - } - - f =NULL ; -found: -return f; -} -static void *x25_seq_forward_start (struct seq_file *seq,loff_t *pos)__acquires (x25_forward_list_lock) { -loff_t l = *pos; -read_lock_bh (&x25_forward_list_lock); -return l ?x25_get_forward_idx (--l) :SEQ_START_TOKEN ; +return seq_list_start_head (&x25_forward_list, *pos); }static void *x25_seq_forward_next (struct seq_file *seq,void *v,loff_t *pos) { -struct x25_forward *f; - - ++*pos; -if (v ==SEQ_START_TOKEN ) { - f =NULL ; -if (!list_empty (&x25_forward_list)) - f =list_entry (x25_forward_list.next, - struct x25_forward, node); - goto out; - } - f = v; -if (f->node.next != &x25_forward_list) - f = list_entry(f->node.next, struct x25_forward, node); -else - f =NULL ; -out: -return f; - +return seq_list_next (v, &x25_forward_list, pos); }static 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)static int x25_seq_forward_show (struct seq_file *seq,void *v) { -struct x25_forward *f; + struct x25_forward *f = list_entry(v, struct x25_forward, node); -if (v ==SEQ_START_TOKEN ) { +if (v == &x25_forward_list) {seq_printf (seq,"lci dev1 dev2\n" ); goto out; }
@@ -212,7 +145,6 @@ static int x25_seq_forward_show(struct seq_file *seq, void *v)seq_printf (seq,"%d %-10s %-10s\n" , f->lci, f->dev1->name, f->dev2->name); - out:return 0 ; }
Signature · 1 line
1.6.3
PATCH 11/13 net: irda: use seq_list_foo() helpers
In reply to Li ZefanSimplify seq_file code.
--- net/irda/irlan/irlan_common.c | 28 ++++------------------------ 1 files changed, 4 insertions(+), 24 deletions(-)
net/irda/irlan/irlan_common.c +4 -24
@@ -1128,34 +1128,14 @@ int irlan_extract_param(__u8 *buf, char *name, char *value, __u16 *len)*/ static void *irlan_seq_start (struct seq_file *seq,loff_t *pos) { -int i =1 ; -struct irlan_cb *self; -rcu_read_lock (); -if (*pos ==0 ) -return SEQ_START_TOKEN ; - -list_for_each_entry (self, &irlans, dev_list) { -if (*pos == i) -return self; - ++i; - } -return NULL ; +return seq_list_start_head (&irlans, *pos); }/* Return entry after v, and increment pos */ static void *irlan_seq_next (struct seq_file *seq,void *v,loff_t *pos) { -struct list_head *nxt; - - ++*pos; -if (v ==SEQ_START_TOKEN ) - nxt = irlans.next; -else - nxt = ((struct irlan_cb *)v)->dev_list.next; - -return (nxt == &irlans) ?NULL - : list_entry(nxt, struct irlan_cb, dev_list); +return seq_list_next (v, &irlans, pos); }/* End of reading /proc file */
@@ -1170,10 +1150,10 @@ static void irlan_seq_stop(struct seq_file *seq, void *v)*/ static int irlan_seq_show (struct seq_file *seq,void *v) { -if (v ==SEQ_START_TOKEN ) +if (v == &irlans)seq_puts (seq,"IrLAN instances:\n" );else { -struct irlan_cb *self = v; + struct irlan_cb *self = list_entry(v, struct irlan_cb, list); IRDA_ASSERT(self != NULL, return -1;); IRDA_ASSERT(self->magic == IRLAN_MAGIC, return -1;);
Signature · 1 line
1.6.3
PATCH 12/13 net: ipx: use seq_list_foo() helpers
In reply to Li ZefanSimplify seq_file code.
--- net/ipx/ipx_proc.c | 90 +++++++--------------------------------------------- 1 files changed, 12 insertions(+), 78 deletions(-)
net/ipx/ipx_proc.c +12 -78
@@ -13,45 +13,15 @@#include <net/tcp_states.h> #include <net/ipx.h> -static __inline__struct ipx_interface *ipx_get_interface_idx (loff_t pos) -{ -struct ipx_interface *i; - -list_for_each_entry (i, &ipx_interfaces, node) -if (!pos--) - goto out; - i =NULL ; -out: -return i; -} - -static struct ipx_interface *ipx_interfaces_next (struct ipx_interface *i) -{ -struct ipx_interface *rc =NULL ; - -if (i->node.next != &ipx_interfaces) - rc = list_entry(i->node.next, struct ipx_interface, node); -return rc; -} -static void *ipx_seq_interface_start (struct seq_file *seq,loff_t *pos) { -loff_t l = *pos; -spin_lock_bh (&ipx_interfaces_lock); -return l ?ipx_get_interface_idx (--l) :SEQ_START_TOKEN ; +return seq_list_start_head (&ipx_interfaces, *pos); }static void *ipx_seq_interface_next (struct seq_file *seq,void *v,loff_t *pos) { -struct ipx_interface *i; - - ++*pos; -if (v ==SEQ_START_TOKEN ) - i =ipx_interfaces_head (); -else - i =ipx_interfaces_next (v); -return i; +return seq_list_next (v, &ipx_interfaces, pos); }static void ipx_seq_interface_stop (struct seq_file *seq,void *v)
@@ -63,7 +33,7 @@ static int ipx_seq_interface_show(struct seq_file *seq, void *v) {struct ipx_interface *i; -if (v ==SEQ_START_TOKEN ) { +if (v == &ipx_interfaces) {seq_puts (seq,"Network Node_Address Primary Device " "Frame_Type" );#ifdef IPX_REFCNT_DEBUG
@@ -73,7 +43,7 @@ static int ipx_seq_interface_show(struct seq_file *seq, void *v) goto out; } - i = v; + i = list_entry(v, struct ipx_interface, node);seq_printf (seq,"%08lX " , (unsigned long int )ntohl (i->if_netnum)); seq_printf(seq, "%02X%02X%02X%02X%02X%02X ", i->if_node[0], i->if_node[1], i->if_node[2],
@@ -89,53 +59,15 @@ out:return 0 ; } -static struct ipx_route *ipx_routes_head (void ) -{ -struct ipx_route *rc =NULL ; - -if (!list_empty (&ipx_routes)) - rc = list_entry(ipx_routes.next, struct ipx_route, node); -return rc; -} - -static struct ipx_route *ipx_routes_next (struct ipx_route *r) -{ -struct ipx_route *rc =NULL ; - -if (r->node.next != &ipx_routes) - rc = list_entry(r->node.next, struct ipx_route, node); -return rc; -} - -static __inline__struct ipx_route *ipx_get_route_idx (loff_t pos) -{ -struct ipx_route *r; - -list_for_each_entry (r, &ipx_routes, node) -if (!pos--) - goto out; - r =NULL ; -out: -return r; -} -static void *ipx_seq_route_start (struct seq_file *seq,loff_t *pos) { -loff_t l = *pos;read_lock_bh (&ipx_routes_lock); -return l ?ipx_get_route_idx (--l) :SEQ_START_TOKEN ; +return seq_list_start_head (&ipx_routes, *pos); }static void *ipx_seq_route_next (struct seq_file *seq,void *v,loff_t *pos) { -struct ipx_route *r; - - ++*pos; -if (v ==SEQ_START_TOKEN ) - r =ipx_routes_head (); -else - r =ipx_routes_next (v); -return r; +return seq_list_next (v, &ipx_routes, pos); }static void ipx_seq_route_stop (struct seq_file *seq,void *v)
@@ -147,11 +79,13 @@ static int ipx_seq_route_show(struct seq_file *seq, void *v) {struct ipx_route *rt; -if (v ==SEQ_START_TOKEN ) { +if (v == &ipx_routes) {seq_puts (seq,"Network Router_Net Router_Node\n" ); goto out; } - rt = v; + + rt = list_entry(v, struct ipx_route, node); +seq_printf (seq,"%08lX " , (unsigned long int )ntohl (rt->ir_net));if (rt->ir_routed) seq_printf(seq, "%08lX %02X%02X%02X%02X%02X%02X\n",
@@ -226,9 +160,9 @@ static void *ipx_seq_socket_next(struct seq_file *seq, void *v, loff_t *pos)spin_unlock_bh (&i->if_sklist_lock); sk =NULL ;for (;;) { - i =ipx_interfaces_next (i); -if (!i) +if (i->node.next == &ipx_interfaces)break ; + i = list_entry(i->node.next, struct ipx_interface, node);spin_lock_bh (&i->if_sklist_lock);if (!hlist_empty (&i->if_sklist)) { sk =sk_head (&i->if_sklist);
Signature · 1 line
1.6.3
PATCH 13/13 net: atm: use seq_list_foo() helpers
In reply to Li ZefanSimplify seq_file code.
--- net/atm/proc.c | 2 +- net/atm/resources.c | 18 ++---------------- 2 files changed, 3 insertions(+), 17 deletions(-)
net/atm/proc.c +1 -1
@@ -236,7 +236,7 @@ static int atm_dev_seq_show(struct seq_file *seq, void *v)"Itf Type ESI/\"MAC\"addr " "AAL(TX,err,RX,err,drop) ... [refcnt]\n" ; -if (v ==SEQ_START_TOKEN ) +if (v == &atm_devs)seq_puts (seq, atm_dev_banner);else { struct atm_dev *dev = list_entry(v, struct atm_dev, dev_list);
net/atm/resources.c +2 -16
@@ -454,21 +454,10 @@ done:return error; } -static inline void *dev_get_idx (loff_t left) -{ -struct list_head *p; - -list_for_each (p, &atm_devs) { -if (!--left) -break ; - } -return (p != &atm_devs) ? p :NULL ; -} -void *atm_dev_seq_start (struct seq_file *seq,loff_t *pos) {mutex_lock (&atm_dev_mutex); -return *pos ?dev_get_idx (*pos) :SEQ_START_TOKEN ; +return seq_list_start_head (&atm_devs, *pos); }void atm_dev_seq_stop (struct seq_file *seq,void *v)
@@ -478,8 +467,5 @@ void atm_dev_seq_stop(struct seq_file *seq, void *v)void *atm_dev_seq_next (struct seq_file *seq,void *v,loff_t *pos) { - ++*pos; - v = (v ==SEQ_START_TOKEN ) - ? atm_devs.next : ((struct list_head *)v)->next; -return (v == &atm_devs) ?NULL : v; +return seq_list_next (v, &atm_devs, pos); }
Signature · 1 line
1.6.3
David Miller
maintainerFrom: Li Zefan <[email protected]>
Date: Tue, 09 Feb 2010 17:18:01 +0800
Quoted 8 lines
This patchset introduces
seq_hlist_foo()helpers, and convertnet/*toseq_hlist_foo()andseq_list_foo().Changelog:
- Add kerneldoc in patch 1/13
- Fix compile warning in patch 11/13
- Fix a bug in patch 12/13
All applied to net-next-2.6, thanks!
David Miller
maintainerFrom: David Miller <[email protected]>
Date: Wed, 10 Feb 2010 11:31:15 -0800 (PST)
Quoted 6 lines
From: Li Zefan <[email protected]>
Date: Tue, 09 Feb 2010 17:18:01 +0800Quoted 3 lines
This patchset introduces
seq_hlist_foo()helpers, and convertnet/*toseq_hlist_foo()andseq_list_foo().
Quoted 7 lines
Quoted 5 lines
Changelog:
- Add kerneldoc in patch 1/13
- Fix compile warning in patch 11/13
- Fix a bug in patch 12/13All applied to net-next-2.6, thanks!
You did not build test your changes.
net/irda/irlan/irlan_common.c:1156: error: 'struct irlan_cb' has no member named 'list' net/irda/irlan/irlan_common.c:1156: warning: type defaults to 'int' in declaration of '__mptr' net/irda/irlan/irlan_common.c:1156: error: 'struct irlan_cb' has no member named 'list'
I'll fix this, but I will not next time. Instead, I'll revert all of your changes and push it back to you.
Thanks.