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

From: Andrew Morton

Date: Thu Jul 30 2026 - 13:44:50 EST


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.