[2/2] misc: sram: Generate unique names for subpools

Message ID 20230417-ux500-sram-v1-2-5924988bb835@linaro.org
State New
Headers
Series SRAM dt binding and fix |

Commit Message

Linus Walleij April 17, 2023, 7:34 a.m. UTC
  The current code will, if we do not specify unique labels
for the SRAM subnodes, fail to register several nodes named
the same.

Example:

sram@40020000 {
  (...)
  sram@0 {
    (...)
  };
  sram@1000 {
    (...)
  };
};

Since the child->name in both cases will be "sram" the
gen_pool_create() will fail because the name is not unique.
So let's use of_full_node_name() instead of child->name
so the name is "sram@0" and "sram@1000" respectively.

However if there are two or more SRAMs on the system
with subnodes named the same (that exists on the U8500)
then this again will not work. So catenate the top node
name and the subnode full name to form a string that will
always be unique.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/misc/sram.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
  

Comments

Rob Herring April 18, 2023, 10:38 p.m. UTC | #1
On Mon, Apr 17, 2023 at 09:34:57AM +0200, Linus Walleij wrote:
> The current code will, if we do not specify unique labels
> for the SRAM subnodes, fail to register several nodes named
> the same.
> 
> Example:
> 
> sram@40020000 {
>   (...)
>   sram@0 {
>     (...)
>   };
>   sram@1000 {
>     (...)
>   };
> };
> 
> Since the child->name in both cases will be "sram" the
> gen_pool_create() will fail because the name is not unique.
> So let's use of_full_node_name() instead of child->name
> so the name is "sram@0" and "sram@1000" respectively.
> 
> However if there are two or more SRAMs on the system
> with subnodes named the same (that exists on the U8500)
> then this again will not work. So catenate the top node
> name and the subnode full name to form a string that will
> always be unique.

Use the naming platform devices use which has the translated address.
How the addresses are defined should not affect the device name.

Rob
  
Linus Walleij April 19, 2023, 12:56 p.m. UTC | #2
On Wed, Apr 19, 2023 at 12:38 AM Rob Herring <robh@kernel.org> wrote:
> On Mon, Apr 17, 2023 at 09:34:57AM +0200, Linus Walleij wrote:
> > The current code will, if we do not specify unique labels
> > for the SRAM subnodes, fail to register several nodes named
> > the same.
> >
> > Example:
> >
> > sram@40020000 {
> >   (...)
> >   sram@0 {
> >     (...)
> >   };
> >   sram@1000 {
> >     (...)
> >   };
> > };
> >
> > Since the child->name in both cases will be "sram" the
> > gen_pool_create() will fail because the name is not unique.
> > So let's use of_full_node_name() instead of child->name
> > so the name is "sram@0" and "sram@1000" respectively.
> >
> > However if there are two or more SRAMs on the system
> > with subnodes named the same (that exists on the U8500)
> > then this again will not work. So catenate the top node
> > name and the subnode full name to form a string that will
> > always be unique.
>
> Use the naming platform devices use which has the translated address.
> How the addresses are defined should not affect the device name.

Aha just dev_name(&pdev->dev) I'll try this, thanks!

Yours,
Linus Walleij
  

Patch

diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c
index f0e7f02605eb..84d4e090678b 100644
--- a/drivers/misc/sram.c
+++ b/drivers/misc/sram.c
@@ -240,10 +240,12 @@  static int sram_reserve_regions(struct sram_dev *sram, struct resource *res)
 				goto err_chunks;
 			}
 			if (!label)
-				label = child->name;
-
-			block->label = devm_kstrdup(sram->dev,
-						    label, GFP_KERNEL);
+				block->label = devm_kasprintf(sram->dev, GFP_KERNEL,
+							"%s-%s", dev_name(sram->dev),
+							of_node_full_name(child));
+			else
+				block->label = devm_kstrdup(sram->dev,
+							    label, GFP_KERNEL);
 			if (!block->label) {
 				ret = -ENOMEM;
 				goto err_chunks;