a453f241e0e4023642b97765c5c9c5f42e4e525e
[openwrt/staging/dangole.git] /
1 From 1cd9ceaa5282ff10ea20a7fbadde5a476a1cc99e Mon Sep 17 00:00:00 2001
2 From: Michael Walle <michael@walle.cc>
3 Date: Wed, 8 Mar 2023 09:20:18 +0100
4 Subject: [PATCH] mtd: core: provide unique name for nvmem device, take two
5
6 Commit c048b60d39e1 ("mtd: core: provide unique name for nvmem device")
7 tries to give the nvmem device a unique name, but fails badly if the mtd
8 device doesn't have a "struct device" associated with it, i.e. if
9 CONFIG_MTD_PARTITIONED_MASTER is not set. This will result in the name
10 "(null)-user-otp", which is not unique. It seems the best we can do is
11 to use the compatible name together with a unique identifier added by
12 the nvmem subsystem by using NVMEM_DEVID_AUTO.
13
14 Fixes: c048b60d39e1 ("mtd: core: provide unique name for nvmem device")
15 Cc: stable@vger.kernel.org
16 Signed-off-by: Michael Walle <michael@walle.cc>
17 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
18 Link: https://lore.kernel.org/linux-mtd/20230308082021.870459-1-michael@walle.cc
19 ---
20 drivers/mtd/mtdcore.c | 5 ++---
21 1 file changed, 2 insertions(+), 3 deletions(-)
22
23 --- a/drivers/mtd/mtdcore.c
24 +++ b/drivers/mtd/mtdcore.c
25 @@ -895,8 +895,8 @@ static struct nvmem_device *mtd_otp_nvme
26
27 /* OTP nvmem will be registered on the physical device */
28 config.dev = mtd->dev.parent;
29 - config.name = kasprintf(GFP_KERNEL, "%s-%s", dev_name(&mtd->dev), compatible);
30 - config.id = NVMEM_DEVID_NONE;
31 + config.name = compatible;
32 + config.id = NVMEM_DEVID_AUTO;
33 config.owner = THIS_MODULE;
34 config.type = NVMEM_TYPE_OTP;
35 config.root_only = true;
36 @@ -912,7 +912,6 @@ static struct nvmem_device *mtd_otp_nvme
37 nvmem = NULL;
38
39 of_node_put(np);
40 - kfree(config.name);
41
42 return nvmem;
43 }