seq_file/netfilter: Start removing returns from seq_<foo>
Subsystems (9)
cover seq_file/netfilter: Start removing returns from seq_<foo>
The return value from seq_printf/puts/putc/etc are frequently misused. Start removing the uses of the return values.
Joe Perches (2):
seq_file: Rename static bool seq_overflow to public bool seq_is_buf_full
netfilter: Convert print_tuple functions to return void
Documentation/filesystems/seq_file.txt | 28 ++++++++++++++++------------ fs/seq_file.c | 28 ++++++++++++++-------------- include/linux/seq_file.h | 8 ++++++++ include/net/netfilter/nf_conntrack_core.h | 2 +- include/net/netfilter/nf_conntrack_l3proto.h | 4 ++-- include/net/netfilter/nf_conntrack_l4proto.h | 4 ++-- net/netfilter/nf_conntrack_l3proto_generic.c | 5 ++--- net/netfilter/nf_conntrack_proto_dccp.c | 10 +++++----- net/netfilter/nf_conntrack_proto_generic.c | 5 ++--- net/netfilter/nf_conntrack_proto_gre.c | 10 +++++----- net/netfilter/nf_conntrack_proto_sctp.c | 10 +++++----- net/netfilter/nf_conntrack_proto_tcp.c | 10 +++++----- net/netfilter/nf_conntrack_proto_udp.c | 10 +++++----- net/netfilter/nf_conntrack_proto_udplite.c | 10 +++++----- net/netfilter/nf_conntrack_standalone.c | 15 +++++++-------- 15 files changed, 84 insertions(+), 75 deletions(-)
Signature · 1 line
1.8.1.2.459.gbcd45b4.dirty
PATCH 1/2 seq_file: Rename static bool seq_overflow to public bool seq_is_buf_full
The return values of seq_printf/puts/putc are frequently misused.
Start down a path to remove all the return value uses of these functions.
Make the static bool seq_overflow public along with a rename of the function to seq_is_buf_full. Rename the still static seq_set_overflow to seq_set_buf_full.
Update the documentation to not show return types for seq_printf et al. Add a description of seq_is_buf_full.
--- Documentation/filesystems/seq_file.txt | 28 ++++++++++++++++------------ fs/seq_file.c | 28 ++++++++++++++-------------- include/linux/seq_file.h | 8 ++++++++ 3 files changed, 38 insertions(+), 26 deletions(-)
Documentation/filesystems/seq_file.txt +16 -12
@@ -171,27 +171,23 @@ output must be passed to the seq_file code. Some utility functions have been defined which make this task easy. Most code will simply use seq_printf(), which works pretty much like -printk(), but which requires the seq_file pointer as an argument. It is -common to ignore the return value from seq_printf(), but a function -producing complicated output may want to check that value and quit if -something non-zero is returned; an error return means that the seq_file -buffer has been filled and further output will be discarded. +printk(), but which requires the seq_file pointer as an argument. For straight character output, the following functions may be used: - int seq_putc(struct seq_file *m, char c); - int seq_puts(struct seq_file *m, const char *s); - int seq_escape(struct seq_file *m, const char *s, const char *esc); + seq_putc(struct seq_file *m, char c); + seq_puts(struct seq_file *m, const char *s); + seq_escape(struct seq_file *m, const char *s, const char *esc); The first two output a single character and a string, just like one would expect. seq_escape() is like seq_puts(), except that any character in s which is in the string esc will be represented in octal form in the output. -There is also a pair of functions for printing filenames: +There are also a pair of functions for printing filenames: - int seq_path(struct seq_file *m, struct path *path, char *esc); - int seq_path_root(struct seq_file *m, struct path *path, - struct path *root, char *esc) + seq_path(struct seq_file *m, struct path *path, char *esc); + seq_path_root(struct seq_file *m, struct path *path, + struct path *root, char *esc) Here, path indicates the file of interest, and esc is a set of characters which should be escaped in the output. A call to seq_path() will output
@@ -200,6 +196,14 @@ root is desired, it can be used with seq_path_root(). Note that, if it turns out that path cannot be reached from root, the value of root will be changed in seq_file_root() to a root which *does* work. +A function producing complicated output may want to check + bool seq_is_buf_full(struct seq_file *m); +and avoid further seq_<output> calls if true is returned. + +A true return from seq_is_buf_full means that the seq_file buffer is full +and further output will be discarded. The seq_show function will attempt +to allocate a larger buffer and retry printing. + Making it all work
fs/seq_file.c +14 -14
@@ -14,18 +14,18 @@#include <asm/uaccess.h> #include <asm/page.h> -/* -* seq_files have a buffer which can may overflow. When this happens a larger +* seq_files have a buffer which may overflow. When this happens a larger * buffer is reallocated and all the data will be printed again. * The overflow state is true when m->count == m->size. */ -static bool seq_overflow (struct seq_file *m) +bool seq_is_buf_full (struct seq_file *m) {return m->count == m->size; } +EXPORT_SYMBOL (seq_is_buf_full); -static void seq_set_overflow (struct seq_file *m) +static void seq_set_buf_full (struct seq_file *m) { m->count = m->size; }
@@ -112,7 +112,7 @@ static int traverse(struct seq_file *m, loff_t offset) error =0 ; m->count =0 ; } -if (seq_overflow (m)) +if (seq_is_buf_full (m)) goto Eoverflow;if (pos + m->count > offset) { m->from = offset - pos;
@@ -255,7 +255,7 @@ Fill:break ; } err = m->op->show (m, p); -if (seq_overflow (m) || err) { +if (seq_is_buf_full (m) || err) { m->count = offs;if (likely (err <=0 ))break ;
@@ -384,7 +384,7 @@ int seq_escape(struct seq_file *m, const char *s, const char *esc) *p++ ='0' + (c &07 );continue ; } -seq_set_overflow (m); +seq_set_buf_full (m);return -1 ; } m->count = p - m->buf;
@@ -403,7 +403,7 @@ int seq_vprintf(struct seq_file *m, const char *f, va_list args)return 0 ; } } -seq_set_overflow (m); +seq_set_buf_full (m);return -1 ; }EXPORT_SYMBOL (seq_vprintf);
@@ -545,7 +545,7 @@ int seq_bitmap(struct seq_file *m, const unsigned long *bits,return 0 ; } } -seq_set_overflow (m); +seq_set_buf_full (m);return -1 ; }EXPORT_SYMBOL (seq_bitmap);
@@ -561,7 +561,7 @@ int seq_bitmap_list(struct seq_file *m, const unsigned long *bits,return 0 ; } } -seq_set_overflow (m); +seq_set_buf_full (m);return -1 ; }EXPORT_SYMBOL (seq_bitmap_list);
@@ -690,7 +690,7 @@ int seq_puts(struct seq_file *m, const char *s) m->count += len;return 0 ; } -seq_set_overflow (m); +seq_set_buf_full (m);return -1 ; }EXPORT_SYMBOL (seq_puts);
@@ -724,7 +724,7 @@ int seq_put_decimal_ull(struct seq_file *m, char delimiter, m->count += len;return 0 ; overflow: -seq_set_overflow (m); +seq_set_buf_full (m);return -1 ; }EXPORT_SYMBOL (seq_put_decimal_ull);
@@ -734,7 +734,7 @@ int seq_put_decimal_ll(struct seq_file *m, char delimiter, {if (num <0 ) {if (m->count +3 >= m->size) { -seq_set_overflow (m); +seq_set_buf_full (m);return -1 ; }if (delimiter)
@@ -762,7 +762,7 @@ int seq_write(struct seq_file *seq, const void *data, size_t len) seq->count += len;return 0 ; } -seq_set_overflow (seq); +seq_set_buf_full (seq);return -1 ; }EXPORT_SYMBOL (seq_write);
include/linux/seq_file.h +8 -0
@@ -43,6 +43,14 @@ struct seq_operations {#define SEQ_SKIP 1/** +* seq_is_buf_full - check if the buffer associated to seq_file is full +* @m: the seq_file handle +* +* Returns true if the buffer is full +*/ +bool seq_is_buf_full (struct seq_file *m); + +/** * seq_get_buf - get buffer to write arbitrary data to * @m: the seq_file handle * @bufp: the beginning of the buffer is stored here
Signature · 1 line
1.8.1.2.459.gbcd45b4.dirty
PATCH 2/2 netfilter: Convert print_tuple functions to return void
In reply to Joe PerchesSince adding a new function to seq_file (seq_is_buf_full) there isn't any value for functions called from seq_show to
return anything. Remove the int returns of the various
print_tuple/<foo>_print_tuple functions.
--- include/net/netfilter/nf_conntrack_core.h | 2 +- include/net/netfilter/nf_conntrack_l3proto.h | 4 ++-- include/net/netfilter/nf_conntrack_l4proto.h | 4 ++-- net/netfilter/nf_conntrack_l3proto_generic.c | 5 ++--- net/netfilter/nf_conntrack_proto_dccp.c | 10 +++++----- net/netfilter/nf_conntrack_proto_generic.c | 5 ++--- net/netfilter/nf_conntrack_proto_gre.c | 10 +++++----- net/netfilter/nf_conntrack_proto_sctp.c | 10 +++++----- net/netfilter/nf_conntrack_proto_tcp.c | 10 +++++----- net/netfilter/nf_conntrack_proto_udp.c | 10 +++++----- net/netfilter/nf_conntrack_proto_udplite.c | 10 +++++----- net/netfilter/nf_conntrack_standalone.c | 15 +++++++-------- 12 files changed, 46 insertions(+), 49 deletions(-)
include/net/netfilter/nf_conntrack_core.h +1 -1
@@ -72,7 +72,7 @@ static inline int nf_conntrack_confirm(struct sk_buff *skb)return ret; } -int +void print_tuple (struct seq_file *s,const struct nf_conntrack_tuple *tuple,const struct nf_conntrack_l3proto *l3proto,const struct nf_conntrack_l4proto *proto);
include/net/netfilter/nf_conntrack_l3proto.h +2 -2
@@ -38,8 +38,8 @@ struct nf_conntrack_l3proto { const struct nf_conntrack_tuple *orig);/* Print out the per-protocol part of the tuple. */ -int (*print_tuple)(struct seq_file *s, -const struct nf_conntrack_tuple *); +void (*print_tuple)(struct seq_file *s, +const struct nf_conntrack_tuple *);/* * Called before tracking.
include/net/netfilter/nf_conntrack_l4proto.h +2 -2
@@ -56,8 +56,8 @@ struct nf_conntrack_l4proto { u_int8_t pf, unsigned int hooknum);/* Print out the per-protocol part of the tuple. Return like seq_* */ -int (*print_tuple)(struct seq_file *s, -const struct nf_conntrack_tuple *); +void (*print_tuple)(struct seq_file *s, +const struct nf_conntrack_tuple *);/* Print out the private part of the conntrack. */ int (*print_conntrack)(struct seq_file *s,struct nf_conn *);
net/netfilter/nf_conntrack_l3proto_generic.c +2 -3
@@ -49,10 +49,9 @@ static bool generic_invert_tuple(struct nf_conntrack_tuple *tuple,return true; } -static int generic_print_tuple (struct seq_file *s, -const struct nf_conntrack_tuple *tuple) +static void generic_print_tuple (struct seq_file *s, +const struct nf_conntrack_tuple *tuple) { -return 0 ; } static int generic_get_l4proto(const struct sk_buff *skb, unsigned int nhoff,
net/netfilter/nf_conntrack_proto_dccp.c +5 -5
@@ -618,12 +618,12 @@ out_invalid:return -NF_ACCEPT ; } -static int dccp_print_tuple (struct seq_file *s, -const struct nf_conntrack_tuple *tuple) +static void dccp_print_tuple (struct seq_file *s, +const struct nf_conntrack_tuple *tuple) { -return seq_printf (s,"sport=%hu dport=%hu " , -ntohs (tuple->src.u.dccp.port), -ntohs (tuple->dst.u.dccp.port)); +seq_printf (s,"sport=%hu dport=%hu " , +ntohs (tuple->src.u.dccp.port), +ntohs (tuple->dst.u.dccp.port)); }static int dccp_print_conntrack (struct seq_file *s,struct nf_conn *ct)
net/netfilter/nf_conntrack_proto_generic.c +2 -3
@@ -39,10 +39,9 @@ static bool generic_invert_tuple(struct nf_conntrack_tuple *tuple, }/* Print out the per-protocol part of the tuple. */ -static int generic_print_tuple (struct seq_file *s, -const struct nf_conntrack_tuple *tuple) +static void generic_print_tuple (struct seq_file *s, +const struct nf_conntrack_tuple *tuple) { -return 0 ; }static unsigned int *generic_get_timeouts (struct net *net)
net/netfilter/nf_conntrack_proto_gre.c +5 -5
@@ -227,12 +227,12 @@ static bool gre_pkt_to_tuple(const struct sk_buff *skb, unsigned int dataoff, }/* print gre part of tuple */ -static int gre_print_tuple (struct seq_file *s, -const struct nf_conntrack_tuple *tuple) +static void gre_print_tuple (struct seq_file *s, +const struct nf_conntrack_tuple *tuple) { -return seq_printf (s,"srckey=0x%x dstkey=0x%x " , -ntohs (tuple->src.u.gre.key), -ntohs (tuple->dst.u.gre.key)); +seq_printf (s,"srckey=0x%x dstkey=0x%x " , +ntohs (tuple->src.u.gre.key), +ntohs (tuple->dst.u.gre.key)); }/* print private data for conntrack */
net/netfilter/nf_conntrack_proto_sctp.c +5 -5
@@ -166,12 +166,12 @@ static bool sctp_invert_tuple(struct nf_conntrack_tuple *tuple, }/* Print out the per-protocol part of the tuple. */ -static int sctp_print_tuple (struct seq_file *s, -const struct nf_conntrack_tuple *tuple) +static void sctp_print_tuple (struct seq_file *s, +const struct nf_conntrack_tuple *tuple) { -return seq_printf (s,"sport=%hu dport=%hu " , -ntohs (tuple->src.u.sctp.port), -ntohs (tuple->dst.u.sctp.port)); +seq_printf (s,"sport=%hu dport=%hu " , +ntohs (tuple->src.u.sctp.port), +ntohs (tuple->dst.u.sctp.port)); }/* Print out the private part of the conntrack. */
net/netfilter/nf_conntrack_proto_tcp.c +5 -5
@@ -302,12 +302,12 @@ static bool tcp_invert_tuple(struct nf_conntrack_tuple *tuple, }/* Print out the per-protocol part of the tuple. */ -static int tcp_print_tuple (struct seq_file *s, -const struct nf_conntrack_tuple *tuple) +static void tcp_print_tuple (struct seq_file *s, +const struct nf_conntrack_tuple *tuple) { -return seq_printf (s,"sport=%hu dport=%hu " , -ntohs (tuple->src.u.tcp.port), -ntohs (tuple->dst.u.tcp.port)); +seq_printf (s,"sport=%hu dport=%hu " , +ntohs (tuple->src.u.tcp.port), +ntohs (tuple->dst.u.tcp.port)); }/* Print out the private part of the conntrack. */
net/netfilter/nf_conntrack_proto_udp.c +5 -5
@@ -63,12 +63,12 @@ static bool udp_invert_tuple(struct nf_conntrack_tuple *tuple, }/* Print out the per-protocol part of the tuple. */ -static int udp_print_tuple (struct seq_file *s, -const struct nf_conntrack_tuple *tuple) +static void udp_print_tuple (struct seq_file *s, +const struct nf_conntrack_tuple *tuple) { -return seq_printf (s,"sport=%hu dport=%hu " , -ntohs (tuple->src.u.udp.port), -ntohs (tuple->dst.u.udp.port)); +seq_printf (s,"sport=%hu dport=%hu " , +ntohs (tuple->src.u.udp.port), +ntohs (tuple->dst.u.udp.port)); }static unsigned int *udp_get_timeouts (struct net *net)
net/netfilter/nf_conntrack_proto_udplite.c +5 -5
@@ -71,12 +71,12 @@ static bool udplite_invert_tuple(struct nf_conntrack_tuple *tuple, }/* Print out the per-protocol part of the tuple. */ -static int udplite_print_tuple (struct seq_file *s, -const struct nf_conntrack_tuple *tuple) +static void udplite_print_tuple (struct seq_file *s, +const struct nf_conntrack_tuple *tuple) { -return seq_printf (s,"sport=%hu dport=%hu " , -ntohs (tuple->src.u.udp.port), -ntohs (tuple->dst.u.udp.port)); +seq_printf (s,"sport=%hu dport=%hu " , +ntohs (tuple->src.u.udp.port), +ntohs (tuple->dst.u.udp.port)); }static unsigned int *udplite_get_timeouts (struct net *net)
net/netfilter/nf_conntrack_standalone.c +7 -8
@@ -36,12 +36,13 @@MODULE_LICENSE ("GPL" );#ifdef CONFIG_NF_CONNTRACK_PROCFS -int +void print_tuple (struct seq_file *s,const struct nf_conntrack_tuple *tuple,const struct nf_conntrack_l3proto *l3proto,const struct nf_conntrack_l4proto *l4proto) { -return l3proto->print_tuple (s, tuple) || l4proto->print_tuple (s, tuple); + l3proto->print_tuple (s, tuple); + l4proto->print_tuple (s, tuple); }EXPORT_SYMBOL_GPL (print_tuple);
@@ -202,9 +203,8 @@ static int ct_seq_show(struct seq_file *s, void *v)if (l4proto->print_conntrack && l4proto->print_conntrack (s, ct)) goto release; -if (print_tuple (s, &ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple, - l3proto, l4proto)) - goto release; +print_tuple (s, &ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple, + l3proto, l4proto);if (seq_print_acct (s, ct,IP_CT_DIR_ORIGINAL )) goto release;
@@ -213,9 +213,8 @@ static int ct_seq_show(struct seq_file *s, void *v)if (seq_printf (s,"[UNREPLIED] " )) goto release; -if (print_tuple (s, &ct->tuplehash[IP_CT_DIR_REPLY ].tuple, - l3proto, l4proto)) - goto release; +print_tuple (s, &ct->tuplehash[IP_CT_DIR_REPLY ].tuple, + l3proto, l4proto);if (seq_print_acct (s, ct,IP_CT_DIR_REPLY )) goto release;
Signature · 1 line
1.8.1.2.459.gbcd45b4.dirty
cover fs: Use seq_is_buf_full
In reply to Joe PerchesConvert the fs uses and misuses of seq_printf to void
These patches depend on https://lkml.org/lkml/2013/12/11/714
Joe Perches (4):
dlm: Use seq_is_buf_full - remove seq_printf returns
dlm: Use seq_puts, remove unnecessary trailing spaces
fs: Convert show_fdinfo functions to void
debugfs: Fix misuse of seq_printf return value
fs/debugfs/file.c | 14 +-- fs/dlm/debug_fs.c | 274 +++++++++++++++++++++++++---------------------------- fs/eventfd.c | 15 +-- fs/eventpoll.c | 19 ++-- fs/notify/fdinfo.c | 68 ++++++------- fs/notify/fdinfo.h | 4 +- fs/proc/fd.c | 2 +- fs/signalfd.c | 10 +- include/linux/fs.h | 2 +- 9 files changed, 184 insertions(+), 224 deletions(-)
Signature · 1 line
1.8.1.2.459.gbcd45b4.dirty
PATCH 1/4 dlm: Use seq_is_buf_full - remove seq_printf returns
In reply to Joe PerchesThe seq_printf return should be ignored and the seq_is_buf_full function should be tested instead.
Convert functions returning int to void whereseq_printf is used.
--- fs/dlm/debug_fs.c | 248 +++++++++++++++++++++++++----------------------------- 1 file changed, 116 insertions(+), 132 deletions(-)
fs/dlm/debug_fs.c +116 -132
@@ -48,8 +48,8 @@ static char *print_lockmode(int mode) } } -static int print_format1_lock (struct seq_file *s,struct dlm_lkb *lkb, -struct dlm_rsb *res) +static void print_format1_lock (struct seq_file *s,struct dlm_lkb *lkb, +struct dlm_rsb *res) {seq_printf (s,"%08x %s" , lkb->lkb_id,print_lockmode (lkb->lkb_grmode));
@@ -68,21 +68,17 @@ static int print_format1_lock(struct seq_file *s, struct dlm_lkb *lkb,if (lkb->lkb_wait_type)seq_printf (s," wait_type: %d" , lkb->lkb_wait_type); -return seq_printf (s,"\n" ); +seq_puts (s,"\n" ); } -static int print_format1 (struct dlm_rsb *res,struct seq_file *s) +static void print_format1 (struct dlm_rsb *res,struct seq_file *s) {struct dlm_lkb *lkb;int i, lvblen = res->res_ls->ls_lvblen, recover_list, root_list; -int rv;lock_rsb (res); - rv =seq_printf (s,"\nResource %p Name (len=%d) \"" , - res, res->res_length); -if (rv) - goto out; +seq_printf (s,"\nResource %p Name (len=%d) \"" , res, res->res_length);for (i =0 ; i < res->res_length; i++) {if (isprint (res->res_name[i]))
@@ -92,17 +88,16 @@ static int print_format1(struct dlm_rsb *res, struct seq_file *s) }if (res->res_nodeid >0 ) - rv =seq_printf (s,"\" \nLocal Copy, Master is node %d\n" , - res->res_nodeid); +seq_printf (s,"\" \nLocal Copy, Master is node %d\n" , + res->res_nodeid);else if (res->res_nodeid ==0 ) - rv =seq_printf (s,"\" \nMaster Copy\n" ); +seq_puts (s,"\" \nMaster Copy\n" );else if (res->res_nodeid ==-1 ) - rv =seq_printf (s,"\" \nLooking up master (lkid %x)\n" , - res->res_first_lkid); +seq_printf (s,"\" \nLooking up master (lkid %x)\n" , + res->res_first_lkid);else - rv =seq_printf (s,"\" \nInvalid master %d\n" , - res->res_nodeid); -if (rv) +seq_printf (s,"\" \nInvalid master %d\n" , res->res_nodeid); +if (seq_is_buf_full (s)) goto out;/* Print the LVB: */
@@ -116,8 +111,8 @@ static int print_format1(struct dlm_rsb *res, struct seq_file *s) }if (rsb_flag (res,RSB_VALNOTVALID ))seq_printf (s," (INVALID)" ); - rv =seq_printf (s,"\n" ); -if (rv) +seq_puts (s,"\n" ); +if (seq_is_buf_full (s)) goto out; }
@@ -125,32 +120,30 @@ static int print_format1(struct dlm_rsb *res, struct seq_file *s) recover_list = !list_empty (&res->res_recover_list);if (root_list || recover_list) { - rv =seq_printf (s,"Recovery: root %d recover %d flags %lx " -"count %d\n" , root_list, recover_list, - res->res_flags, res->res_recover_locks_count); -if (rv) - goto out; +seq_printf (s,"Recovery: root %d recover %d flags %lx count %d\n" , + root_list, recover_list, + res->res_flags, res->res_recover_locks_count); }/* Print the locks attached to this resource */ seq_printf (s,"Granted Queue\n" );list_for_each_entry (lkb, &res->res_grantqueue, lkb_statequeue) { - rv =print_format1_lock (s, lkb, res); -if (rv) +print_format1_lock (s, lkb, res); +if (seq_is_buf_full (s)) goto out; }seq_printf (s,"Conversion Queue\n" );list_for_each_entry (lkb, &res->res_convertqueue, lkb_statequeue) { - rv =print_format1_lock (s, lkb, res); -if (rv) +print_format1_lock (s, lkb, res); +if (seq_is_buf_full (s)) goto out; }seq_printf (s,"Waiting Queue\n" );list_for_each_entry (lkb, &res->res_waitqueue, lkb_statequeue) { - rv =print_format1_lock (s, lkb, res); -if (rv) +print_format1_lock (s, lkb, res); +if (seq_is_buf_full (s)) goto out; }
@@ -159,23 +152,23 @@ static int print_format1(struct dlm_rsb *res, struct seq_file *s)seq_printf (s,"Lookup Queue\n" );list_for_each_entry (lkb, &res->res_lookup, lkb_rsb_lookup) { - rv =seq_printf (s,"%08x %s" , lkb->lkb_id, -print_lockmode (lkb->lkb_rqmode)); +seq_printf (s,"%08x %s" , + lkb->lkb_id,print_lockmode (lkb->lkb_rqmode));if (lkb->lkb_wait_type)seq_printf (s," wait_type: %d" , lkb->lkb_wait_type); - rv =seq_printf (s,"\n" ); +seq_puts (s,"\n" ); +if (seq_is_buf_full (s)) + goto out; } out:unlock_rsb (res); -return rv; } -static int print_format2_lock (struct seq_file *s,struct dlm_lkb *lkb, -struct dlm_rsb *r) +static void print_format2_lock (struct seq_file *s,struct dlm_lkb *lkb, +struct dlm_rsb *r) {u64 xid =0 ;u64 us; -int rv;if (lkb->lkb_flags &DLM_IFL_USER ) {if (lkb->lkb_ua)
@@ -188,103 +181,97 @@ static int print_format2_lock(struct seq_file *s, struct dlm_lkb *lkb,/* id nodeid remid pid xid exflags flags sts grmode rqmode time_us r_nodeid r_len r_name */ - rv =seq_printf (s,"%x %d %x %u %llu %x %x %d %d %d %llu %u %d \"%s\"\n" , - lkb->lkb_id, - lkb->lkb_nodeid, - lkb->lkb_remid, - lkb->lkb_ownpid, - (unsigned long long )xid, - lkb->lkb_exflags, - lkb->lkb_flags, - lkb->lkb_status, - lkb->lkb_grmode, - lkb->lkb_rqmode, - (unsigned long long )us, - r->res_nodeid, - r->res_length, - r->res_name); -return rv; +seq_printf (s,"%x %d %x %u %llu %x %x %d %d %d %llu %u %d \"%s\"\n" , + lkb->lkb_id, + lkb->lkb_nodeid, + lkb->lkb_remid, + lkb->lkb_ownpid, + (unsigned long long )xid, + lkb->lkb_exflags, + lkb->lkb_flags, + lkb->lkb_status, + lkb->lkb_grmode, + lkb->lkb_rqmode, + (unsigned long long )us, + r->res_nodeid, + r->res_length, + r->res_name); } -static int print_format2 (struct dlm_rsb *r,struct seq_file *s) +static void print_format2 (struct dlm_rsb *r,struct seq_file *s) {struct dlm_lkb *lkb; -int rv =0 ;lock_rsb (r);list_for_each_entry (lkb, &r->res_grantqueue, lkb_statequeue) { - rv =print_format2_lock (s, lkb, r); -if (rv) +print_format2_lock (s, lkb, r); +if (seq_is_buf_full (s)) goto out; }list_for_each_entry (lkb, &r->res_convertqueue, lkb_statequeue) { - rv =print_format2_lock (s, lkb, r); -if (rv) +print_format2_lock (s, lkb, r); +if (seq_is_buf_full (s)) goto out; }list_for_each_entry (lkb, &r->res_waitqueue, lkb_statequeue) { - rv =print_format2_lock (s, lkb, r); -if (rv) +print_format2_lock (s, lkb, r); +if (seq_is_buf_full (s)) goto out; } out:unlock_rsb (r); -return rv; } -static int print_format3_lock (struct seq_file *s,struct dlm_lkb *lkb, +static void print_format3_lock (struct seq_file *s,struct dlm_lkb *lkb,int rsb_lookup) {u64 xid =0 ; -int rv;if (lkb->lkb_flags &DLM_IFL_USER ) {if (lkb->lkb_ua) xid = lkb->lkb_ua->xid; } - rv =seq_printf (s,"lkb %x %d %x %u %llu %x %x %d %d %d %d %d %d %u %llu %llu\n" , - lkb->lkb_id, - lkb->lkb_nodeid, - lkb->lkb_remid, - lkb->lkb_ownpid, - (unsigned long long )xid, - lkb->lkb_exflags, - lkb->lkb_flags, - lkb->lkb_status, - lkb->lkb_grmode, - lkb->lkb_rqmode, - lkb->lkb_last_bast.mode, - rsb_lookup, - lkb->lkb_wait_type, - lkb->lkb_lvbseq, - (unsigned long long )ktime_to_ns (lkb->lkb_timestamp), - (unsigned long long )ktime_to_ns (lkb->lkb_last_bast_time)); -return rv; +seq_printf (s,"lkb %x %d %x %u %llu %x %x %d %d %d %d %d %d %u %llu %llu\n" , + lkb->lkb_id, + lkb->lkb_nodeid, + lkb->lkb_remid, + lkb->lkb_ownpid, + (unsigned long long )xid, + lkb->lkb_exflags, + lkb->lkb_flags, + lkb->lkb_status, + lkb->lkb_grmode, + lkb->lkb_rqmode, + lkb->lkb_last_bast.mode, + rsb_lookup, + lkb->lkb_wait_type, + lkb->lkb_lvbseq, + (unsigned long long )ktime_to_ns (lkb->lkb_timestamp), + (unsigned long long )ktime_to_ns (lkb->lkb_last_bast_time)); } -static int print_format3 (struct dlm_rsb *r,struct seq_file *s) +static void print_format3 (struct dlm_rsb *r,struct seq_file *s) {struct dlm_lkb *lkb;int i, lvblen = r->res_ls->ls_lvblen;int print_name =1 ; -int rv;lock_rsb (r); - rv =seq_printf (s,"rsb %p %d %x %lx %d %d %u %d " , - r, - r->res_nodeid, - r->res_first_lkid, - r->res_flags, - !list_empty (&r->res_root_list), - !list_empty (&r->res_recover_list), - r->res_recover_locks_count, - r->res_length); -if (rv) +seq_printf (s,"rsb %p %d %x %lx %d %d %u %d " , + r, + r->res_nodeid, + r->res_first_lkid, + r->res_flags, + !list_empty (&r->res_root_list), + !list_empty (&r->res_recover_list), + r->res_recover_locks_count, + r->res_length); +if (seq_is_buf_full (s)) goto out;for (i =0 ; i < r->res_length; i++) {
@@ -300,8 +287,8 @@ static int print_format3(struct dlm_rsb *r, struct seq_file *s)else seq_printf (s," %02x" , (unsigned char )r->res_name[i]); } - rv =seq_printf (s,"\n" ); -if (rv) +seq_puts (s,"\n" ); +if (seq_is_buf_full (s)) goto out;if (!r->res_lvbptr)
@@ -311,58 +298,55 @@ static int print_format3(struct dlm_rsb *r, struct seq_file *s)for (i =0 ; i < lvblen; i++)seq_printf (s," %02x" , (unsigned char )r->res_lvbptr[i]); - rv =seq_printf (s,"\n" ); -if (rv) +seq_puts (s,"\n" ); +if (seq_is_buf_full (s)) goto out; do_locks:list_for_each_entry (lkb, &r->res_grantqueue, lkb_statequeue) { - rv =print_format3_lock (s, lkb,0 ); -if (rv) +print_format3_lock (s, lkb,0 ); +if (seq_is_buf_full (s)) goto out; }list_for_each_entry (lkb, &r->res_convertqueue, lkb_statequeue) { - rv =print_format3_lock (s, lkb,0 ); -if (rv) +print_format3_lock (s, lkb,0 ); +if (seq_is_buf_full (s)) goto out; }list_for_each_entry (lkb, &r->res_waitqueue, lkb_statequeue) { - rv =print_format3_lock (s, lkb,0 ); -if (rv) +print_format3_lock (s, lkb,0 ); +if (seq_is_buf_full (s)) goto out; }list_for_each_entry (lkb, &r->res_lookup, lkb_rsb_lookup) { - rv =print_format3_lock (s, lkb,1 ); -if (rv) +print_format3_lock (s, lkb,1 ); +if (seq_is_buf_full (s)) goto out; } out:unlock_rsb (r); -return rv; } -static int print_format4 (struct dlm_rsb *r,struct seq_file *s) +static void print_format4 (struct dlm_rsb *r,struct seq_file *s) {int our_nodeid =dlm_our_nodeid ();int print_name =1 ; -int i, rv; +int i;lock_rsb (r); - rv =seq_printf (s,"rsb %p %d %d %d %d %lu %lx %d " , - r, - r->res_nodeid, - r->res_master_nodeid, - r->res_dir_nodeid, - our_nodeid, - r->res_toss_time, - r->res_flags, - r->res_length); -if (rv) - goto out; +seq_printf (s,"rsb %p %d %d %d %d %lu %lx %d " , + r, + r->res_nodeid, + r->res_master_nodeid, + r->res_dir_nodeid, + our_nodeid, + r->res_toss_time, + r->res_flags, + r->res_length);for (i =0 ; i < r->res_length; i++) {if (!isascii (r->res_name[i]) || !isprint (r->res_name[i]))
@@ -377,10 +361,9 @@ static int print_format4(struct dlm_rsb *r, struct seq_file *s)else seq_printf (s," %02x" , (unsigned char )r->res_name[i]); } - rv =seq_printf (s,"\n" ); - out: +seq_puts (s,"\n" ); +unlock_rsb (r); -return rv; } struct rsbtbl_iter {
@@ -390,11 +373,12 @@ struct rsbtbl_iter {int header; }; -/* seq_printf returns -1 if the buffer is full, and 0 otherwise. -If the buffer is full, seq_printf can be called again, but it -does nothing and just returns -1. So, the these printing routines -periodically check the return value to avoid wasting too much time -trying to print to a full buffer. */ +/* +* If the buffer is full, seq_printf can be called again, but it +* does nothing. So, the these printing routines periodically check +* seq_is_buf_full to avoid wasting too much time trying to print to +* a full buffer. +*/ static int table_seq_show (struct seq_file *seq,void *iter_ptr) {
@@ -403,7 +387,7 @@ static int table_seq_show(struct seq_file *seq, void *iter_ptr)switch (ri->format) {case 1 : - rv =print_format1 (ri->rsb, seq); +print_format1 (ri->rsb, seq);break ;case 2 :if (ri->header) {
@@ -412,21 +396,21 @@ static int table_seq_show(struct seq_file *seq, void *iter_ptr) "r_nodeid r_len r_name\n"); ri->header =0 ; } - rv =print_format2 (ri->rsb, seq); +print_format2 (ri->rsb, seq);break ;case 3 :if (ri->header) {seq_printf (seq,"version rsb 1.1 lvb 1.1 lkb 1.1\n" ); ri->header =0 ; } - rv =print_format3 (ri->rsb, seq); +print_format3 (ri->rsb, seq);break ;case 4 :if (ri->header) {seq_printf (seq,"version 4 rsb 2\n" ); ri->header =0 ; } - rv =print_format4 (ri->rsb, seq); +print_format4 (ri->rsb, seq);break ; }
Signature · 1 line
1.8.1.2.459.gbcd45b4.dirty
PATCH 2/4 dlm: Use seq_puts, remove unnecessary trailing spaces
In reply to Joe PerchesConvert the seq_printf output with constant strings to seq_puts. Remove unnecessary trailing spaces from seq_(printf/puts) output.
--- fs/dlm/debug_fs.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-)
fs/dlm/debug_fs.c +16 -18
@@ -88,29 +88,29 @@ static void print_format1(struct dlm_rsb *res, struct seq_file *s) }if (res->res_nodeid >0 ) -seq_printf (s,"\" \nLocal Copy, Master is node %d\n" , +seq_printf (s,"\"\nLocal Copy, Master is node %d\n" , res->res_nodeid);else if (res->res_nodeid ==0 ) -seq_puts (s,"\" \nMaster Copy\n" ); +seq_puts (s,"\"\nMaster Copy\n" );else if (res->res_nodeid ==-1 ) -seq_printf (s,"\" \nLooking up master (lkid %x)\n" , +seq_printf (s,"\"\nLooking up master (lkid %x)\n" , res->res_first_lkid);else -seq_printf (s,"\" \nInvalid master %d\n" , res->res_nodeid); +seq_printf (s,"\"\nInvalid master %d\n" , res->res_nodeid);if (seq_is_buf_full (s)) goto out;/* Print the LVB: */ if (res->res_lvbptr) { -seq_printf (s,"LVB: " ); +seq_puts (s,"LVB: " );for (i =0 ; i < lvblen; i++) {if (i == lvblen /2 ) -seq_printf (s,"\n " ); +seq_puts (s,"\n " );seq_printf (s,"%02x " , (unsigned char ) res->res_lvbptr[i]); }if (rsb_flag (res,RSB_VALNOTVALID )) -seq_printf (s," (INVALID)" ); +seq_puts (s," (INVALID)" );seq_puts (s,"\n" );if (seq_is_buf_full (s)) goto out;
@@ -126,21 +126,21 @@ static void print_format1(struct dlm_rsb *res, struct seq_file *s) }/* Print the locks attached to this resource */ -seq_printf (s,"Granted Queue\n" ); +seq_puts (s,"Granted Queue\n" );list_for_each_entry (lkb, &res->res_grantqueue, lkb_statequeue) {print_format1_lock (s, lkb, res);if (seq_is_buf_full (s)) goto out; } -seq_printf (s,"Conversion Queue\n" ); +seq_puts (s,"Conversion Queue\n" );list_for_each_entry (lkb, &res->res_convertqueue, lkb_statequeue) {print_format1_lock (s, lkb, res);if (seq_is_buf_full (s)) goto out; } -seq_printf (s,"Waiting Queue\n" ); +seq_puts (s,"Waiting Queue\n" );list_for_each_entry (lkb, &res->res_waitqueue, lkb_statequeue) {print_format1_lock (s, lkb, res);if (seq_is_buf_full (s))
@@ -150,7 +150,7 @@ static void print_format1(struct dlm_rsb *res, struct seq_file *s)if (list_empty (&res->res_lookup)) goto out; -seq_printf (s,"Lookup Queue\n" ); +seq_puts (s,"Lookup Queue\n" );list_for_each_entry (lkb, &res->res_lookup, lkb_rsb_lookup) {seq_printf (s,"%08x %s" , lkb->lkb_id,print_lockmode (lkb->lkb_rqmode));
@@ -279,7 +279,7 @@ static void print_format3(struct dlm_rsb *r, struct seq_file *s) print_name =0 ; } -seq_printf (s,"%s" , print_name ?"str " :"hex" ); +seq_puts (s, print_name ?"str " :"hex" );for (i =0 ; i < r->res_length; i++) {if (print_name)
@@ -353,7 +353,7 @@ static void print_format4(struct dlm_rsb *r, struct seq_file *s) print_name =0 ; } -seq_printf (s,"%s" , print_name ?"str " :"hex" ); +seq_puts (s, print_name ?"str " :"hex" );for (i =0 ; i < r->res_length; i++) {if (print_name)
@@ -391,23 +391,21 @@ static int table_seq_show(struct seq_file *seq, void *iter_ptr)break ;case 2 :if (ri->header) { -seq_printf (seq,"id nodeid remid pid xid exflags " -"flags sts grmode rqmode time_ms " -"r_nodeid r_len r_name\n" ); +seq_puts (seq,"id nodeid remid pid xid exflags flags sts grmode rqmode time_ms r_nodeid r_len r_name\n" ); ri->header =0 ; }print_format2 (ri->rsb, seq);break ;case 3 :if (ri->header) { -seq_printf (seq,"version rsb 1.1 lvb 1.1 lkb 1.1\n" ); +seq_puts (seq,"version rsb 1.1 lvb 1.1 lkb 1.1\n" ); ri->header =0 ; }print_format3 (ri->rsb, seq);break ;case 4 :if (ri->header) { -seq_printf (seq,"version 4 rsb 2\n" ); +seq_puts (seq,"version 4 rsb 2\n" ); ri->header =0 ; }print_format4 (ri->rsb, seq);
Signature · 1 line
1.8.1.2.459.gbcd45b4.dirty
PATCH 3/4 fs: Convert show_fdinfo functions to void
In reply to Joe Perchesseq_printf functions shouldn't really check the return value. Checking seq_is_buf_full occasionally is used instead.
--- fs/eventfd.c | 15 ++++-------- fs/eventpoll.c | 19 ++++++--------- fs/notify/fdinfo.c | 68 +++++++++++++++++++++++------------------------------- fs/notify/fdinfo.h | 4 ++-- fs/proc/fd.c | 2 +- fs/signalfd.c | 10 +++----- include/linux/fs.h | 2 +- 7 files changed, 48 insertions(+), 72 deletions(-)
fs/eventfd.c +5 -10
@@ -286,25 +286,20 @@ static ssize_t eventfd_write(struct file *file, const char __user *buf, size_t creturn res; } -#ifdef CONFIG_PROC_FS -static int eventfd_show_fdinfo (struct seq_file *m,struct file *f) +static void eventfd_show_fdinfo (struct seq_file *m,struct file *f) { +#ifdef CONFIG_PROC_FS struct eventfd_ctx *ctx = f->private_data; -int ret;spin_lock_irq (&ctx->wqh.lock); - ret =seq_printf (m,"eventfd-count: %16llx\n" , - (unsigned long long )ctx->count); +seq_printf (m,"eventfd-count: %16llx\n" , + (unsigned long long )ctx->count);spin_unlock_irq (&ctx->wqh.lock); - -return ret; -}#endif +}static const struct file_operations eventfd_fops = { -#ifdef CONFIG_PROC_FS .show_fdinfo = eventfd_show_fdinfo, -#endif .release = eventfd_release, .poll = eventfd_poll, .read = eventfd_read,
fs/eventpoll.c +7 -12
@@ -869,34 +869,29 @@ static unsigned int ep_eventpoll_poll(struct file *file, poll_table *wait)return pollflags !=-1 ? pollflags :0 ; } -#ifdef CONFIG_PROC_FS -static int ep_show_fdinfo (struct seq_file *m,struct file *f) +static void ep_show_fdinfo (struct seq_file *m,struct file *f) { +#ifdef CONFIG_PROC_FS struct eventpoll *ep = f->private_data;struct rb_node *rbp; -int ret =0 ;mutex_lock (&ep->mtx);for (rbp =rb_first (&ep->rbr); rbp; rbp =rb_next (rbp)) { struct epitem *epi = rb_entry(rbp, struct epitem, rbn); - ret =seq_printf (m,"tfd: %8d events: %8x data: %16llx\n" , - epi->ffd.fd, epi->event.events, - (long long )epi->event.data); -if (ret) +seq_printf (m,"tfd: %8d events: %8x data: %16llx\n" , + epi->ffd.fd, epi->event.events, + (long long )epi->event.data); +if (seq_is_buf_full (m))break ; }mutex_unlock (&ep->mtx); - -return ret; -}#endif +}/* File callbacks that implement the eventpoll file behaviour */ static const struct file_operations eventpoll_fops = { -#ifdef CONFIG_PROC_FS .show_fdinfo = ep_show_fdinfo, -#endif .release = ep_eventpoll_release, .poll = ep_eventpoll_poll, .llseek = noop_llseek,
fs/notify/fdinfo.c +29 -39
146 lines not on this page · raw message
fs/notify/fdinfo.h +2 -2
@@ -10,11 +10,11 @@ struct file;#ifdef CONFIG_PROC_FS #ifdef CONFIG_INOTIFY_USER -extern int inotify_show_fdinfo (struct seq_file *m,struct file *f); +void inotify_show_fdinfo (struct seq_file *m,struct file *f);#endif #ifdef CONFIG_FANOTIFY -extern int fanotify_show_fdinfo (struct seq_file *m,struct file *f); +void fanotify_show_fdinfo (struct seq_file *m,struct file *f);#endif #else /* CONFIG_PROC_FS */
fs/proc/fd.c +1 -1
@@ -51,7 +51,7 @@ static int seq_show(struct seq_file *m, void *v)seq_printf (m,"pos:\t%lli\nflags:\t0%o\n" , (long long )file->f_pos, f_flags);if (file->f_op->show_fdinfo) - ret = file->f_op->show_fdinfo (m, file); + file->f_op->show_fdinfo (m, file);fput (file); }
fs/signalfd.c +3 -7
@@ -229,24 +229,20 @@ static ssize_t signalfd_read(struct file *file, char __user *buf, size_t count,return total ? total: ret; } -#ifdef CONFIG_PROC_FS -static int signalfd_show_fdinfo (struct seq_file *m,struct file *f) +static void signalfd_show_fdinfo (struct seq_file *m,struct file *f) { +#ifdef CONFIG_PROC_FS struct signalfd_ctx *ctx = f->private_data;sigset_t sigmask; sigmask = ctx->sigmask;signotset (&sigmask);render_sigset_t (m,"sigmask:\t" , &sigmask); - -return 0 ; -}#endif +}static const struct file_operations signalfd_fops = { -#ifdef CONFIG_PROC_FS .show_fdinfo = signalfd_show_fdinfo, -#endif .release = signalfd_release, .poll = signalfd_poll, .read = signalfd_read,
include/linux/fs.h +1 -1
@@ -1546,7 +1546,7 @@ struct file_operations {int (*setlease)(struct file *,long ,struct file_lock **);long (*fallocate)(struct file *file,int mode,loff_t offset,loff_t len); -int (*show_fdinfo)(struct seq_file *m,struct file *f); +void (*show_fdinfo)(struct seq_file *m,struct file *f); };struct inode_operations {
Signature · 1 line
1.8.1.2.459.gbcd45b4.dirty
PATCH 4/4 debugfs: Fix misuse of seq_printf return value
In reply to Joe PerchesAdding repeated -1 to the return is not correct.
Use seq_is_buf_full to test for unnecessary seq_printf uses and always return 0.
--- fs/debugfs/file.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
fs/debugfs/file.c +8 -6
@@ -695,15 +695,17 @@ EXPORT_SYMBOL_GPL(debugfs_create_u32_array);int debugfs_print_regs32 (struct seq_file *s,const struct debugfs_reg32 *regs,int nregs,void __iomem *base,char *prefix) { -int i, ret =0 ; +int i;for (i =0 ; i < nregs; i++, regs++) { -if (prefix) - ret +=seq_printf (s,"%s" , prefix); - ret +=seq_printf (s,"%s = 0x%08x\n" , regs->name, -readl (base + regs->offset)); +seq_printf (s,"%s%s = 0x%08x\n" , + prefix ? prefix :"" , + regs->name,readl (base + regs->offset)); +if (seq_is_buf_full (s)) +break ; } -return ret; + +return 0 ; }EXPORT_SYMBOL_GPL (debugfs_print_regs32);
Signature · 1 line
1.8.1.2.459.gbcd45b4.dirty
Re: [PATCH -next 0/4] fs: Use seq_is_buf_full
In reply to Joe PerchesQuoted 9 lines · Joe Perches
Convert the fs uses and misuses of
seq_printfto voidThese patches depend on https://lkml.org/lkml/2013/12/11/714
Joe Perches (4):
dlm: Useseq_is_buf_full- removeseq_printfreturns
dlm: Useseq_puts, remove unnecessary trailing spaces
fs: Convertshow_fdinfofunctions to void
debugfs: Fix misuse ofseq_printfreturn value
Ping?
Quoted 11 lines
fs/debugfs/file.c | 14 +-- fs/dlm/debug_fs.c | 274 +++++++++++++++++++++++++---------------------------- fs/eventfd.c | 15 +-- fs/eventpoll.c | 19 ++-- fs/notify/fdinfo.c | 68 ++++++------- fs/notify/fdinfo.h | 4 +- fs/proc/fd.c | 2 +- fs/signalfd.c | 10 +- include/linux/fs.h | 2 +- 9 files changed, 184 insertions(+), 224 deletions(-)