[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <45d0cfaf-2511-4b1e-f4da-b67fa9f9e867@linaro.org>
Date: Tue, 2 Jul 2019 17:54:54 +0100
From: Srinivas Kandagatla <srinivas.kandagatla@...aro.org>
To: Sascha Hauer <s.hauer@...gutronix.de>
Cc: linux-mtd@...ts.infradead.org, linux-kernel@...r.kernel.org,
kernel@...gutronix.de
Subject: Re: nvmem creates multiple devices with the same name
Hi Sascha,
On 01/07/2019 09:06, Sascha Hauer wrote:
> Hi Srinivas,
>
> On Tue, May 21, 2019 at 11:21:07AM +0200, Sascha Hauer wrote:
>> On Tue, May 21, 2019 at 10:02:32AM +0100, Srinivas Kandagatla wrote:
>>>
>>>
>>> On 21/05/2019 09:56, Sascha Hauer wrote:
>>>> . Are there any suggestions how to register the nvmem devices
>>>> with a different name?
>>>
>>> struct nvmem_config provides id field for this purpose, this will be used by
>>> nvmem to set the device name space along with name field.
>>
>> There's no way for a caller to know a unique name/id combination.
>> The mtd layer could initialize the id field with the mtd number, but
>> that would still not guarantee that another caller, like an EEPROM
>> driver or such, doesn't use the same name/id combination.
>
> This is still an unresolved issue. Do you have any input how we could
> proceed here?
Sorry for the delay!
I think simplest solution would be to check if there is already an nvmem
provider with the same name before assigning name to the device and then
append the id in case it exists.
Let me know if below patch helps the situation so that I can take this
in next cycle!
----------------------------------->cut<----------------------------
nvmem: core: Check nvmem device name before adding the same one
In some usecases where nvmem names are directly derived from
partition names, its likely that different devices might have
same partition name.
This will be an issue as we will be creating two different
nvmem devices with same name and sysfs will not be very happy with
that.
Simple solution is to check the existance of the nvmem provider with
same name and append an id if it exists before creating the device
name.
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@...aro.org>
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index f24008b66826..cf70a405023c 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -641,7 +641,11 @@ struct nvmem_device *nvmem_register(const struct
nvmem_config *config)
nvmem->dev.of_node = config->dev->of_node;
if (config->id == -1 && config->name) {
- dev_set_name(&nvmem->dev, "%s", config->name);
+ if (nvmem_find(config->name))
+ dev_set_name(&nvmem->dev, "%s%d", config->name,
+ nvmem->id);
+ else
+ dev_set_name(&nvmem->dev, "%s", config->name);
} else {
dev_set_name(&nvmem->dev, "%s%d",
config->name ? : "nvmem",
----------------------------------->cut<----------------------------
>
> Thanks
> Sascha
>
Powered by blists - more mailing lists