Re: [PATCH] mm: return -ENOMEM for page-table allocation failure in insert_pages()

From: Lorenzo Stoakes (ARM)

Date: Thu Jul 30 2026 - 13:08:03 EST


On Thu, Jul 30, 2026 at 09:15:58AM -0700, Andrew Morton wrote:
> On Thu, 30 Jul 2026 08:42:49 +0100 "Lorenzo Stoakes (ARM)" <ljs@xxxxxxxxxx> wrote:
>
> > pages_to_write_in_pmd = min_t(unsigned long,
> > remaining_pages_total, PTRS_PER_PTE - pte_index(addr));
> >
> > /* Allocate the PTE if necessary; takes PMD lock once only. */
> > ret = -ENOMEM; <------------------------------ set it again?
> > if (pte_alloc(mm, pmd))
> > goto out;
> >
> > The way this function is written is horrible in general, I hate 'preset default
> > return value' as a pattern.
>
> It used to be the preferred way because
>
> ret = -ENOMEM;
> if (expr)
> goto out;
>
> generated slightly better code than
>
> if (expr) {
> ret = -ENOMEM;
> goto out;
> }
>
> Whether that is the case with current compilers I don't know.

Thanks for the background on that!

I'd put money on there being no difference now :) but in any case that kind of
micro-optimisation isn't really a concern here even if it was the case.

--
Cheers, Lorenzo