Skip to contentSkip to conversation

perf/x86/intel: Replace snprintf with strscpy in intel_pmu_init

PATCH In review Thorsten Blum 2 participants 2 messages Jan 31 – Sep 15

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf/x86/intel: Replace snprintf with strscpy in intel_pmu_init

Replace snprintf("%s", ...) with the faster and more direct strscpy().

---
 arch/x86/events/intel/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/events/intel/core.c +2 -1
index bdf3f0d0fe21..025971ab6341 100644
@@ -12,6 +12,7 @@
 #include <linux/types.h>
 #include <linux/init.h>
 #include <linux/slab.h>
+#include <linux/string.h>
 #include <linux/export.h>
 #include <linux/nmi.h>
 #include <linux/kvm_host.h>
@@ -8077,7 +8078,7 @@ __init int intel_pmu_init(void)
 		}
 	}
 
-	snprintf(pmu_name_str, sizeof(pmu_name_str), "%s", name);
+	strscpy(pmu_name_str, name);
 
 	if (!is_hybrid()) {
 		group_events_td.attrs  = td_attr;
Signature · 2 lines
Thorsten Blum <[email protected]>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Thorsten Blum

Replace snprintf("%s", ...) with the faster and more direct strscpy().

Thanks,
Ian

Quoted 29 lines
---
 arch/x86/events/intel/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/events/intel/core.c +2 -2
index bdf3f0d0fe21..025971ab6341 100644
@@ -12,6 +12,7 @@
 #include <linux/types.h>
 #include <linux/init.h>
 #include <linux/slab.h>
+#include <linux/string.h>
 #include <linux/export.h>
 #include <linux/nmi.h>
 #include <linux/kvm_host.h>
@@ -8077,7 +8078,7 @@ __init int intel_pmu_init(void)
                }
        }
 
-       snprintf(pmu_name_str, sizeof(pmu_name_str), "%s", name);
+       strscpy(pmu_name_str, name);
 
        if (!is_hybrid()) {
                group_events_td.attrs  = td_attr;
--

Thorsten Blum <[email protected]>
GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4