diff options
author | Pavel Emelianov <xemul@sw.ru> | 2007-07-10 20:22:26 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-07-10 20:51:13 -0400 |
commit | bcf67e16251c42302499499b1c50f7d35622f564 (patch) | |
tree | 3df64aa83005c0a153acf3a1a0d7a6e6d49dc688 /fs/seq_file.c | |
parent | c14d444b55f285063a4018c10d521614b70b581a (diff) |
Make common helpers for seq_files that work with list_heads
Many places in kernel use seq_file API to iterate over a regular list_head.
The code for such iteration is identical in all the places, so it's worth
introducing a common helpers.
This makes code about 300 lines smaller:
The first version of this patch made the helper functions static inline
in the seq_file.h header. This patch moves them to the fs/seq_file.c as
Andrew proposed. The vmlinux .text section sizes are as follows:
2.6.22-rc1-mm1: 0x001794d5
with the previous version: 0x00179505
with this patch: 0x00179135
The config file used was make allnoconfig with the "y" inclusion of all
the possible options to make the files modified by the patch compile plus
drivers I have on the test node.
This patch:
Many places in kernel use seq_file API to iterate over a regular list_head.
The code for such iteration is identical in all the places, so it's worth
introducing a common helpers.
Signed-off-by: Pavel Emelianov <xemul@openvz.org>
Cc: "David S. Miller" <davem@davemloft.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/seq_file.c')
-rw-r--r-- | fs/seq_file.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/fs/seq_file.c b/fs/seq_file.c index 0ac22af7afe5..49194a4e6b91 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c | |||
@@ -447,3 +447,37 @@ int seq_puts(struct seq_file *m, const char *s) | |||
447 | return -1; | 447 | return -1; |
448 | } | 448 | } |
449 | EXPORT_SYMBOL(seq_puts); | 449 | EXPORT_SYMBOL(seq_puts); |
450 | |||
451 | struct list_head *seq_list_start(struct list_head *head, loff_t pos) | ||
452 | { | ||
453 | struct list_head *lh; | ||
454 | |||
455 | list_for_each(lh, head) | ||
456 | if (pos-- == 0) | ||
457 | return lh; | ||
458 | |||
459 | return NULL; | ||
460 | } | ||
461 | |||
462 | EXPORT_SYMBOL(seq_list_start); | ||
463 | |||
464 | struct list_head *seq_list_start_head(struct list_head *head, loff_t pos) | ||
465 | { | ||
466 | if (!pos) | ||
467 | return head; | ||
468 | |||
469 | return seq_list_start(head, pos - 1); | ||
470 | } | ||
471 | |||
472 | EXPORT_SYMBOL(seq_list_start_head); | ||
473 | |||
474 | struct list_head *seq_list_next(void *v, struct list_head *head, loff_t *ppos) | ||
475 | { | ||
476 | struct list_head *lh; | ||
477 | |||
478 | lh = ((struct list_head *)v)->next; | ||
479 | ++*ppos; | ||
480 | return lh == head ? NULL : lh; | ||
481 | } | ||
482 | |||
483 | EXPORT_SYMBOL(seq_list_next); | ||