All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86: event, use scnprintf instead of snprintf
       [not found] <cover.1578550730.git.liuyang34@xiaomi.com>
@ 2020-01-09  6:36 ` liuyang34
  2020-01-09  8:03   ` Greg Kroah-Hartman
  0 siblings, 1 reply; 2+ messages in thread
From: liuyang34 @ 2020-01-09  6:36 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Thomas Gleixner, Borislav Petkov, H. Peter Anvin, x86,
	Darren Hart, Andy Shevchenko, Richard Fontana,
	Greg Kroah-Hartman, Allison Randal, linux-kernel,
	platform-driver-x86
  Cc: liuyang34

the return size will low than PAGE_SIZE but maybe over 40 in show_sysctl_tfa,
so use scnprintf instead of snprintf to get real size

Signed-off-by: liuyang34 <liuyang34@xiaomi.com>
---
 arch/x86/events/intel/core.c    | 6 +++---
 arch/x86/events/intel/pt.c      | 2 +-
 arch/x86/platform/uv/uv_sysfs.c | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 3be51aa..bf287b4 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -4372,7 +4372,7 @@ static ssize_t show_sysctl_tfa(struct device *cdev,
 			      struct device_attribute *attr,
 			      char *buf)
 {
-	return snprintf(buf, 40, "%d\n", allow_tsx_force_abort);
+	return scnprintf(buf, 40, "%d\n", allow_tsx_force_abort);
 }
 
 static ssize_t set_sysctl_tfa(struct device *cdev,
@@ -4406,7 +4406,7 @@ static ssize_t branches_show(struct device *cdev,
 			     struct device_attribute *attr,
 			     char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "%d\n", x86_pmu.lbr_nr);
+	return scnprintf(buf, PAGE_SIZE, "%d\n", x86_pmu.lbr_nr);
 }
 
 static DEVICE_ATTR_RO(branches);
@@ -4422,7 +4422,7 @@ static ssize_t pmu_name_show(struct device *cdev,
 			     struct device_attribute *attr,
 			     char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "%s\n", pmu_name_str);
+	return scnprintf(buf, PAGE_SIZE, "%s\n", pmu_name_str);
 }
 
 static DEVICE_ATTR_RO(pmu_name);
diff --git a/arch/x86/events/intel/pt.c b/arch/x86/events/intel/pt.c
index 1db7a51..4ca7ed9 100644
--- a/arch/x86/events/intel/pt.c
+++ b/arch/x86/events/intel/pt.c
@@ -92,7 +92,7 @@ static ssize_t pt_cap_show(struct device *cdev,
 		container_of(attr, struct dev_ext_attribute, attr);
 	enum pt_capabilities cap = (long)ea->var;
 
-	return snprintf(buf, PAGE_SIZE, "%x\n", intel_pt_validate_hw_cap(cap));
+	return scnprintf(buf, PAGE_SIZE, "%x\n", intel_pt_validate_hw_cap(cap));
 }
 
 static struct attribute_group pt_cap_group __ro_after_init = {
diff --git a/arch/x86/platform/uv/uv_sysfs.c b/arch/x86/platform/uv/uv_sysfs.c
index 6221473..aa44c82 100644
--- a/arch/x86/platform/uv/uv_sysfs.c
+++ b/arch/x86/platform/uv/uv_sysfs.c
@@ -15,13 +15,13 @@ struct kobject *sgi_uv_kobj;
 static ssize_t partition_id_show(struct kobject *kobj,
 			struct kobj_attribute *attr, char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "%ld\n", sn_partition_id);
+	return scnprintf(buf, PAGE_SIZE, "%ld\n", sn_partition_id);
 }
 
 static ssize_t coherence_id_show(struct kobject *kobj,
 			struct kobj_attribute *attr, char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "%ld\n", uv_partition_coherence_id());
+	return scnprintf(buf, PAGE_SIZE, "%ld\n", uv_partition_coherence_id());
 }
 
 static struct kobj_attribute partition_id_attr =
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] x86: event, use scnprintf instead of snprintf
  2020-01-09  6:36 ` [PATCH] x86: event, use scnprintf instead of snprintf liuyang34
@ 2020-01-09  8:03   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2020-01-09  8:03 UTC (permalink / raw)
  To: liuyang34
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Thomas Gleixner, Borislav Petkov, H. Peter Anvin, x86,
	Darren Hart, Andy Shevchenko, Richard Fontana, Allison Randal,
	linux-kernel, platform-driver-x86, liuyang34

On Thu, Jan 09, 2020 at 02:36:26PM +0800, liuyang34 wrote:
> the return size will low than PAGE_SIZE but maybe over 40 in show_sysctl_tfa,
> so use scnprintf instead of snprintf to get real size
> 
> Signed-off-by: liuyang34 <liuyang34@xiaomi.com>
> ---
>  arch/x86/events/intel/core.c    | 6 +++---
>  arch/x86/events/intel/pt.c      | 2 +-
>  arch/x86/platform/uv/uv_sysfs.c | 4 ++--
>  3 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
> index 3be51aa..bf287b4 100644
> --- a/arch/x86/events/intel/core.c
> +++ b/arch/x86/events/intel/core.c
> @@ -4372,7 +4372,7 @@ static ssize_t show_sysctl_tfa(struct device *cdev,
>  			      struct device_attribute *attr,
>  			      char *buf)
>  {
> -	return snprintf(buf, 40, "%d\n", allow_tsx_force_abort);
> +	return scnprintf(buf, 40, "%d\n", allow_tsx_force_abort);

No, just use sprintf() for all of these.  We "know" the buffer size is
big enough for a single number.  There's no need for fancy checks for
any sysfs file.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-01-09  8:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <cover.1578550730.git.liuyang34@xiaomi.com>
2020-01-09  6:36 ` [PATCH] x86: event, use scnprintf instead of snprintf liuyang34
2020-01-09  8:03   ` Greg Kroah-Hartman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.