Re: [PATCH v2] mm: folio_zero_user: open code range computation in folio_zero_user()

From: Andrew Morton

Date: Wed Feb 04 2026 - 17:31:22 EST


On Wed, 4 Feb 2026 22:01:42 +0100 "David Hildenbrand (arm)" <david@xxxxxxxxxx> wrote:

> > As David pointed out, the previous open coded version makes a few
> > unnecessary changes. Could you queue this one instead?
> >
>
> I'm late, maybe this is already upstream.

It's in mm-unstable. The second round of MM upstreaming is two weeks hence.

> >
> > /* Region to the left of the fault */
> > - r[1] = DEFINE_RANGE(pg.start,
> > - clamp_t(s64, r[2].start - 1, pg.start - 1, r[2].start));
> > + r[1] = DEFINE_RANGE(pg.start, r[2].start - 1);
> >
> > /* Region to the right of the fault: always valid for the common fault_idx=0 case. */
> > - r[0] = DEFINE_RANGE(clamp_t(s64, r[2].end + 1, r[2].end, pg.end + 1),
> > - pg.end);
> > + r[0] = DEFINE_RANGE(r[2].end + 1, pg.end);
>
> TBH, without the clamp that looks much more readable here.

me too.

> >
> > for (i = 0; i < ARRAY_SIZE(r); i++) {
> > const unsigned long addr = base_addr + r[i].start * PAGE_SIZE;
> > - const unsigned int nr_pages = range_len(&r[i]);
> > + const long nr_pages = (long)range_len(&r[i]);
> > struct page *page = folio_page(folio, r[i].start);
> >
> > if (nr_pages > 0)
> > - clear_contig_highpages(page, addr, nr_pages);
> > + clear_contig_highpages(page, addr, (unsigned int)nr_pages);
>
> Is that cast really required?

Seems not. The types for nr_pages are a bit chaotic - u64->long->uint.