mm: Coccinelle-driven cleanups across memory management code
Subsystems (5)
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
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
@@ -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
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 usemin().
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
Re: [PATCH 1/3] mm/pagewalk: use min() macro instead of manual ternary
In reply to Sahil ChandnaQuoted 22 lines · On Tue, 18 Nov 2025 11:38:49 +0530 Sahil Chandna <[email protected]>…
mm: pagewalk: use
min()macro instead of manual ternary expressionUse 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 usemin().Found by: make coccicheck MODE=report M=mm/
No functional change intended.Signed-off-by Sahil Chandna <[email protected]>--- mm/pagewalk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/pagewalk.c +0
-0
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,
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.cmm/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);
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.cmm/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
PATCH 2/3 mm/vmscan: use %pe to print PTR_ERR() values
In reply to Sahil ChandnaUse 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
@@ -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
Re: [PATCH 2/3] mm/vmscan: use %pe to print PTR_ERR() values
…
Quoted 4 lines
+++
b/mm/vmscan.cmm/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
Re: [PATCH 2/3] mm/vmscan: use %pe to print PTR_ERR() values
In reply to Sahil ChandnaQuoted 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 intendedSigned-off-by Sahil Chandna <[email protected]>
Thanks,
SJ
[...]
PATCH 3/3 mm/zswap: use %pe to print PTR_ERR() values
In reply to Sahil ChandnaUse 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
@@ -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
Re: [PATCH 3/3] mm/zswap: use %pe to print PTR_ERR() values
…
Quoted 5 lines
+++
b/mm/zswap.cmm/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
Re: [PATCH 3/3] mm/zswap: use %pe to print PTR_ERR() values
Quoted 7 lines · Markus Elfring
…
Quoted 5 lines
+++
b/mm/zswap.cmm/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.
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.cmm/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#n110That 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
Re: [PATCH 3/3] mm/zswap: use %pe to print PTR_ERR() values
In reply to Sahil ChandnaQuoted 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.Signed-off-by Sahil Chandna <[email protected]>
Quoted 22 lines
--- mm/zswap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)mm/zswap.c +2
-2@@ -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
Re: [PATCH 3/3] mm/zswap: use %pe to print PTR_ERR() values
In reply to Sahil ChandnaQuoted 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.Signed-off-by Sahil Chandna <[email protected]>
Thanks,
SJ
[...]
Re: [PATCH 3/3] mm/zswap: use %pe to print PTR_ERR() values
In reply to Sahil ChandnaQuoted 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.Signed-off-by Sahil Chandna <[email protected]>