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

From: David Laight

Date: Tue Nov 18 2025 - 11:56:13 EST


On Tue, 18 Nov 2025 15:18:50 +0000
Matthew Wilcox <willy@xxxxxxxxxxxxx> wrote:

> On Tue, Nov 18, 2025 at 10:45:37AM +0000, David Laight wrote:
> > On Tue, 18 Nov 2025 11:38:49 +0530
> > Sahil Chandna <chandna.sahil@xxxxxxxxx> wrote:
> > > +++ b/mm/pagewalk.c
> > > @@ -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);
>
> 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