On Thu, Jul 09, 2026 at 04:45:51PM +0800, Richard Cheng wrote:
> On Tue, Jun 30, 2026 at 05:18:38PM +0800, Gregory Price wrote:
> > +/**
> > + * offline_and_remove_memory_ranges - offline and remove multiple memory
> > ranges
> > + * @ranges: array of physical address ranges to offline and remove
> > + * @nr_ranges: number of entries in @ranges
> > + *
> > + * Offline and remove several memory ranges as one operation, serialized
> > + * against other hotplug operations by a single lock_device_hotplug().
> > + *
> > + * This offlines all ranges before removing any of them. If offlining any
> > + * range fails, the entire process is reverted and nothing is removed.
> > + * This provides a fully atomic semantic for unplugging an entire device.
> > + *
> > + * Each range must be memory-block aligned in start and size.
> > + *
> > + * Return: 0 on success, negative errno otherwise. On failure no range has
> > + * been removed.
> > + */
>
> I think this can return 1, and it shouldn't.
> device_offline() returns 1 when a block is already offline, and phase 1
> passes that value through as-is.
>
I just realized try_offline_memory_block() already clamps the value to 0
static int try_offline_memory_block(struct memory_block *mem, void *arg)
{
...
rc = device_offline(&mem->dev);
...
/* Ignore if already offline. */
return rc < 0 ? rc : 0;
}
But this is a bit non-obvious, let me see about making this a little
bit clearer.
~Gregory