public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [tip: perf/core] perf/core: Convert snprintf() to scnprintf()
@ 2022-09-21  8:08 tip-bot2 for Jules Irenge
  2022-09-21  8:34 ` Peter Zijlstra
  0 siblings, 1 reply; 7+ messages in thread
From: tip-bot2 for Jules Irenge @ 2022-09-21  8:08 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Jules Irenge, Ingo Molnar, x86, linux-kernel

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     678739d622ae7b75b62d550858b6bf104c43e2df
Gitweb:        https://git.kernel.org/tip/678739d622ae7b75b62d550858b6bf104c43e2df
Author:        Jules Irenge <jbi.octave@gmail.com>
AuthorDate:    Sun, 18 Sep 2022 00:41:08 +01:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Wed, 21 Sep 2022 10:01:20 +02:00

perf/core: Convert snprintf() to scnprintf()

Coccinelle reports a warning:

    WARNING: use scnprintf or sprintf

Adding to that, there has also been some slow migration from snprintf to scnprintf.

This LWN article explains the rationale for this change:

    https: //lwn.net/Articles/69419/

No change in behavior.

[ mingo: Improved the changelog. ]

Signed-off-by: Jules Irenge <jbi.octave@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/events/core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 7da5515..c07e9a3 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -10952,7 +10952,7 @@ static ssize_t nr_addr_filters_show(struct device *dev,
 {
 	struct pmu *pmu = dev_get_drvdata(dev);
 
-	return snprintf(page, PAGE_SIZE - 1, "%d\n", pmu->nr_addr_filters);
+	return scnprintf(page, PAGE_SIZE - 1, "%d\n", pmu->nr_addr_filters);
 }
 DEVICE_ATTR_RO(nr_addr_filters);
 
@@ -10963,7 +10963,7 @@ type_show(struct device *dev, struct device_attribute *attr, char *page)
 {
 	struct pmu *pmu = dev_get_drvdata(dev);
 
-	return snprintf(page, PAGE_SIZE-1, "%d\n", pmu->type);
+	return scnprintf(page, PAGE_SIZE - 1, "%d\n", pmu->type);
 }
 static DEVICE_ATTR_RO(type);
 
@@ -10974,7 +10974,7 @@ perf_event_mux_interval_ms_show(struct device *dev,
 {
 	struct pmu *pmu = dev_get_drvdata(dev);
 
-	return snprintf(page, PAGE_SIZE-1, "%d\n", pmu->hrtimer_interval_ms);
+	return scnprintf(page, PAGE_SIZE - 1, "%d\n", pmu->hrtimer_interval_ms);
 }
 
 static DEFINE_MUTEX(mux_interval_mutex);

^ permalink raw reply related	[flat|nested] 7+ messages in thread
* [tip: perf/core] perf/core: Convert snprintf() to scnprintf()
@ 2022-09-21 10:40 tip-bot2 for Jules Irenge
  0 siblings, 0 replies; 7+ messages in thread
From: tip-bot2 for Jules Irenge @ 2022-09-21 10:40 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Jules Irenge, Ingo Molnar, x86, linux-kernel

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     dca6344d7a77dd0501a73745f4a9fb1ee2bc9d7c
Gitweb:        https://git.kernel.org/tip/dca6344d7a77dd0501a73745f4a9fb1ee2bc9d7c
Author:        Jules Irenge <jbi.octave@gmail.com>
AuthorDate:    Sun, 18 Sep 2022 00:41:08 +01:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Wed, 21 Sep 2022 12:34:36 +02:00

perf/core: Convert snprintf() to scnprintf()

Coccinelle reports a warning:

    WARNING: use scnprintf or sprintf

This LWN article explains the rationale for this change:

    https: //lwn.net/Articles/69419/

Ie. snprintf() returns what *would* be the resulting length,
while scnprintf() returns the actual length.

Adding to that, there has also been some slow migration from snprintf to scnprintf,
here's the shift in usage in the past 3.5 years, in all fs/ files:

                         v5.0    v6.0-rc6
   --------------------------------------
   snprintf() uses:        63         213
   scnprintf() uses:      374         186

No intended change in behavior.

[ mingo: Improved the changelog & reviewed the usage sites. ]

Signed-off-by: Jules Irenge <jbi.octave@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/events/core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 7da5515..c07e9a3 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -10952,7 +10952,7 @@ static ssize_t nr_addr_filters_show(struct device *dev,
 {
 	struct pmu *pmu = dev_get_drvdata(dev);
 
-	return snprintf(page, PAGE_SIZE - 1, "%d\n", pmu->nr_addr_filters);
+	return scnprintf(page, PAGE_SIZE - 1, "%d\n", pmu->nr_addr_filters);
 }
 DEVICE_ATTR_RO(nr_addr_filters);
 
@@ -10963,7 +10963,7 @@ type_show(struct device *dev, struct device_attribute *attr, char *page)
 {
 	struct pmu *pmu = dev_get_drvdata(dev);
 
-	return snprintf(page, PAGE_SIZE-1, "%d\n", pmu->type);
+	return scnprintf(page, PAGE_SIZE - 1, "%d\n", pmu->type);
 }
 static DEVICE_ATTR_RO(type);
 
@@ -10974,7 +10974,7 @@ perf_event_mux_interval_ms_show(struct device *dev,
 {
 	struct pmu *pmu = dev_get_drvdata(dev);
 
-	return snprintf(page, PAGE_SIZE-1, "%d\n", pmu->hrtimer_interval_ms);
+	return scnprintf(page, PAGE_SIZE - 1, "%d\n", pmu->hrtimer_interval_ms);
 }
 
 static DEFINE_MUTEX(mux_interval_mutex);

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

end of thread, other threads:[~2022-09-29  8:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-21  8:08 [tip: perf/core] perf/core: Convert snprintf() to scnprintf() tip-bot2 for Jules Irenge
2022-09-21  8:34 ` Peter Zijlstra
2022-09-21 10:44   ` Ingo Molnar
2022-09-21 12:55     ` David Sterba
2022-09-29  8:28       ` Jules Irenge
2022-09-21 11:58   ` Jules Irenge
  -- strict thread matches above, loose matches on Subject: below --
2022-09-21 10:40 tip-bot2 for Jules Irenge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox