Skip to contentSkip to conversation

mm/hugetlb: Use str_plural() in report_hugepages()

PATCH Applied Thorsten Blum 5 participants 7 messages Jun 30, 2025 – Jul 2, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/hugetlb: Use str_plural() in report_hugepages()

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)

---
 mm/hugetlb.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/hugetlb.c +2 -1
index 9dc95eac558c..08abe7395f2f 100644
@@ -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);
 	}
Signature · 1 line
2.50.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 24 lines · Thorsten Blum

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)

---
  mm/hugetlb.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
mm/hugetlb.c +1 -0
index 9dc95eac558c..08abe7395f2f 100644
@@ -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>

mm/hugetlb.c static void __init report_hugepages(void) · line 3731

Quoted 8 lines
mm/hugetlb.c +1 -1
@@ -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

#2 lore raw
In reply to Thorsten Blum
Quoted 24 lines · Thorsten Blum

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)

---
 mm/hugetlb.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/hugetlb.c +1 -0
index 9dc95eac558c..08abe7395f2f 100644
@@ -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>

mm/hugetlb.c static void __init report_hugepages(void) · line 3731

Quoted 8 lines
mm/hugetlb.c +1 -1
@@ -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.

#3 lore raw
Quoted 3 lines · Anshuman Khandual

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

Reviewed-by
#4 lore raw
Quoted 7 lines · Thorsten Blum
Quoted 3 lines · Anshuman Khandual

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.