nvmem: core: Allow allocating several anonymous nvmem devices
authorAban Bedel <albeu@free.fr>
Fri, 31 Mar 2017 12:44:46 +0000 (13:44 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 8 Apr 2017 15:51:48 +0000 (17:51 +0200)
Currently the nvmem core expect the config to provide a name and ID
that are then used to create the device name. When no device name is
given 'nvmem' is used. However if there is several such anonymous
devices they all get named 'nvmem0', which doesn't work.

To fix this problem use the ID from the config only when the config
also provides a name. When no name is provided take the uinque ID of
the nvmem device instead.

Signed-off-by: Aban Bedel <albeu@free.fr>
Reviewed-by: Moritz Fischer <mdf@kernel.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/nvmem/core.c

index 408b521ee5209b9775c691113b854d027a8677fa..8c830a80a648f1d649c35f0af2fdc1493bdba725 100644 (file)
@@ -468,7 +468,8 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
        np = config->dev->of_node;
        nvmem->dev.of_node = np;
        dev_set_name(&nvmem->dev, "%s%d",
-                    config->name ? : "nvmem", config->id);
+                    config->name ? : "nvmem",
+                    config->name ? config->id : nvmem->id);
 
        nvmem->read_only = of_property_read_bool(np, "read-only") |
                           config->read_only;