locking/lockdep: Replace snprintf with strscpy in seq_stats
PATCH RESEND 1/1 locking/lockdep: Replace snprintf with strscpy in seq_stats
Replace snprintf("%s", ...) with the faster and more direct strscpy().
--- kernel/locking/lockdep_proc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/locking/lockdep_proc.c +3 -2
@@ -19,6 +19,7 @@#include <linux/debug_locks.h> #include <linux/vmalloc.h> #include <linux/sort.h> +#include <linux/string.h> #include <linux/uaccess.h> #include <asm/div64.h>
@@ -488,9 +489,9 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)const char *key_name; key_name =__get_key_name (ckey, str); -snprintf (name, namelen,"%s" , key_name); +strscpy (name, key_name, namelen); }else { -snprintf (name, namelen,"%s" , cname); +strscpy (name, cname, namelen); }rcu_read_unlock_sched ();
Quoted 23 lines · Thorsten Blum
Replace
snprintf("%s", ...)with the faster and more directstrscpy().Reviewed-by Waiman Long <[email protected]>Signed-off-by Thorsten Blum <[email protected]>--- kernel/locking/lockdep_proc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)kernel/locking/lockdep_proc.c +1
-0@@ -19,6 +19,7 @@#include <linux/debug_locks.h> #include <linux/vmalloc.h> #include <linux/sort.h> +#include <linux/string.h> #include <linux/uaccess.h> #include <asm/div64.h> @@ -488,9 +489,9 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)const char *key_name;
kernel/locking/lockdep_proc.c static void seq_stats(struct seq_file *m, struct lock_stat_data *data) · line 497
Quoted 10 lines
kernel/locking/lockdep_proc.c +2
-2key_name =__get_key_name (ckey, str); -snprintf (name, namelen,"%s" , key_name); +strscpy (name, key_name, namelen); }else { -snprintf (name, namelen,"%s" , cname); +strscpy (name, cname, namelen); }rcu_read_unlock_sched ();
Quoted 25 lines · Waiman Long
Quoted 23 lines · Thorsten Blum
Replace
snprintf("%s", ...)with the faster and more directstrscpy().Reviewed-by Waiman Long <[email protected]>Signed-off-by Thorsten Blum <[email protected]>--- kernel/locking/lockdep_proc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)kernel/locking/lockdep_proc.c +1
-1@@ -19,6 +19,7 @@#include <linux/debug_locks.h> #include <linux/vmalloc.h> #include <linux/sort.h> +#include <linux/string.h> #include <linux/uaccess.h> #include <asm/div64.h> @@ -488,9 +489,9 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)const char *key_name; key_name =__get_key_name (ckey, str); -snprintf (name, namelen,"%s" , key_name);
Quoted 9 lines
kernel/locking/lockdep_proc.c static void seq_stats(struct seq_file *m, struct lock_stat_data *data) · line 497
Quoted 7 lines
kernel/locking/lockdep_proc.c +2
-1+strscpy (name, key_name, namelen); }else { -snprintf (name, namelen,"%s" , cname); +strscpy (name, cname, namelen); }rcu_read_unlock_sched ();Acked-by Waiman Long <[email protected]>
Queued, thank you both!
Regards,
Boqun
Boqun Feng
maintainerQuoted 36 lines · Boqun Feng
Quoted 25 lines · Waiman Long
Quoted 23 lines · Thorsten Blum
Replace
snprintf("%s", ...)with the faster and more directstrscpy().Reviewed-by Waiman Long <[email protected]>Signed-off-by Thorsten Blum <[email protected]>--- kernel/locking/lockdep_proc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)kernel/locking/lockdep_proc.c +1
-1@@ -19,6 +19,7 @@#include <linux/debug_locks.h> #include <linux/vmalloc.h> #include <linux/sort.h> +#include <linux/string.h> #include <linux/uaccess.h> #include <asm/div64.h> @@ -488,9 +489,9 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)const char *key_name; key_name =__get_key_name (ckey, str); -snprintf (name, namelen,"%s" , key_name);Quoted 9 lines
kernel/locking/lockdep_proc.c static void seq_stats(struct seq_file *m, struct lock_stat_data *data) · line 497
Quoted 7 lines
kernel/locking/lockdep_proc.c +2
-1+strscpy (name, key_name, namelen); }else { -snprintf (name, namelen,"%s" , cname); +strscpy (name, cname, namelen); }rcu_read_unlock_sched ();Acked-by Waiman Long <[email protected]>
Quoted 2 lines
Queued, thank you both!
I was trying to merge it for v7.2 but sashiko found it out this:
https://sashiko.dev/#/patchset/20260605052331.1628-1-boqun%40kernel.org
Thorsten, could you take a look?
Regards,
Boqun
Quoted 2 lines
Regards,
Boqun
Quoted 37 lines · Boqun Feng
Quoted 36 lines · Boqun Feng
Quoted 34 lines · Waiman Long
Quoted 20 lines · Thorsten Blum
Replace
snprintf("%s", ...)with the faster and more directstrscpy().Reviewed-by Waiman Long <[email protected]>Signed-off-by Thorsten Blum <[email protected]>--- kernel/locking/lockdep_proc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)kernel/locking/lockdep_proc.c +1
-0@@ -19,6 +19,7 @@#include <linux/debug_locks.h> #include <linux/vmalloc.h> #include <linux/sort.h> +#include <linux/string.h> #include <linux/uaccess.h> #include <asm/div64.h> kernel/locking/lockdep_proc.c static void seq_stats(struct seq_file *m, struct lock_stat_data *data) · line 496
Quoted 10 lines
kernel/locking/lockdep_proc.c +2
-2@@ -488,9 +489,9 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)const char *key_name; key_name =__get_key_name (ckey, str); -snprintf (name, namelen,"%s" , key_name); +strscpy (name, key_name, namelen); }else { -snprintf (name, namelen,"%s" , cname); +strscpy (name, cname, namelen); }rcu_read_unlock_sched ();Acked-by Waiman Long <[email protected]>
Quoted 8 lines
Quoted 2 lines
Queued, thank you both!
I was trying to merge it for v7.2 but sashiko found it out this:
https://sashiko.dev/#/patchset/20260605052331.1628-1-boqun%40kernel.orgThorsten, could you take a look?
This appears valid, so we should probably drop this patch. I incorrectly assumed snprintf() also requires the source to be non-NULL for %s.
Handling a failed lookup explicitly could improve this code, but that requires more work and testing because it would change /proc/lock_stat output from "(null)" to no output.
Thanks for catching this,
Thorsten
Peter Zijlstra
maintainerQuoted 21 lines · Thorsten Blum
Replace
snprintf("%s", ...)with the faster and more directstrscpy().Reviewed-by Waiman Long <[email protected]>Signed-off-by Thorsten Blum <[email protected]>--- kernel/locking/lockdep_proc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)kernel/locking/lockdep_proc.c +1
-0@@ -19,6 +19,7 @@#include <linux/debug_locks.h> #include <linux/vmalloc.h> #include <linux/sort.h> +#include <linux/string.h> #include <linux/uaccess.h> #include <asm/div64.h>
kernel/locking/lockdep_proc.c static void seq_stats(struct seq_file *m, struct lock_stat_data *data) · line 496
Quoted 10 lines
kernel/locking/lockdep_proc.c +2
-2@@ -488,9 +489,9 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)const char *key_name; key_name =__get_key_name (ckey, str); -snprintf (name, namelen,"%s" , key_name); +strscpy (name, key_name, namelen); }else { -snprintf (name, namelen,"%s" , cname); +strscpy (name, cname, namelen); }rcu_read_unlock_sched ();
Why though? I suppose it doesn't matter, but this hardly seems worth the electrons is was sent with :/
Quoted 24 lines · Peter Zijlstra
Quoted 23 lines · Thorsten Blum
Replace
snprintf("%s", ...)with the faster and more directstrscpy().Reviewed-by Waiman Long <[email protected]>Signed-off-by Thorsten Blum <[email protected]>--- kernel/locking/lockdep_proc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)kernel/locking/lockdep_proc.c +1
-0@@ -19,6 +19,7 @@#include <linux/debug_locks.h> #include <linux/vmalloc.h> #include <linux/sort.h> +#include <linux/string.h> #include <linux/uaccess.h> #include <asm/div64.h> @@ -488,9 +489,9 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)const char *key_name;
Quoted 11 lines
kernel/locking/lockdep_proc.c static void seq_stats(struct seq_file *m, struct lock_stat_data *data) · line 496
Quoted 8 lines
kernel/locking/lockdep_proc.c +2
-2key_name =__get_key_name (ckey, str); -snprintf (name, namelen,"%s" , key_name); +strscpy (name, key_name, namelen); }else { -snprintf (name, namelen,"%s" , cname); +strscpy (name, cname, namelen); }rcu_read_unlock_sched ();Why though? I suppose it doesn't matter, but this hardly seems worth the electrons is was sent with :/
Is "faster and more direct" not a reason? There's nothing to format so the format specifier is unnecessary and can be removed.