[PATCH] locking/lockdep: Replace snprintf with strscpy in seq_stats

Thorsten Blum posted 1 patch 1 week, 4 days ago
kernel/locking/lockdep_proc.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
[PATCH] locking/lockdep: Replace snprintf with strscpy in seq_stats
Posted by Thorsten Blum 1 week, 4 days ago
Replace snprintf("%s", ...) with the faster and more direct strscpy().

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 kernel/locking/lockdep_proc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
index 1916db9aa46b..e458fa258d05 100644
--- a/kernel/locking/lockdep_proc.c
+++ b/kernel/locking/lockdep_proc.c
@@ -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();
 
-- 
Thorsten Blum <thorsten.blum@linux.dev>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4
Re: [PATCH] locking/lockdep: Replace snprintf with strscpy in seq_stats
Posted by Waiman Long 1 week, 4 days ago
On 1/26/26 6:54 PM, Thorsten Blum wrote:
> Replace snprintf("%s", ...) with the faster and more direct strscpy().
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>   kernel/locking/lockdep_proc.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
> index 1916db9aa46b..e458fa258d05 100644
> --- a/kernel/locking/lockdep_proc.c
> +++ b/kernel/locking/lockdep_proc.c
> @@ -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();
>   
Reviewed-by: Waiman Long <longman@redhat.com>