Skip to contentSkip to conversation

locking/lockdep: Replace snprintf with strscpy in seq_stats

PATCH Superseded Thorsten Blum 2 participants 2 messages Jan 26 – Jan 27 Locking primitives

lore
Share & tools
lore
#0 lore raw

PATCH 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
index 1916db9aa46b..e458fa258d05 100644
@@ -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();
 
Signature · 2 lines
Thorsten Blum <[email protected]>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 21 lines · Thorsten Blum

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 +1 -0
index 1916db9aa46b..e458fa258d05 100644
@@ -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 -2
 
  		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();