Re: [PATCH v3 1/2] x86/mm: Handle alloc failure in phys_*_init()

From: H. Peter Anvin
Date: Wed Jun 11 2025 - 19:09:32 EST


On June 10, 2025 7:55:36 AM PDT, Dave Hansen <dave.hansen@xxxxxxxxx> wrote:
>On 6/10/25 03:16, Em Sharnoff wrote:
>> + if (!pmd)
>> + return (unsigned long)ERR_PTR(-ENOMEM);
>
>All of this casting isn't great to look at. Just about every line of
>code that this patch touches also introduces has a cast.
>
>Could you please find a way to reduce the number of casts?
>
>> + /*
>> + * We might have IS_ERR(paddr_last) if allocation failed, but we should
>> + * still update pud before bailing, so that subsequent retries can pick
>> + * up on progress (here and in phys_pmd_init) without leaking pmd.
>> + */
>
>Please write everything in imperative voice. No "we's", please.
>
>> - for (i = 0; i < nr_range; i++)
>> + for (i = 0; i < nr_range; i++) {
>> ret = kernel_physical_mapping_init(mr[i].start, mr[i].end,
>> mr[i].page_size_mask,
>> prot);
>> + if (IS_ERR((void *)ret))
>> + return ret;
>> + }
>
>Are there any _actual_ users of 'paddr_last'? I see a lot of setting it
>and passing it around, but I _think_ this is the only place it actually
>gets used. Here, the fact that it's an address doesn't even matter.
>
>

Given that ERR_PTR and IS_ERR are basically just casts to and from pointers, why have them at all?