Skip to contentSkip to conversation

mfd: syscon: Use a unique name with regmap_config

PATCH Superseded Suman Anna 4 participants 9 messages Jan 27, 2020 – Jul 24, 2020

Subsystems (2)
lore
Share & tools
lore

Suman Anna

author
#0 lore raw

PATCH v2 1/1 mfd: syscon: Use a unique name with regmap_config

The DT node full name is currently being used in regmap_config which in turn is used to create the regmap debugfs directories. This name however is not guaranteed to be unique and the regmap debugfs registration can fail in the cases where the syscon nodes have the same unit-address but are present in different DT node hierarchies. Replace this logic using the syscon reg resource address instead (inspired from logic used while creating platform devices) to ensure a unique name is given for each syscon.

---
v2: Fix build warning reported by kbuild test bot
v1: https://patchwork.kernel.org/patch/11346363/

 drivers/mfd/syscon.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mfd/syscon.c +3 -1
index e22197c832e8..f0815d8e6e95 100644
@@ -101,12 +101,14 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_clk)
 		}
 	}
 
-	syscon_config.name = of_node_full_name(np);
+	syscon_config.name = kasprintf(GFP_KERNEL, "%pOFn@%llx", np,
+				       (u64)res.start);
 	syscon_config.reg_stride = reg_io_width;
 	syscon_config.val_bits = reg_io_width * 8;
 	syscon_config.max_register = resource_size(&res) - reg_io_width;
 
 	regmap = regmap_init_mmio(NULL, base, &syscon_config);
+	kfree(syscon_config.name);
 	if (IS_ERR(regmap)) {
 		pr_err("regmap init failed\n");
 		ret = PTR_ERR(regmap);
Signature · 1 line
2.23.0
#1 lore raw
Quoted 22 lines · Suman Anna

The DT node full name is currently being used in regmap_config which in turn is used to create the regmap debugfs directories. This name however is not guaranteed to be unique and the regmap debugfs registration can fail in the cases where the syscon nodes have the same unit-address but are present in different DT node hierarchies. Replace this logic using the syscon reg resource address instead (inspired from logic used while creating platform devices) to ensure a unique name is given for each syscon.

---
v2: Fix build warning reported by kbuild test bot
v1: https://patchwork.kernel.org/patch/11346363/

  drivers/mfd/syscon.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mfd/syscon.c +0 -0
index e22197c832e8..f0815d8e6e95 100644

drivers/mfd/syscon.c static struct syscon *of_syscon_register(struct device_node *np, bool check_clk) · line 105

Quoted 6 lines
drivers/mfd/syscon.c +2 -1
@@ -101,12 +101,14 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_clk)
  		}
  	}
 
-	syscon_config.name = of_node_full_name(np);
+	syscon_config.name = kasprintf(GFP_KERNEL, "%pOFn@%llx", np,
+				       (u64)res.start);

Would it make sense to also include the node name along with the pointer address so that the name is still easily identifiable?

Quoted 10 lines
drivers/mfd/syscon.c +1 -0
  	syscon_config.reg_stride = reg_io_width;
  	syscon_config.val_bits = reg_io_width * 8;
  	syscon_config.max_register = resource_size(&res) - reg_io_width;
 
  	regmap = regmap_init_mmio(NULL, base, &syscon_config);
+	kfree(syscon_config.name);
  	if (IS_ERR(regmap)) {
  		pr_err("regmap init failed\n");
  		ret = PTR_ERR(regmap);
author
#2 lore raw

Hi David,

Quoted 18 lines · David Lechner
Quoted 17 lines · Suman Anna

The DT node full name is currently being used in regmap_config which in turn is used to create the regmap debugfs directories. This name however is not guaranteed to be unique and the regmap debugfs registration can fail in the cases where the syscon nodes have the same unit-address but are present in different DT node hierarchies. Replace this logic using the syscon reg resource address instead (inspired from logic used while creating platform devices) to ensure a unique name is given for each syscon.

---
v2: Fix build warning reported by kbuild test bot
v1: https://patchwork.kernel.org/patch/11346363/

  drivers/mfd/syscon.c | 4 +++-

  1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 14 lines

drivers/mfd/syscon.c static struct syscon *of_syscon_register(struct · line 106

Quoted 11 lines
drivers/mfd/syscon.c +2 -0
index e22197c832e8..f0815d8e6e95 100644
@@ -101,12 +101,14 @@ static struct syscon *of_syscon_register(struct
 device_node *np, bool check_clk)
           }
       }
   -    syscon_config.name = of_node_full_name(np);
+    syscon_config.name = kasprintf(GFP_KERNEL, "%pOFn@%llx", np,
+                       (u64)res.start);

Would it make sense to also include the node name along with the pointer address so that the name is still easily identifiable?

I haven't dropped the node name, it is still there, the pOFn part. I am only replacing the DT unit-address with the bus address, I haven't changed the name style either.

regards
Suman

Quoted 11 lines
Quoted 10 lines
drivers/mfd/syscon.c +1 -0
       syscon_config.reg_stride = reg_io_width;
       syscon_config.val_bits = reg_io_width * 8;
       syscon_config.max_register = resource_size(&res) - reg_io_width;
         regmap = regmap_init_mmio(NULL, base, &syscon_config);
+    kfree(syscon_config.name);
       if (IS_ERR(regmap)) {
           pr_err("regmap init failed\n");
           ret = PTR_ERR(regmap);
#3 lore raw
In reply to Suman Anna

drivers/mfd/syscon.c static struct syscon *of_syscon_register(struct device_node *np, bool check_clk) · line 105

Quoted 13 lines · Suman Anna

The DT node full name is currently being used in regmap_config which in turn is used to create the regmap debugfs directories. This name however is not guaranteed to be unique and the regmap debugfs registration can fail in the cases where the syscon nodes have the same unit-address but are present in different DT node hierarchies. Replace this logic using the syscon reg resource address instead (inspired from logic used while creating platform devices) to ensure a unique name is given for each syscon.

drivers/mfd/syscon.c +2 -1
-       syscon_config.name = of_node_full_name(np);
+       syscon_config.name = kasprintf(GFP_KERNEL, "%pOFn@%llx", np,
+                                      (u64)res.start);

Explicit castings in printf() usually tell us that something is not okay. Yes, for resource_size_t we have %pa.

On top of that, I would rather see %pfwn to avoid modification for other fwnode types.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#4 lore raw

Hi Andy,

Quoted 11 lines · Andy Shevchenko
Quoted 9 lines · Suman Anna

The DT node full name is currently being used in regmap_config which in turn is used to create the regmap debugfs directories. This name however is not guaranteed to be unique and the regmap debugfs registration can fail in the cases where the syscon nodes have the same unit-address but are present in different DT node hierarchies. Replace this logic using the syscon reg resource address instead (inspired from logic used while creating platform devices) to ensure a unique name is given for each syscon.

Quoted 5 lines

drivers/mfd/syscon.c static struct syscon *of_syscon_register(struct device_node *np, bool check_clk) · line 105

Quoted 3 lines
drivers/mfd/syscon.c +2 -1
-       syscon_config.name = of_node_full_name(np);
+       syscon_config.name = kasprintf(GFP_KERNEL, "%pOFn@%llx", np,
+                                      (u64)res.start);

Explicit castings in printf() usually tell us that something is not okay.

Yes, I agree in general.

Quoted 1 line

Yes, for resource_size_t we have %pa.

And that was the first thing I tried when doing v2, before moving away from it. This is not for a console printf statement, but is rather for the regmap debugfs name. Using a %pa adds the 0x and leading zeros in the debugfs name, when compared to the name before this patch. The typecast retains the current format, and replaces the unit-address without the leading 0s either. Introducing a local-variable to avoid the typecast is overkill.

Quoted 3 lines

On top of that, I would rather see %pfwn to avoid modification for other fwnode types.

Did you mean %pfwP? That can probably be handled when syscon code is updated to use fwnode API.

regards
Suman

#5 lore raw
Quoted 2 lines · Suman Anna
Quoted 1 line · Andy Shevchenko

On Tue, Jan 28, 2020 at 1:14 AM Suman Anna <[email protected]> wrote:

...

Quoted 10 lines
Quoted 5 lines

drivers/mfd/syscon.c static struct syscon *of_syscon_register(struct device_node *np, bool check_clk) · line 105

Quoted 3 lines
drivers/mfd/syscon.c +2 -1
-       syscon_config.name = of_node_full_name(np);
+       syscon_config.name = kasprintf(GFP_KERNEL, "%pOFn@%llx", np,
+                                      (u64)res.start);

Explicit castings in printf() usually tell us that something is not okay.

Yes, I agree in general.

Quoted 1 line

Yes, for resource_size_t we have %pa.

Quoted 7 lines

And that was the first thing I tried when doing v2, before moving away from it. This is not for a console printf statement, but is rather for the regmap debugfs name. Using a %pa adds the 0x and leading zeros in the debugfs name, when compared to the name before this patch. The typecast retains the current format, and replaces the unit-address without the leading 0s either. Introducing a local-variable to avoid the typecast is overkill.

Thanks for the clarification.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw
In reply to Suman Anna
Quoted 9 lines · Suman Anna

The DT node full name is currently being used in regmap_config which in turn is used to create the regmap debugfs directories. This name however is not guaranteed to be unique and the regmap debugfs registration can fail in the cases where the syscon nodes have the same unit-address but are present in different DT node hierarchies. Replace this logic using the syscon reg resource address instead (inspired from logic used while creating platform devices) to ensure a unique name is given for each syscon.

Quoted 7 lines

---
v2: Fix build warning reported by kbuild test bot
v1: https://patchwork.kernel.org/patch/11346363/

 drivers/mfd/syscon.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Waiting for Arnd to review.

Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
author
#7 lore raw
Quoted 16 lines · Lee Jones
Quoted 14 lines · Suman Anna

The DT node full name is currently being used in regmap_config which in turn is used to create the regmap debugfs directories. This name however is not guaranteed to be unique and the regmap debugfs registration can fail in the cases where the syscon nodes have the same unit-address but are present in different DT node hierarchies. Replace this logic using the syscon reg resource address instead (inspired from logic used while creating platform devices) to ensure a unique name is given for each syscon.

---
v2: Fix build warning reported by kbuild test bot
v1: https://patchwork.kernel.org/patch/11346363/

Quoted 5 lines
Quoted 2 lines
 drivers/mfd/syscon.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Waiting for Arnd to review.

Hi Arnd,

Gentle ping, any comments?

regards
Suman

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#8 lore raw
In reply to Lee Jones
Quoted 16 lines · Lee Jones
Quoted 14 lines · Suman Anna

The DT node full name is currently being used in regmap_config which in turn is used to create the regmap debugfs directories. This name however is not guaranteed to be unique and the regmap debugfs registration can fail in the cases where the syscon nodes have the same unit-address but are present in different DT node hierarchies. Replace this logic using the syscon reg resource address instead (inspired from logic used while creating platform devices) to ensure a unique name is given for each syscon.

---
v2: Fix build warning reported by kbuild test bot
v1: https://patchwork.kernel.org/patch/11346363/

Quoted 4 lines
Quoted 2 lines
 drivers/mfd/syscon.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Waiting for Arnd to review.

Still waiting for some input from Arnd.

Might be worth submitting a [RESEND].

Signature · 4 lines
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog