Skip to contentSkip to conversation

mm: Coccinelle-driven cleanups across memory management code

PATCH Superseded Sahil Chandna 7 participants 16 messages Nov 18, 2025 – Nov 19, 2025

Subsystems (5)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover mm: Coccinelle-driven cleanups across memory management code

This patch series contains three minor cleanups identified by Coccinelle scripts under scripts/coccinelle/misc/:

* Replace manual ternary expression with the min() macro in pagewalk.c
* Use the %pe printk format specifier for PTR_ERR() reporting in vmscan.c and zswap.c
Found using:
make coccicheck MODE=report M=mm/

Sahil Chandna (3):
mm/pagewalk: use min() macro instead of manual ternary mm/vmscan: use %pe to print PTR_ERR() values mm/zswap: use %pe to print PTR_ERR() values

 mm/pagewalk.c | 2 +-
 mm/vmscan.c   | 4 ++--
 mm/zswap.c    | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)
Signature · 1 line
2.50.1
#1 lore raw

PATCH 1/3 mm/pagewalk: use min() macro instead of manual ternary

mm: pagewalk: use min() macro instead of manual ternary expression

Use the kernel-provided min() macro to compute the minimum value instead of an explicit ternary expression. This improves readability and matches common kernel style.

This was flagged by Coccinelle (misc/minmax.cocci) as an opportunity to use min().

Found by: make coccicheck MODE=report M=mm/
No functional change intended.

---
 mm/pagewalk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/pagewalk.c +1 -1
index 9f91cf85a5be..82db421b5b34 100644
@@ -313,7 +313,7 @@ static unsigned long hugetlb_entry_end(struct hstate *h, unsigned long addr,
 				       unsigned long end)
 {
 	unsigned long boundary = (addr & huge_page_mask(h)) + huge_page_size(h);
-	return boundary < end ? boundary : end;
+	return min(boundary, end);
 }
 
 static int walk_hugetlb_range(unsigned long addr, unsigned long end,
Signature · 1 line
2.50.1
#2 lore raw

Re: [PATCH 1/3] mm/pagewalk: use min() macro instead of manual ternary

Quoted 1 line

mm: pagewalk: use min() macro instead of manual ternary expression

How do you think about to avoid the repetition of a patch subject in the change description?

…

Quoted 2 lines

This was flagged by Coccinelle (misc/minmax.cocci) as an opportunity to use min().

Would an other word wrapping be a bit nicer?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.18-rc6#n658

Regards,
Markus

#3 lore raw

Re: [PATCH 1/3] mm/pagewalk: use min() macro instead of manual ternary

In reply to Sahil Chandna
Quoted 22 lines · On Tue, 18 Nov 2025 11:38:49 +0530 Sahil Chandna <[email protected]>…

mm: pagewalk: use min() macro instead of manual ternary expression

Use the kernel-provided min() macro to compute the minimum value instead of an explicit ternary expression. This improves readability and matches common kernel style.

This was flagged by Coccinelle (misc/minmax.cocci) as an opportunity to use min().

Found by: make coccicheck MODE=report M=mm/
No functional change intended.

---
 mm/pagewalk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/pagewalk.c +0 -0
index 9f91cf85a5be..82db421b5b34 100644

mm/pagewalk.c static unsigned long hugetlb_entry_end(struct hstate *h, unsigned long addr, · line 316

Quoted 5 lines
mm/pagewalk.c +1 -1
@@ -313,7 +313,7 @@ static unsigned long hugetlb_entry_end(struct hstate *h, unsigned long addr,
 				       unsigned long end)
 {
 	unsigned long boundary = (addr & huge_page_mask(h)) + huge_page_size(h);
-	return boundary < end ? boundary : end;
+	return min(boundary, end);

You can remove the temporary:

	return min((addr & huge_page_mask(h)) + huge_page_size(h), end);

David

Quoted 3 lines
mm/pagewalk.c +0 -0
 }
 
 static int walk_hugetlb_range(unsigned long addr, unsigned long end,
#4 lore raw

Re: [PATCH 1/3] mm/pagewalk: use min() macro instead of manual ternary

Quoted 11 lines · David Laight

mm/pagewalk.c static unsigned long hugetlb_entry_end(struct hstate *h, unsigned long addr, · line 316

Quoted 7 lines · On Tue, 18 Nov 2025 11:38:49 +0530 Sahil Chandna <[email protected]>…

+++ b/mm/pagewalk.c

mm/pagewalk.c +1 -1
@@ -313,7 +313,7 @@ static unsigned long hugetlb_entry_end(struct hstate *h, unsigned long addr,
 				       unsigned long end)
 {
 	unsigned long boundary = (addr & huge_page_mask(h)) + huge_page_size(h);
-	return boundary < end ? boundary : end;
+	return min(boundary, end);

You can remove the temporary:

Quoted 1 line
	return min((addr & huge_page_mask(h)) + huge_page_size(h), end);

You can, but I'm not sure that's better. What would be better is:

	unsigned long boundary = (addr | ~huge_page_mask(h)) + 1;
	return min(boundary, end);

if you insist, we could do:

	return min((addr | ~huge_page_mask(h)) + 1, end);
#5 lore raw

Re: [PATCH 1/3] mm/pagewalk: use min() macro instead of manual ternary

Quoted 14 lines · On Tue, 18 Nov 2025 15:18:50 +0000 Matthew Wilcox <[email protected]> wrote:
Quoted 11 lines · David Laight

mm/pagewalk.c static unsigned long hugetlb_entry_end(struct hstate *h, unsigned long addr, · line 316

Quoted 7 lines · On Tue, 18 Nov 2025 11:38:49 +0530 Sahil Chandna <[email protected]>…

+++ b/mm/pagewalk.c

mm/pagewalk.c +1 -1
@@ -313,7 +313,7 @@ static unsigned long hugetlb_entry_end(struct hstate *h, unsigned long addr,
 				       unsigned long end)
 {
 	unsigned long boundary = (addr & huge_page_mask(h)) + huge_page_size(h);
-	return boundary < end ? boundary : end;
+	return min(boundary, end);  

You can remove the temporary:

Quoted 1 line
	return min((addr & huge_page_mask(h)) + huge_page_size(h), end);  
Quoted 8 lines

You can, but I'm not sure that's better. What would be better is:

	unsigned long boundary = (addr | ~huge_page_mask(h)) + 1;
	return min(boundary, end);

if you insist, we could do:

	return min((addr | ~huge_page_mask(h)) + 1, end);

Indeed...

David

#6 lore raw

PATCH 2/3 mm/vmscan: use %pe to print PTR_ERR() values

In reply to Sahil Chandna

Use the %pe printk format specifier to report error pointers directly instead of printing PTR_ERR() as a long value. This improves clarity, produces more readable error messages.

This instance was flagged by the Coccinelle script (misc/ptr_err_to_pe.cocci) as an opportunity to adopt %pe.

Found by: make coccicheck MODE=report M=mm/
No functional change intended

---
 mm/vmscan.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/vmscan.c +2 -2
index b2fc8b626d3d..7d5b41696cc3 100644
@@ -7500,8 +7500,8 @@ void __meminit kswapd_run(int nid)
 		pgdat->kswapd = kthread_create_on_node(kswapd, pgdat, nid, "kswapd%d", nid);
 		if (IS_ERR(pgdat->kswapd)) {
 			/* failure at boot is fatal */
-			pr_err("Failed to start kswapd on node %d,ret=%ld\n",
-				   nid, PTR_ERR(pgdat->kswapd));
+			pr_err("Failed to start kswapd on node %d,ret=%pe\n",
+				   nid, pgdat->kswapd);
 			BUG_ON(system_state < SYSTEM_RUNNING);
 			pgdat->kswapd = NULL;
 		} else {
Signature · 1 line
2.50.1
#7 lore raw

Re: [PATCH 2/3] mm/vmscan: use %pe to print PTR_ERR() values

…

Quoted 4 lines

+++ b/mm/vmscan.c

mm/vmscan.c +0 -0
@@ -7500,8 +7500,8 @@ void __meminit kswapd_run(int nid)
 		pgdat->kswapd = kthread_create_on_node(kswapd, pgdat, nid, "kswapd%d", nid);
 		if (IS_ERR(pgdat->kswapd)) {

…

mm/vmscan.c void __meminit kswapd_run(int nid) · line 7505

Quoted 3 lines
mm/vmscan.c +2 -0
+			pr_err("Failed to start kswapd on node %d,ret=%pe\n",
+				   nid, pgdat->kswapd);
 			BUG_ON(system_state < SYSTEM_RUNNING);

…

I propose to adjust the indentation for the passed parameters.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v6.18-rc6#n110

Regards,
Markus

Reviewed-by on v1 2/3
#8 lore raw

Re: [PATCH 2/3] mm/vmscan: use %pe to print PTR_ERR() values

In reply to Sahil Chandna
Quoted 11 lines · On Tue, 18 Nov 2025 11:38:50 +0530 Sahil Chandna <[email protected]>…

Use the %pe printk format specifier to report error pointers directly instead of printing PTR_ERR() as a long value. This improves clarity, produces more readable error messages.

This instance was flagged by the Coccinelle script (misc/ptr_err_to_pe.cocci) as an opportunity to adopt %pe.

Found by: make coccicheck MODE=report M=mm/
No functional change intended

Thanks,
SJ

[...]

#9 lore raw

PATCH 3/3 mm/zswap: use %pe to print PTR_ERR() values

In reply to Sahil Chandna

Use the %pe printk format specifier to report error pointers directly instead of printing PTR_ERR() as a long value. This improves clarity, produces more readable error messages.

This instance was flagged by the Coccinelle script (misc/ptr_err_to_pe.cocci) as an opportunity to adopt %pe.

Found by: make coccicheck MODE=report M=mm/
No functional change intended.

---
 mm/zswap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/zswap.c +2 -2
index c1af782e54ec..c35604db32ad 100644
@@ -749,8 +749,8 @@ static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node)
 
 	acomp = crypto_alloc_acomp_node(pool->tfm_name, 0, 0, cpu_to_node(cpu));
 	if (IS_ERR(acomp)) {
-		pr_err("could not alloc crypto acomp %s : %ld\n",
-				pool->tfm_name, PTR_ERR(acomp));
+		pr_err("could not alloc crypto acomp %s : %pe\n",
+				pool->tfm_name, acomp);
 		ret = PTR_ERR(acomp);
 		goto fail;
 	}
Signature · 1 line
2.50.1
#10 lore raw

Re: [PATCH 3/3] mm/zswap: use %pe to print PTR_ERR() values

…

Quoted 5 lines

+++ b/mm/zswap.c

mm/zswap.c +0 -0
@@ -749,8 +749,8 @@ static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node)
 
 	acomp = crypto_alloc_acomp_node(pool->tfm_name, 0, 0, cpu_to_node(cpu));
 	if (IS_ERR(acomp)) {

…

mm/zswap.c static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node) · line 754

Quoted 3 lines
mm/zswap.c +2 -0
+		pr_err("could not alloc crypto acomp %s : %pe\n",
+				pool->tfm_name, acomp);
 		ret = PTR_ERR(acomp);

…

Would you like to reduce the indentation for the passed parameters?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v6.18-rc6#n110

Regards,
Markus

#11 lore raw

Re: [PATCH 3/3] mm/zswap: use %pe to print PTR_ERR() values

Quoted 7 lines · Markus Elfring

…

Quoted 5 lines

+++ b/mm/zswap.c

mm/zswap.c +0 -0
@@ -749,8 +749,8 @@ static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node)
 
 	acomp = crypto_alloc_acomp_node(pool->tfm_name, 0, 0, cpu_to_node(cpu));
 	if (IS_ERR(acomp)) {

…

Quoted 7 lines

mm/zswap.c static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node) · line 754

Quoted 3 lines
mm/zswap.c +2 -0
+		pr_err("could not alloc crypto acomp %s : %pe\n",
+				pool->tfm_name, acomp);
 		ret = PTR_ERR(acomp);

…

Would you like to reduce the indentation for the passed parameters?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v6.18-rc6#n110

That is the exact opposite of what this suggestion is intended to say.

Sahil, you should ignore any suggestion made to you by Markus. He has been told many times to stop making these useless and unhelpful comments, and yet he persists.

#12 lore raw

Re: [PATCH 3/3] mm/zswap: use %pe to print PTR_ERR() values

Quoted 11 lines
Quoted 11 lines
Quoted 5 lines

+++ b/mm/zswap.c

mm/zswap.c +0 -0
@@ -749,8 +749,8 @@ static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node)
 
 	acomp = crypto_alloc_acomp_node(pool->tfm_name, 0, 0, cpu_to_node(cpu));
 	if (IS_ERR(acomp)) {

…

Quoted 3 lines
mm/zswap.c +2 -0
+		pr_err("could not alloc crypto acomp %s : %pe\n",
+				pool->tfm_name, acomp);
 		ret = PTR_ERR(acomp);

…

Quoted 4 lines
Quoted 2 lines

Would you like to reduce the indentation for the passed parameters?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v6.18-rc6#n110

That is the exact opposite of what this suggestion is intended to say.

I wonder about the interpretation of the provided information in such a direction.

Quoted 1 line

Sahil, you should ignore any suggestion made to you by Markus.

Do you try to distract from reminders according to a known information source here?

Regards,
Markus

Acked-by on v1 3/3
#13 lore raw

Re: [PATCH 3/3] mm/zswap: use %pe to print PTR_ERR() values

In reply to Sahil Chandna
Quoted 11 lines · Sahil Chandna

Use the %pe printk format specifier to report error pointers directly instead of printing PTR_ERR() as a long value. This improves clarity, produces more readable error messages.

This instance was flagged by the Coccinelle script (misc/ptr_err_to_pe.cocci) as an opportunity to adopt %pe.

Found by: make coccicheck MODE=report M=mm/
No functional change intended.

Quoted 22 lines
---
 mm/zswap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/zswap.c +2 -2
index c1af782e54ec..c35604db32ad 100644
@@ -749,8 +749,8 @@ static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node)
 
 	acomp = crypto_alloc_acomp_node(pool->tfm_name, 0, 0, cpu_to_node(cpu));
 	if (IS_ERR(acomp)) {
-		pr_err("could not alloc crypto acomp %s : %ld\n",
-				pool->tfm_name, PTR_ERR(acomp));
+		pr_err("could not alloc crypto acomp %s : %pe\n",
+				pool->tfm_name, acomp);
 		ret = PTR_ERR(acomp);
 		goto fail;
 	}
Signature · 1 line
2.50.1
Reviewed-by on v1 3/3
#14 lore raw

Re: [PATCH 3/3] mm/zswap: use %pe to print PTR_ERR() values

In reply to Sahil Chandna
Quoted 11 lines · On Tue, 18 Nov 2025 11:38:51 +0530 Sahil Chandna <[email protected]>…

Use the %pe printk format specifier to report error pointers directly instead of printing PTR_ERR() as a long value. This improves clarity, produces more readable error messages.

This instance was flagged by the Coccinelle script (misc/ptr_err_to_pe.cocci) as an opportunity to adopt %pe.

Found by: make coccicheck MODE=report M=mm/
No functional change intended.

Thanks,
SJ

[...]

maintainer Acked-by on v1 3/3
#15 lore raw

Re: [PATCH 3/3] mm/zswap: use %pe to print PTR_ERR() values

In reply to Sahil Chandna
Quoted 5 lines · Sahil Chandna

Use the %pe printk format specifier to report error pointers directly instead of printing PTR_ERR() as a long value. This improves clarity, produces more readable error messages.

Quoted 7 lines

This instance was flagged by the Coccinelle script (misc/ptr_err_to_pe.cocci) as an opportunity to adopt %pe.

Found by: make coccicheck MODE=report M=mm/
No functional change intended.