linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
	kernel@pengutronix.de
Subject: Re: nvmem creates multiple devices with the same name
Date: Tue, 2 Jul 2019 17:54:54 +0100	[thread overview]
Message-ID: <45d0cfaf-2511-4b1e-f4da-b67fa9f9e867@linaro.org> (raw)
In-Reply-To: <20190701080642.4oxmw7c3rmwrt5ee@pengutronix.de>

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@linaro.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
> 

  reply	other threads:[~2019-07-02 16:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-21  8:56 nvmem creates multiple devices with the same name Sascha Hauer
2019-05-21  9:02 ` Srinivas Kandagatla
2019-05-21  9:21   ` Sascha Hauer
2019-07-01  8:06     ` Sascha Hauer
2019-07-02 16:54       ` Srinivas Kandagatla [this message]
2019-07-08  7:14         ` Sascha Hauer
2019-07-02 18:59 ` Boris Brezillon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45d0cfaf-2511-4b1e-f4da-b67fa9f9e867@linaro.org \
    --to=srinivas.kandagatla@linaro.org \
    --cc=kernel@pengutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).