Re: [PATCH] mtd: take a reference when opening an unpartitioned master

From: Miquel Raynal

Date: Fri Nov 20 2026 - 09:55:37 EST


On 08/11/2026 at 14:12:39 -07, James Hilliard <james.hilliard1@xxxxxxxxx> wrote:

> CONFIG_MTD_PARTITIONED_MASTER controls whether a master is registered
> alongside its partitions. Without that option, an unpartitioned device
> is still registered as a master and can be opened directly.

"can be opened directly"

> __get_mtd_device() skips the master while walking the parent chain and
> only takes its reference when CONFIG_MTD_PARTITIONED_MASTER is enabled.
> A direct open therefore leaves the registration reference as the sole
> reference. Unregistering the device releases its device-model and
> NVMEM

"releases its device-model"

> state while the handle remains open.
>
> Take and release the master reference for direct opens as well. Retain
> the existing behavior for partition handles whose master is not
> registered.

Is this really what you do? The code does not test whether the
master is registered. The condition is:

mtd == master || IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER)

As a result:

- A handle on the master takes a master reference.
- A handle on a partition takes a master reference only when
CONFIG_MTD_PARTITIONED_MASTER is enabled.

No? I believe the code is correct, but that's again one of those very
imprecise commit logs where words taken independently are fine but put
alltogether don't build any meaningful message in my brain. Maybe:

A handle on the master now takes a master reference. A handle on a
partition takes a master reference only when CONFIG_MTD_PARTITIONED_MASTER
is enabled.

In general I think this commit log must be reworded.

Thanks,
Miquèl