* [PATCH] mm/hugetlb_vmemmap: Use max() macro to simplify the code
@ 2026-01-21 1:51 zenghongling
2026-01-21 2:33 ` Muchun Song
2026-01-21 6:17 ` Matthew Wilcox
0 siblings, 2 replies; 4+ messages in thread
From: zenghongling @ 2026-01-21 1:51 UTC (permalink / raw)
To: muchun.song, osalvador, david, akpm
Cc: linux-mm, linux-kernel, zhongling0719, zenghongling
Use the max() macro to simplify the function and improve
its readability.
Signed-off-by: zenghongling <zenghongling@kylinos.cn>
---
mm/hugetlb_vmemmap.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/hugetlb_vmemmap.h b/mm/hugetlb_vmemmap.h
index 18b490825215..abdfa870b096 100644
--- a/mm/hugetlb_vmemmap.h
+++ b/mm/hugetlb_vmemmap.h
@@ -48,7 +48,7 @@ static inline unsigned int hugetlb_vmemmap_optimizable_size(const struct hstate
if (!is_power_of_2(sizeof(struct page)))
return 0;
- return size > 0 ? size : 0;
+ return max(size, 0);
}
#else
static inline int hugetlb_vmemmap_restore_folio(const struct hstate *h, struct folio *folio)
--
2.25.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/hugetlb_vmemmap: Use max() macro to simplify the code
2026-01-21 1:51 [PATCH] mm/hugetlb_vmemmap: Use max() macro to simplify the code zenghongling
@ 2026-01-21 2:33 ` Muchun Song
2026-01-21 6:17 ` Matthew Wilcox
1 sibling, 0 replies; 4+ messages in thread
From: Muchun Song @ 2026-01-21 2:33 UTC (permalink / raw)
To: zenghongling
Cc: osalvador, david, akpm, linux-mm, linux-kernel, zhongling0719
> On Jan 21, 2026, at 09:51, zenghongling <zenghongling@kylinos.cn> wrote:
>
> Use the max() macro to simplify the function and improve
> its readability.
>
> Signed-off-by: zenghongling <zenghongling@kylinos.cn>
Reviewed-by: Muchun Song <muchun.song@linux.dev>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/hugetlb_vmemmap: Use max() macro to simplify the code
2026-01-21 1:51 [PATCH] mm/hugetlb_vmemmap: Use max() macro to simplify the code zenghongling
2026-01-21 2:33 ` Muchun Song
@ 2026-01-21 6:17 ` Matthew Wilcox
2026-01-21 11:32 ` David Laight
1 sibling, 1 reply; 4+ messages in thread
From: Matthew Wilcox @ 2026-01-21 6:17 UTC (permalink / raw)
To: zenghongling
Cc: muchun.song, osalvador, david, akpm, linux-mm, linux-kernel,
zhongling0719
On Wed, Jan 21, 2026 at 09:51:14AM +0800, zenghongling wrote:
> Use the max() macro to simplify the function and improve
> its readability.
How does this improve readability? I understand what this does in
the ternary form. I have to think far harder about it in the max()
form.
> if (!is_power_of_2(sizeof(struct page)))
> return 0;
> - return size > 0 ? size : 0;
> + return max(size, 0);
> }
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/hugetlb_vmemmap: Use max() macro to simplify the code
2026-01-21 6:17 ` Matthew Wilcox
@ 2026-01-21 11:32 ` David Laight
0 siblings, 0 replies; 4+ messages in thread
From: David Laight @ 2026-01-21 11:32 UTC (permalink / raw)
To: Matthew Wilcox
Cc: zenghongling, muchun.song, osalvador, david, akpm, linux-mm,
linux-kernel, zhongling0719
On Wed, 21 Jan 2026 06:17:07 +0000
Matthew Wilcox <willy@infradead.org> wrote:
> On Wed, Jan 21, 2026 at 09:51:14AM +0800, zenghongling wrote:
> > Use the max() macro to simplify the function and improve
> > its readability.
>
> How does this improve readability? I understand what this does in
> the ternary form. I have to think far harder about it in the max()
> form.
I must do a patch for checkpatch.pl to stop it suggesting min/max
for trivial cases.
Oh - and stop it ever suggesting the _t variants.
IMHO it is better to have an explicit cast on one of the parameters.
David
>
> > if (!is_power_of_2(sizeof(struct page)))
> > return 0;
> > - return size > 0 ? size : 0;
> > + return max(size, 0);
> > }
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-01-21 13:16 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-21 1:51 [PATCH] mm/hugetlb_vmemmap: Use max() macro to simplify the code zenghongling
2026-01-21 2:33 ` Muchun Song
2026-01-21 6:17 ` Matthew Wilcox
2026-01-21 11:32 ` David Laight
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox