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

From: Gregory Price

Date: Mon Feb 02 2026 - 16:39:01 EST


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?

~Gregory