Re: [PATCH v2 1/4] mtd: core: provide unique name for nvmem device, take two

From: Miquel Raynal
Date: Wed Mar 08 2023 - 08:43:14 EST


Hi Michael,

michael@xxxxxxxx wrote on Wed, 8 Mar 2023 09:20:18 +0100:

> Commit c048b60d39e1 ("mtd: core: provide unique name for nvmem device")
> tries to give the nvmem device a unique name, but fails badly if the mtd
> device doesn't have a "struct device" associated with it, i.e. if
> CONFIG_MTD_PARTITIONED_MASTER is not set. This will result in the name
> "(null)-user-otp", which is not unique. It seems the best we can do is
> to use the compatible name together with a unique identifier added by
> the nvmem subsystem by using NVMEM_DEVID_AUTO.
>
> Fixes: c048b60d39e1 ("mtd: core: provide unique name for nvmem device")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Michael Walle <michael@xxxxxxxx>
> ---
> v2:
> - actually use NVMEM_DEVID_AUTO as described in the commit message
>

Thanks for the v2, as I want to share a clean immutable branch with
Greg, I made an exception in force pushing this patch in place of its
v1 counterpart.

> drivers/mtd/mtdcore.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
> index 0feacb9fbdac..8fc66cda4a09 100644
> --- a/drivers/mtd/mtdcore.c
> +++ b/drivers/mtd/mtdcore.c
> @@ -888,8 +888,8 @@ static struct nvmem_device *mtd_otp_nvmem_register(struct mtd_info *mtd,
>
> /* OTP nvmem will be registered on the physical device */
> config.dev = mtd->dev.parent;
> - config.name = kasprintf(GFP_KERNEL, "%s-%s", dev_name(&mtd->dev), compatible);
> - config.id = NVMEM_DEVID_NONE;
> + config.name = compatible;
> + config.id = NVMEM_DEVID_AUTO;
> config.owner = THIS_MODULE;
> config.type = NVMEM_TYPE_OTP;
> config.root_only = true;
> @@ -905,7 +905,6 @@ static struct nvmem_device *mtd_otp_nvmem_register(struct mtd_info *mtd,
> nvmem = NULL;
>
> of_node_put(np);
> - kfree(config.name);
>
> return nvmem;
> }


Thanks,
Miquèl