[PATCH] mm/hugetlb: Use str_plural() in report_hugepages()

Thorsten Blum posted 1 patch 3 months, 1 week ago
mm/hugetlb.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH] mm/hugetlb: Use str_plural() in report_hugepages()
Posted by Thorsten Blum 3 months, 1 week ago
Use the string choice helper function str_plural() to simplify the code
and to fix the following Coccinelle/coccicheck warning reported by
string_choices.cocci:

  opportunity for str_plural(nrinvalid)

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 mm/hugetlb.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 9dc95eac558c..08abe7395f2f 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -25,6 +25,7 @@
 #include <linux/mmdebug.h>
 #include <linux/sched/signal.h>
 #include <linux/rmap.h>
+#include <linux/string_choices.h>
 #include <linux/string_helpers.h>
 #include <linux/swap.h>
 #include <linux/swapops.h>
@@ -3724,7 +3725,7 @@ static void __init report_hugepages(void)
 			buf, h->nr_huge_pages);
 		if (nrinvalid)
 			pr_info("HugeTLB: %s page size: %lu invalid page%s discarded\n",
-					buf, nrinvalid, nrinvalid > 1 ? "s" : "");
+					buf, nrinvalid, str_plural(nrinvalid));
 		pr_info("HugeTLB: %d KiB vmemmap can be freed for a %s page\n",
 			hugetlb_vmemmap_optimizable_size(h) / SZ_1K, buf);
 	}
-- 
2.50.0
Re: [PATCH] mm/hugetlb: Use str_plural() in report_hugepages()
Posted by Oscar Salvador 3 months, 1 week ago
On Mon, Jun 30, 2025 at 07:18:26PM +0200, Thorsten Blum wrote:
> Use the string choice helper function str_plural() to simplify the code
> and to fix the following Coccinelle/coccicheck warning reported by
> string_choices.cocci:
> 
>   opportunity for str_plural(nrinvalid)
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>

Acked-by: Oscar Salvador <osalvador@suse.de>


-- 
Oscar Salvador
SUSE Labs
Re: [PATCH] mm/hugetlb: Use str_plural() in report_hugepages()
Posted by David Hildenbrand 3 months, 1 week ago
On 30.06.25 19:18, Thorsten Blum wrote:
> Use the string choice helper function str_plural() to simplify the code
> and to fix the following Coccinelle/coccicheck warning reported by
> string_choices.cocci:
> 
>    opportunity for str_plural(nrinvalid)
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---

Acked-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb
Re: [PATCH] mm/hugetlb: Use str_plural() in report_hugepages()
Posted by Anshuman Khandual 3 months, 1 week ago

On 30/06/25 10:48 PM, Thorsten Blum wrote:
> Use the string choice helper function str_plural() to simplify the code
> and to fix the following Coccinelle/coccicheck warning reported by
> string_choices.cocci:
> 
>   opportunity for str_plural(nrinvalid)
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>  mm/hugetlb.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 9dc95eac558c..08abe7395f2f 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -25,6 +25,7 @@
>  #include <linux/mmdebug.h>
>  #include <linux/sched/signal.h>
>  #include <linux/rmap.h>
> +#include <linux/string_choices.h>
>  #include <linux/string_helpers.h>
>  #include <linux/swap.h>
>  #include <linux/swapops.h>
> @@ -3724,7 +3725,7 @@ static void __init report_hugepages(void)
>  			buf, h->nr_huge_pages);
>  		if (nrinvalid)
>  			pr_info("HugeTLB: %s page size: %lu invalid page%s discarded\n",
> -					buf, nrinvalid, nrinvalid > 1 ? "s" : "");
> +					buf, nrinvalid, str_plural(nrinvalid));
>  		pr_info("HugeTLB: %d KiB vmemmap can be freed for a %s page\n",
>  			hugetlb_vmemmap_optimizable_size(h) / SZ_1K, buf);
>  	}

Seems like there be more than one place where such str_plural() changes
could be made. Hence could you please collate them all part of a series
instead.
Re: [PATCH] mm/hugetlb: Use str_plural() in report_hugepages()
Posted by Thorsten Blum 3 months, 1 week ago
On 1. Jul 2025, at 06:43, Anshuman Khandual wrote:
> Seems like there be more than one place where such str_plural() changes
> could be made. Hence could you please collate them all part of a series
> instead.

There are only two instances under mm/ and I didn't think a patch series
would be necessary.

Thanks,
Thorsten
Re: [PATCH] mm/hugetlb: Use str_plural() in report_hugepages()
Posted by Anshuman Khandual 3 months, 1 week ago

On 01/07/25 2:05 PM, Thorsten Blum wrote:
> On 1. Jul 2025, at 06:43, Anshuman Khandual wrote:
>> Seems like there be more than one place where such str_plural() changes
>> could be made. Hence could you please collate them all part of a series
>> instead.
> 
> There are only two instances under mm/ and I didn't think a patch series
> would be necessary.

Reasonable enough.

LGTM.

Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
Re: [PATCH] mm/hugetlb: Use str_plural() in report_hugepages()
Posted by Dev Jain 3 months, 1 week ago
On 30/06/25 10:48 pm, Thorsten Blum wrote:
> Use the string choice helper function str_plural() to simplify the code
> and to fix the following Coccinelle/coccicheck warning reported by
> string_choices.cocci:
>
>    opportunity for str_plural(nrinvalid)
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>   mm/hugetlb.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 9dc95eac558c..08abe7395f2f 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -25,6 +25,7 @@
>   #include <linux/mmdebug.h>
>   #include <linux/sched/signal.h>
>   #include <linux/rmap.h>
> +#include <linux/string_choices.h>
>   #include <linux/string_helpers.h>
>   #include <linux/swap.h>
>   #include <linux/swapops.h>
> @@ -3724,7 +3725,7 @@ static void __init report_hugepages(void)
>   			buf, h->nr_huge_pages);
>   		if (nrinvalid)
>   			pr_info("HugeTLB: %s page size: %lu invalid page%s discarded\n",
> -					buf, nrinvalid, nrinvalid > 1 ? "s" : "");
> +					buf, nrinvalid, str_plural(nrinvalid));
>   		pr_info("HugeTLB: %d KiB vmemmap can be freed for a %s page\n",
>   			hugetlb_vmemmap_optimizable_size(h) / SZ_1K, buf);
>   	}

LGTM

Reviewed-by: Dev Jain <dev.jain@arm.com>