2024-03-27 22:42:50

by Thorsten Blum

[permalink] [raw]
Subject: [PATCH] smp: Use str_plural() to fix Coccinelle warnings

Fixes the following two Coccinelle/coccicheck warnings reported by
string_choices.cocci:

opportunity for str_plural(num_cpus)
opportunity for str_plural(num_nodes)

Signed-off-by: Thorsten Blum <[email protected]>
---
kernel/smp.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/smp.c b/kernel/smp.c
index f085ebcdf9e7..58b7f134c044 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -982,8 +982,8 @@ void __init smp_init(void)
num_nodes = num_online_nodes();
num_cpus = num_online_cpus();
pr_info("Brought up %d node%s, %d CPU%s\n",
- num_nodes, (num_nodes > 1 ? "s" : ""),
- num_cpus, (num_cpus > 1 ? "s" : ""));
+ num_nodes, str_plural(num_nodes),
+ num_cpus, str_plural(num_cpus));

/* Any cleanup work */
smp_cpus_done(setup_max_cpus);
--
2.44.0



2024-04-01 17:36:32

by Thorsten Blum

[permalink] [raw]
Subject: [PATCH v2] smp: Use str_plural() to fix Coccinelle warnings

Fixes the following two Coccinelle/coccicheck warnings reported by
string_choices.cocci:

opportunity for str_plural(num_cpus)
opportunity for str_plural(num_nodes)

Signed-off-by: Thorsten Blum <[email protected]>
---
Changes in v2:
- Include missing header file
---
kernel/smp.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/smp.c b/kernel/smp.c
index f085ebcdf9e7..28fee28174e0 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -25,6 +25,7 @@
#include <linux/nmi.h>
#include <linux/sched/debug.h>
#include <linux/jump_label.h>
+#include <linux/string_choices.h>

#include <trace/events/ipi.h>
#define CREATE_TRACE_POINTS
@@ -982,8 +983,8 @@ void __init smp_init(void)
num_nodes = num_online_nodes();
num_cpus = num_online_cpus();
pr_info("Brought up %d node%s, %d CPU%s\n",
- num_nodes, (num_nodes > 1 ? "s" : ""),
- num_cpus, (num_cpus > 1 ? "s" : ""));
+ num_nodes, str_plural(num_nodes),
+ num_cpus, str_plural(num_cpus));

/* Any cleanup work */
smp_cpus_done(setup_max_cpus);
--
2.44.0


2024-04-01 20:56:54

by Paul E. McKenney

[permalink] [raw]
Subject: Re: [PATCH v2] smp: Use str_plural() to fix Coccinelle warnings

On Mon, Apr 01, 2024 at 04:31:18PM +0200, Thorsten Blum wrote:
> Fixes the following two Coccinelle/coccicheck warnings reported by
> string_choices.cocci:
>
> opportunity for str_plural(num_cpus)
> opportunity for str_plural(num_nodes)
>
> Signed-off-by: Thorsten Blum <[email protected]>

Acked-by: Paul E. McKenney <[email protected]>

> ---
> Changes in v2:
> - Include missing header file
> ---
> kernel/smp.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/smp.c b/kernel/smp.c
> index f085ebcdf9e7..28fee28174e0 100644
> --- a/kernel/smp.c
> +++ b/kernel/smp.c
> @@ -25,6 +25,7 @@
> #include <linux/nmi.h>
> #include <linux/sched/debug.h>
> #include <linux/jump_label.h>
> +#include <linux/string_choices.h>
>
> #include <trace/events/ipi.h>
> #define CREATE_TRACE_POINTS
> @@ -982,8 +983,8 @@ void __init smp_init(void)
> num_nodes = num_online_nodes();
> num_cpus = num_online_cpus();
> pr_info("Brought up %d node%s, %d CPU%s\n",
> - num_nodes, (num_nodes > 1 ? "s" : ""),
> - num_cpus, (num_cpus > 1 ? "s" : ""));
> + num_nodes, str_plural(num_nodes),
> + num_cpus, str_plural(num_cpus));
>
> /* Any cleanup work */
> smp_cpus_done(setup_max_cpus);
> --
> 2.44.0
>