lockdep: Fine-tuning for some function implementations
Subsystems (2)
cover lockdep: Fine-tuning for some function implementations
From: Markus Elfring <[email protected]>
Date: Wed, 3 May 2017 22:17:03 +0200
Some update suggestions were taken into account
from static source code analysis.
Markus Elfring (6):
Replace 11 seq_puts() calls by seq_putc()
Use seq_putc() in seq_header()
Replace four seq_printf() calls by seq_puts() Combine two seq_printf() calls into one call in l_show() Improve a size determination in lock_stat_open() Add spaces for better code readability
kernel/locking/lockdep_proc.c | 50 ++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 27 deletions(-)
Signature · 1 line
2.12.2
PATCH 1/6 lockdep: Replace 11 seq_puts() calls by seq_putc()
From: Markus Elfring <[email protected]>
Date: Wed, 3 May 2017 21:00:26 +0200
Some single characters should be put into a sequence. Thus use the corresponding function "seq_putc".
This issue was detected by using the Coccinelle software.
--- kernel/locking/lockdep_proc.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-)
kernel/locking/lockdep_proc.c +11 -13
@@ -81,15 +81,14 @@ static int l_show(struct seq_file *m, void *v)print_name (m, class); -seq_puts (m,"\n" ); +seq_putc (m,'\n' );list_for_each_entry (entry, &class->locks_after, entry) {if (entry->distance =1 ) {seq_printf (m," -> [%p] " , entry->class->key);print_name (m, entry->class); -seq_puts (m,"\n" ); +seq_putc (m,'\n' ); } } -seq_puts (m,"\n" ); - +seq_putc (m,'\n' );return 0 ; }
@@ -156,10 +155,9 @@ static int lc_show(struct seq_file *m, void *v)seq_printf (m,"[%p] " , class->key);print_name (m, class); -seq_puts (m,"\n" ); +seq_putc (m,'\n' ); } -seq_puts (m,"\n" ); - +seq_putc (m,'\n' );return 0 ; }
@@ -393,10 +391,10 @@ static void seq_line(struct seq_file *m, char c, int offset, int length)int i;for (i =0 ; i < offset; i++) -seq_puts (m," " ); +seq_putc (m,' ' );for (i =0 ; i < length; i++)seq_printf (m,"%c" , c); -seq_puts (m,"\n" ); +seq_putc (m,'\n' ); }static void snprint_time (char *buf,size_t bufsiz,s64 nr)
@@ -483,7 +481,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)seq_lock_time (m, &stats->write_waittime);seq_printf (m," %14lu " , stats->bounces[bounce_acquired_write]);seq_lock_time (m, &stats->write_holdtime); -seq_puts (m,"\n" ); +seq_putc (m,'\n' ); }if (stats->read_holdtime.nr) {
@@ -492,7 +490,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)seq_lock_time (m, &stats->read_waittime);seq_printf (m," %14lu " , stats->bounces[bounce_acquired_read]);seq_lock_time (m, &stats->read_holdtime); -seq_puts (m,"\n" ); +seq_putc (m,'\n' ); }if (stats->read_waittime.nr + stats->write_waittime.nr =0 )
@@ -532,9 +530,9 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data) ip, (void *)class->contending_point[i]); }if (i) { -seq_puts (m,"\n" ); +seq_putc (m,'\n' );seq_line (m,'.' ,0 ,40 +1 +12 * (14 +1 )); -seq_puts (m,"\n" ); +seq_putc (m,'\n' ); } }
Signature · 1 line
2.12.2
PATCH 2/6 lockdep: Use seq_putc() in seq_header()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 3 May 2017 21:30:26 +0200
A single character (line break) should be put into a sequence. Thus use the corresponding function "seq_putc".
This issue was detected by using the Coccinelle software.
--- kernel/locking/lockdep_proc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/locking/lockdep_proc.c +1 -1
@@ -560,7 +560,7 @@ static void seq_header(struct seq_file *m)"holdtime-total" , "holdtime-avg");seq_line (m,'-' ,0 ,40 +1 +12 * (14 +1 )); -seq_printf (m,"\n" ); +seq_putc (m,'\n' ); }static void *ls_start (struct seq_file *m,loff_t *pos)
Signature · 1 line
2.12.2
PATCH 3/6 lockdep: Replace four seq_printf() calls by seq_puts()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 3 May 2017 21:46:49 +0200
Four strings which did not contain data format specifications should be put into a sequence. Thus use the corresponding function "seq_puts".
This issue was detected by using the Coccinelle software.
--- kernel/locking/lockdep_proc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/locking/lockdep_proc.c +4 -4
@@ -61,7 +61,7 @@ static int l_show(struct seq_file *m, void *v)char usage[LOCK_USAGE_CHARS ];if (v = &all_lock_classes) { -seq_printf (m,"all lock classes:\n" ); +seq_puts (m,"all lock classes:\n" );return 0 ; }
@@ -141,8 +141,8 @@ static int lc_show(struct seq_file *m, void *v)if (v =SEQ_START_TOKEN ) {if (nr_chain_hlocks >MAX_LOCKDEP_CHAIN_HLOCKS ) -seq_printf (m,"(buggered) " ); -seq_printf (m,"all lock chains:\n" ); +seq_puts (m,"(buggered) " ); +seq_puts (m,"all lock chains:\n" );return 0 ; }
@@ -541,7 +541,7 @@ static void seq_header(struct seq_file *m)seq_puts (m,"lock_stat version 0.4\n" );if (unlikely (!debug_locks)) -seq_printf (m,"*WARNING* lock debugging disabled!! - possibly due to a lockdep warning\n" ); +seq_puts (m,"*WARNING* lock debugging disabled!! - possibly due to a lockdep warning\n" );seq_line (m,'-' ,0 ,40 +1 +12 * (14 +1 )); seq_printf(m, "%40s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s "
Signature · 1 line
2.12.2
PATCH 4/6 lockdep: Combine two seq_printf() calls into one call in l_show()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 3 May 2017 21:56:11 +0200
A bit of data was put into a sequence by two separate function calls. Print the same data by a single function call instead.
This issue was detected by using the Coccinelle software.
--- kernel/locking/lockdep_proc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/locking/lockdep_proc.c +1 -3
@@ -75,7 +75,5 @@ static int l_show(struct seq_file *m, void *v)#endif get_usage_chars (class, usage); -seq_printf (m," %s" , usage); - -seq_printf (m,": " ); +seq_printf (m," %s: " , usage);print_name (m, class);
Signature · 1 line
2.12.2
PATCH 5/6 lockdep: Improve a size determination in lock_stat_open()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 3 May 2017 22:05:57 +0200
Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- kernel/locking/lockdep_proc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/locking/lockdep_proc.c +1 -1
@@ -607,7 +607,7 @@ static int lock_stat_open(struct inode *inode, struct file *file) {int res;struct lock_class *class; -struct lock_stat_seq *data =vmalloc (sizeof (struct lock_stat_seq )); +struct lock_stat_seq *data =vmalloc (sizeof (*data));if (!data)return -ENOMEM ;
Signature · 1 line
2.12.2
PATCH 6/6 lockdep: Add spaces for better code readability
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 3 May 2017 22:11:28 +0200
Use space characters at some source code places according to the Linux coding style convention.
--- kernel/locking/lockdep_proc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
kernel/locking/lockdep_proc.c +5 -5
@@ -402,7 +402,7 @@ static void snprint_time(char *buf, size_t bufsiz, s64 nr) nr +=5 ;/* for display rounding */ div =div_s64_rem (nr,1000 , &rem); -snprintf (buf, bufsiz,"%lld.%02d" , (long long )div, (int )rem/10 ); +snprintf (buf, bufsiz,"%lld.%02d" , (long long )div, (int )rem /10 ); }static void seq_time (struct seq_file *m,s64 time)
@@ -461,11 +461,11 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data) namelen =strlen (name);if (class->name_version >1 ) { -snprintf (name+namelen,3 ,"#%d" , class->name_version); +snprintf (name + namelen,3 ,"#%d" , class->name_version); namelen +=2 ; }if (class->subclass) { -snprintf (name+namelen,3 ,"/%d" , class->subclass); +snprintf (name + namelen,3 ,"/%d" , class->subclass); namelen +=2 ; }
@@ -504,7 +504,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)break ;if (!i) -seq_line (m,'-' ,40 -namelen, namelen); +seq_line (m,'-' ,40 - namelen, namelen);snprintf (ip,sizeof (ip),"[<%p>]" , (void *)class->contention_point[i]);
@@ -519,7 +519,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)break ;if (!i) -seq_line (m,'-' ,40 -namelen, namelen); +seq_line (m,'-' ,40 - namelen, namelen);snprintf (ip,sizeof (ip),"[<%p>]" , (void *)class->contending_point[i]);
Signature · 1 line
2.12.2