Skip to content

Commit 1d6664f

Browse files
Like Xusean-jc
authored andcommitted
KVM: x86: Use sysfs_emit() instead of sprintf()
Use sysfs_emit() instead of the sprintf() for sysfs entries. sysfs_emit() knows the maximum of the temporary buffer used for outputting sysfs content and avoids overrunning the buffer length. Signed-off-by: Like Xu <likexu@tencent.com> Link: https://lore.kernel.org/r/20230625073438.57427-1-likexu@tencent.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent fdf0eaf commit 1d6664f

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

arch/x86/kvm/mmu/mmu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6862,7 +6862,7 @@ static void mmu_destroy_caches(void)
68626862
static int get_nx_huge_pages(char *buffer, const struct kernel_param *kp)
68636863
{
68646864
if (nx_hugepage_mitigation_hard_disabled)
6865-
return sprintf(buffer, "never\n");
6865+
return sysfs_emit(buffer, "never\n");
68666866

68676867
return param_get_bool(buffer, kp);
68686868
}

arch/x86/kvm/vmx/vmx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,9 @@ static int vmentry_l1d_flush_set(const char *s, const struct kernel_param *kp)
366366
static int vmentry_l1d_flush_get(char *s, const struct kernel_param *kp)
367367
{
368368
if (WARN_ON_ONCE(l1tf_vmx_mitigation >= ARRAY_SIZE(vmentry_l1d_param)))
369-
return sprintf(s, "???\n");
369+
return sysfs_emit(s, "???\n");
370370

371-
return sprintf(s, "%s\n", vmentry_l1d_param[l1tf_vmx_mitigation].option);
371+
return sysfs_emit(s, "%s\n", vmentry_l1d_param[l1tf_vmx_mitigation].option);
372372
}
373373

374374
static void vmx_setup_fb_clear_ctrl(void)

0 commit comments

Comments
 (0)