Re: [PATCH 2/9] mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg

David Hildenbrand (arm)
2026-02-04T21:08:53Z

On 2/2/26 22:37, Gregory Price wrote:
> On Mon, Feb 02, 2026 at 06:46:09PM +0000, Jonathan Cameron wrote:
>>>
>>> I can add a cleanup-patch prior to use the enum, but i don't think this
>>> actually enables the compiler to do anything new at the moment?
>>
>> Good point. More coffee needed (or sleep)
>>
>> It lets sparse do some checking, but sadly only for wrong enum assignment.
>> (Gcc has -Wenum-conversion as well which I think is effectively the same)
>> I.e. you can't assign a value from a different enum without casting.
>>
>> It can't do anything if people just pass in an out of range int.
>>
>
> Which, after looking a bit... mm/memory_hotplug.c does this quite a bit
> internally - except it uses a uint8_t
>
> Example:
>
> static int try_offline_memory_block(struct memory_block *mem, void *arg)
> {
> uint8_t online_type = MMOP_ONLINE_KERNEL;
> uint8_t **online_types = arg;
> ... snip ...
> }
>
> int offline_and_remove_memory(u64 start, u64 size)
> {
> uint8_t *online_types, *tmp;
> ... snip ...
> online_types = kmalloc_array(mb_count, sizeof(*online_types),
> GFP_KERNEL);
> }
>
> So that's fun.
>
> I'm not sure it's worth the churn here, but happy to do it if there are
> strong opinions.
>
> ---
>
> David do you have thoughts here?

I guess we should clean that all up where easily possible, but I don't
expect you to do that.

For online_types I used it, obviously, to save memory. So I'd expect it
to stay at least there, but cast it to the proper type once we take it
out the array.

--
Cheers,

David