linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] of: Convert to using %pOFn for node name printf
@ 2018-08-28 15:52 Rob Herring
  2018-08-28 15:52 ` [PATCH 1/4] of/unittest: remove use of node name pointer in overlay high level test Rob Herring
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Rob Herring @ 2018-08-28 15:52 UTC (permalink / raw)
  To: Frank Rowand, devicetree; +Cc: linux-kernel

This is the DT portion of converting node name printf's to use the 
%pOFn format specifier rather than device_node.name. Patches for other 
subsystems are independent and have been sent separately.

Rob

Rob Herring (4):
  of/unittest: remove use of node name pointer in overlay high level
    test
  of/unittest: add printf tests for node name
  of: Convert to using %pOFn instead of device_node.name
  vsprintf: print OF node name using full_name

 drivers/of/device.c   |  4 ++--
 drivers/of/of_mdio.c  | 12 ++++++------
 drivers/of/of_numa.c  |  4 ++--
 drivers/of/overlay.c  |  4 ++--
 drivers/of/platform.c |  8 ++++----
 drivers/of/unittest.c | 26 ++++++++++++++++----------
 lib/vsprintf.c        |  9 +++++++--
 7 files changed, 39 insertions(+), 28 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/4] of/unittest: remove use of node name pointer in overlay high level test
  2018-08-28 15:52 [PATCH 0/4] of: Convert to using %pOFn for node name printf Rob Herring
@ 2018-08-28 15:52 ` Rob Herring
  2018-08-28 15:52 ` [PATCH 2/4] of/unittest: add printf tests for node name Rob Herring
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Rob Herring @ 2018-08-28 15:52 UTC (permalink / raw)
  To: Frank Rowand, devicetree; +Cc: linux-kernel

In preparation for removing the node name pointer, it needs to be
removed from of_unittest_overlay_high_level. However, it's not really
correct to use the node name without the unit-address and we should use
the full node name. This most easily done by iterating over the child
nodes with for_each_child_of_node() which is what of_get_child_by_name()
does internally. While at it, we might as well convert the outer loop to
use for_each_child_of_node() too instead of open coding it.

Cc: Frank Rowand <frowand.list@gmail.com>
Signed-off-by: Rob Herring <robh@kernel.org>
---
 drivers/of/unittest.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index 722537e14848..69a522e48970 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -2347,10 +2347,12 @@ static __init void of_unittest_overlay_high_level(void)
 		}
 	}
 
-	for (np = overlay_base_root->child; np; np = np->sibling) {
-		if (of_get_child_by_name(of_root, np->name)) {
-			unittest(0, "illegal node name in overlay_base %s",
-				np->name);
+	for_each_child_of_node(overlay_base_root, np) {
+		struct device_node *base_child;
+		for_each_child_of_node(of_root, base_child) {
+			if (!strcmp(np->full_name, base_child->full_name))
+				unittest(0, "illegal node name in overlay_base %pOFn",
+					np);
 			return;
 		}
 	}
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/4] of/unittest: add printf tests for node name
  2018-08-28 15:52 [PATCH 0/4] of: Convert to using %pOFn for node name printf Rob Herring
  2018-08-28 15:52 ` [PATCH 1/4] of/unittest: remove use of node name pointer in overlay high level test Rob Herring
@ 2018-08-28 15:52 ` Rob Herring
  2018-08-28 15:52 ` [PATCH 3/4] of: Convert to using %pOFn instead of device_node.name Rob Herring
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Rob Herring @ 2018-08-28 15:52 UTC (permalink / raw)
  To: Frank Rowand, devicetree; +Cc: linux-kernel

Add some printf test for printing the node name (without the
unit-address).

Cc: Frank Rowand <frowand.list@gmail.com>
Signed-off-by: Rob Herring <robh@kernel.org>
---
 drivers/of/unittest.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index 69a522e48970..9def7be9c111 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -299,6 +299,10 @@ static void __init of_unittest_printf(void)
 
 	of_unittest_printf_one(np, "%pOF",  full_name);
 	of_unittest_printf_one(np, "%pOFf", full_name);
+	of_unittest_printf_one(np, "%pOFn", "dev");
+	of_unittest_printf_one(np, "%2pOFn", "dev");
+	of_unittest_printf_one(np, "%5pOFn", "  dev");
+	of_unittest_printf_one(np, "%pOFnc", "dev:test-sub-device");
 	of_unittest_printf_one(np, "%pOFp", phandle_str);
 	of_unittest_printf_one(np, "%pOFP", "dev@100");
 	of_unittest_printf_one(np, "ABC %pOFP ABC", "ABC dev@100 ABC");
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/4] of: Convert to using %pOFn instead of device_node.name
  2018-08-28 15:52 [PATCH 0/4] of: Convert to using %pOFn for node name printf Rob Herring
  2018-08-28 15:52 ` [PATCH 1/4] of/unittest: remove use of node name pointer in overlay high level test Rob Herring
  2018-08-28 15:52 ` [PATCH 2/4] of/unittest: add printf tests for node name Rob Herring
@ 2018-08-28 15:52 ` Rob Herring
  2018-09-07 12:29   ` Thierry Reding
  2018-08-28 15:52 ` [PATCH 4/4] vsprintf: print OF node name using full_name Rob Herring
  2018-08-31 23:51 ` [PATCH 0/4] of: Convert to using %pOFn for node name printf Frank Rowand
  4 siblings, 1 reply; 10+ messages in thread
From: Rob Herring @ 2018-08-28 15:52 UTC (permalink / raw)
  To: Frank Rowand, devicetree
  Cc: linux-kernel, Andrew Lunn, Florian Fainelli, netdev

In preparation to remove the node name pointer from struct device_node,
convert printf users to use the %pOFn format specifier.

Cc: Frank Rowand <frowand.list@gmail.com>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: devicetree@vger.kernel.org
Cc: netdev@vger.kernel.org
Signed-off-by: Rob Herring <robh@kernel.org>
---
 drivers/of/device.c   |  4 ++--
 drivers/of/of_mdio.c  | 12 ++++++------
 drivers/of/of_numa.c  |  4 ++--
 drivers/of/overlay.c  |  4 ++--
 drivers/of/platform.c |  8 ++++----
 drivers/of/unittest.c | 12 ++++++------
 6 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/drivers/of/device.c b/drivers/of/device.c
index 5957cd4fa262..daa075d87317 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -219,7 +219,7 @@ static ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len
 		return -ENODEV;
 
 	/* Name & Type */
-	csize = snprintf(str, len, "of:N%sT%s", dev->of_node->name,
+	csize = snprintf(str, len, "of:N%pOFnT%s", dev->of_node,
 			 dev->of_node->type);
 	tsize = csize;
 	len -= csize;
@@ -298,7 +298,7 @@ void of_device_uevent(struct device *dev, struct kobj_uevent_env *env)
 	if ((!dev) || (!dev->of_node))
 		return;
 
-	add_uevent_var(env, "OF_NAME=%s", dev->of_node->name);
+	add_uevent_var(env, "OF_NAME=%pOFn", dev->of_node);
 	add_uevent_var(env, "OF_FULLNAME=%pOF", dev->of_node);
 	if (dev->of_node->type && strcmp("<NULL>", dev->of_node->type) != 0)
 		add_uevent_var(env, "OF_TYPE=%s", dev->of_node->type);
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index e92391d6d1bd..5ad1342f5682 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -97,8 +97,8 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio,
 		return rc;
 	}
 
-	dev_dbg(&mdio->dev, "registered phy %s at address %i\n",
-		child->name, addr);
+	dev_dbg(&mdio->dev, "registered phy %pOFn at address %i\n",
+		child, addr);
 	return 0;
 }
 
@@ -127,8 +127,8 @@ static int of_mdiobus_register_device(struct mii_bus *mdio,
 		return rc;
 	}
 
-	dev_dbg(&mdio->dev, "registered mdio device %s at address %i\n",
-		child->name, addr);
+	dev_dbg(&mdio->dev, "registered mdio device %pOFn at address %i\n",
+		child, addr);
 	return 0;
 }
 
@@ -263,8 +263,8 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
 				continue;
 
 			/* be noisy to encourage people to set reg property */
-			dev_info(&mdio->dev, "scan phy %s at address %i\n",
-				 child->name, addr);
+			dev_info(&mdio->dev, "scan phy %pOFn at address %i\n",
+				 child, addr);
 
 			if (of_mdiobus_child_is_phy(child)) {
 				rc = of_mdiobus_register_phy(mdio, child, addr);
diff --git a/drivers/of/of_numa.c b/drivers/of/of_numa.c
index 27d9b4bba535..67d3386195bf 100644
--- a/drivers/of/of_numa.c
+++ b/drivers/of/of_numa.c
@@ -163,8 +163,8 @@ int of_node_to_nid(struct device_node *device)
 		np = of_get_next_parent(np);
 	}
 	if (np && r)
-		pr_warn("Invalid \"numa-node-id\" property in node %s\n",
-			np->name);
+		pr_warn("Invalid \"numa-node-id\" property in node %pOFn\n",
+			np);
 	of_node_put(np);
 
 	/*
diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index eda57ef12fd0..42b1f73ac5f6 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -425,8 +425,8 @@ static int build_changeset_next_level(struct overlay_changeset *ovcs,
 	for_each_child_of_node(overlay_node, child) {
 		ret = add_changeset_node(ovcs, target_node, child);
 		if (ret) {
-			pr_debug("Failed to apply node @%pOF/%s, err=%d\n",
-				 target_node, child->name, ret);
+			pr_debug("Failed to apply node @%pOF/%pOFn, err=%d\n",
+				 target_node, child, ret);
 			of_node_put(child);
 			return ret;
 		}
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 7ba90c290a42..868905f2d638 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -91,8 +91,8 @@ static void of_device_make_bus_id(struct device *dev)
 		 */
 		reg = of_get_property(node, "reg", NULL);
 		if (reg && (addr = of_translate_address(node, reg)) != OF_BAD_ADDR) {
-			dev_set_name(dev, dev_name(dev) ? "%llx.%s:%s" : "%llx.%s",
-				     (unsigned long long)addr, node->name,
+			dev_set_name(dev, dev_name(dev) ? "%llx.%pOFn:%s" : "%llx.%pOFn",
+				     (unsigned long long)addr, node,
 				     dev_name(dev));
 			return;
 		}
@@ -142,8 +142,8 @@ struct platform_device *of_device_alloc(struct device_node *np,
 			WARN_ON(rc);
 		}
 		if (of_irq_to_resource_table(np, res, num_irq) != num_irq)
-			pr_debug("not all legacy IRQ resources mapped for %s\n",
-				 np->name);
+			pr_debug("not all legacy IRQ resources mapped for %pOFn\n",
+				 np);
 	}
 
 	dev->dev.of_node = of_node_get(np);
diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index 9def7be9c111..d9d012198ca5 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -212,8 +212,8 @@ static int __init of_unittest_check_node_linkage(struct device_node *np)
 
 	for_each_child_of_node(np, child) {
 		if (child->parent != np) {
-			pr_err("Child node %s links to wrong parent %s\n",
-				 child->name, np->name);
+			pr_err("Child node %pOFn links to wrong parent %pOFn\n",
+				 child, np);
 			rc = -EINVAL;
 			goto put_child;
 		}
@@ -1040,16 +1040,16 @@ static void __init of_unittest_platform_populate(void)
 	for_each_child_of_node(np, child) {
 		for_each_child_of_node(child, grandchild)
 			unittest(of_find_device_by_node(grandchild),
-				 "Could not create device for node '%s'\n",
-				 grandchild->name);
+				 "Could not create device for node '%pOFn'\n",
+				 grandchild);
 	}
 
 	of_platform_depopulate(&test_bus->dev);
 	for_each_child_of_node(np, child) {
 		for_each_child_of_node(child, grandchild)
 			unittest(!of_find_device_by_node(grandchild),
-				 "device didn't get destroyed '%s'\n",
-				 grandchild->name);
+				 "device didn't get destroyed '%pOFn'\n",
+				 grandchild);
 	}
 
 	platform_device_unregister(test_bus);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/4] vsprintf: print OF node name using full_name
  2018-08-28 15:52 [PATCH 0/4] of: Convert to using %pOFn for node name printf Rob Herring
                   ` (2 preceding siblings ...)
  2018-08-28 15:52 ` [PATCH 3/4] of: Convert to using %pOFn instead of device_node.name Rob Herring
@ 2018-08-28 15:52 ` Rob Herring
  2018-08-31 23:51 ` [PATCH 0/4] of: Convert to using %pOFn for node name printf Frank Rowand
  4 siblings, 0 replies; 10+ messages in thread
From: Rob Herring @ 2018-08-28 15:52 UTC (permalink / raw)
  To: Frank Rowand, devicetree; +Cc: linux-kernel

In preparation to remove the node name pointer from struct device_node,
convert the node name print to get the node name from the full name.

Signed-off-by: Rob Herring <robh@kernel.org>
---
 lib/vsprintf.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index d5b3a3f95c01..891c282092a0 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1596,6 +1596,7 @@ char *device_node_string(char *buf, char *end, struct device_node *dn,
 		fmt = "f";
 
 	for (pass = false; strspn(fmt,"fnpPFcC"); fmt++, pass = true) {
+		int precision;
 		if (pass) {
 			if (buf < end)
 				*buf = ':';
@@ -1607,7 +1608,11 @@ char *device_node_string(char *buf, char *end, struct device_node *dn,
 			buf = device_node_gen_full_name(dn, buf, end);
 			break;
 		case 'n':	/* name */
-			buf = string(buf, end, dn->name, str_spec);
+			p = kbasename(of_node_full_name(dn));
+			precision = str_spec.precision;
+			str_spec.precision = strchrnul(p, '@') - p;
+			buf = string(buf, end, p, str_spec);
+			str_spec.precision = precision;
 			break;
 		case 'p':	/* phandle */
 			buf = number(buf, end, (unsigned int)dn->phandle, num_spec);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/4] of: Convert to using %pOFn for node name printf
  2018-08-28 15:52 [PATCH 0/4] of: Convert to using %pOFn for node name printf Rob Herring
                   ` (3 preceding siblings ...)
  2018-08-28 15:52 ` [PATCH 4/4] vsprintf: print OF node name using full_name Rob Herring
@ 2018-08-31 23:51 ` Frank Rowand
  4 siblings, 0 replies; 10+ messages in thread
From: Frank Rowand @ 2018-08-31 23:51 UTC (permalink / raw)
  To: Rob Herring, devicetree; +Cc: linux-kernel

On 08/28/18 08:52, Rob Herring wrote:
> This is the DT portion of converting node name printf's to use the 
> %pOFn format specifier rather than device_node.name. Patches for other 
> subsystems are independent and have been sent separately.
> 
> Rob
> 
> Rob Herring (4):
>   of/unittest: remove use of node name pointer in overlay high level
>     test
>   of/unittest: add printf tests for node name
>   of: Convert to using %pOFn instead of device_node.name
>   vsprintf: print OF node name using full_name
> 
>  drivers/of/device.c   |  4 ++--
>  drivers/of/of_mdio.c  | 12 ++++++------
>  drivers/of/of_numa.c  |  4 ++--
>  drivers/of/overlay.c  |  4 ++--
>  drivers/of/platform.c |  8 ++++----
>  drivers/of/unittest.c | 26 ++++++++++++++++----------
>  lib/vsprintf.c        |  9 +++++++--
>  7 files changed, 39 insertions(+), 28 deletions(-)
> 


Reviewed-by: Frank Rowand <frank.rowand@sony.com>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/4] of: Convert to using %pOFn instead of device_node.name
  2018-08-28 15:52 ` [PATCH 3/4] of: Convert to using %pOFn instead of device_node.name Rob Herring
@ 2018-09-07 12:29   ` Thierry Reding
  2018-09-07 14:58     ` Rob Herring
  2018-09-08  0:30     ` Joe Perches
  0 siblings, 2 replies; 10+ messages in thread
From: Thierry Reding @ 2018-09-07 12:29 UTC (permalink / raw)
  To: Rob Herring
  Cc: Frank Rowand, devicetree, linux-kernel, Andrew Lunn,
	Florian Fainelli, netdev

[-- Attachment #1: Type: text/plain, Size: 2503 bytes --]

On Tue, Aug 28, 2018 at 10:52:53AM -0500, Rob Herring wrote:
> In preparation to remove the node name pointer from struct device_node,
> convert printf users to use the %pOFn format specifier.
> 
> Cc: Frank Rowand <frowand.list@gmail.com>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Cc: devicetree@vger.kernel.org
> Cc: netdev@vger.kernel.org
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---
>  drivers/of/device.c   |  4 ++--
>  drivers/of/of_mdio.c  | 12 ++++++------
>  drivers/of/of_numa.c  |  4 ++--
>  drivers/of/overlay.c  |  4 ++--
>  drivers/of/platform.c |  8 ++++----
>  drivers/of/unittest.c | 12 ++++++------
>  6 files changed, 22 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/of/device.c b/drivers/of/device.c
> index 5957cd4fa262..daa075d87317 100644
> --- a/drivers/of/device.c
> +++ b/drivers/of/device.c
> @@ -219,7 +219,7 @@ static ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len
>  		return -ENODEV;
>  
>  	/* Name & Type */
> -	csize = snprintf(str, len, "of:N%sT%s", dev->of_node->name,
> +	csize = snprintf(str, len, "of:N%pOFnT%s", dev->of_node,
>  			 dev->of_node->type);
>  	tsize = csize;
>  	len -= csize;

This seems to cause the modalias to be improperly constructed. As a
consequence, automatic module loading at boot time is now broken. I
think the reason why this fails is because vsnprintf() will skip all
alpha-numeric characters after a call to pointer(). Presumably this
is meant to be a generic way of skipping whatever specifiers we throw
at it.

Unfortunately for the case of OF modaliases, this means that the 'T'
character gets eaten, so we end up with something like this:

	# udevadm info /sys/bus/platform/devices/54200000.dc
	[...]
	E: MODALIAS=of:Ndc<NULL>Cnvidia,tegra124-dc
	[...]

instead of this:

	# udevadm info /sys/bus/platform/devices/54200000.dc
	[...]
	E: MODALIAS=of:NdcT<NULL>Cnvidia,tegra124-dc
	[...]

Everything is back to normal if I revert this patch. However, since
that's obviously not what we want, I think perhaps what we need is a
way for pointer() (and its implementations) to report back how many
characters in the format string it consumed so that we can support
these kinds of back-to-back strings.

If nobody else has the time I can look into coding up a fix, but in the
meantime it might be best to back this one out until we can handle the
OF modalias format string.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/4] of: Convert to using %pOFn instead of device_node.name
  2018-09-07 12:29   ` Thierry Reding
@ 2018-09-07 14:58     ` Rob Herring
  2018-09-08  0:30     ` Joe Perches
  1 sibling, 0 replies; 10+ messages in thread
From: Rob Herring @ 2018-09-07 14:58 UTC (permalink / raw)
  To: Thierry Reding
  Cc: Frank Rowand, devicetree, linux-kernel, Andrew Lunn,
	Florian Fainelli, netdev

On Fri, Sep 7, 2018 at 7:29 AM Thierry Reding <thierry.reding@gmail.com> wrote:
>
> On Tue, Aug 28, 2018 at 10:52:53AM -0500, Rob Herring wrote:
> > In preparation to remove the node name pointer from struct device_node,
> > convert printf users to use the %pOFn format specifier.
> >
> > Cc: Frank Rowand <frowand.list@gmail.com>
> > Cc: Andrew Lunn <andrew@lunn.ch>
> > Cc: Florian Fainelli <f.fainelli@gmail.com>
> > Cc: devicetree@vger.kernel.org
> > Cc: netdev@vger.kernel.org
> > Signed-off-by: Rob Herring <robh@kernel.org>
> > ---
> >  drivers/of/device.c   |  4 ++--
> >  drivers/of/of_mdio.c  | 12 ++++++------
> >  drivers/of/of_numa.c  |  4 ++--
> >  drivers/of/overlay.c  |  4 ++--
> >  drivers/of/platform.c |  8 ++++----
> >  drivers/of/unittest.c | 12 ++++++------
> >  6 files changed, 22 insertions(+), 22 deletions(-)
> >
> > diff --git a/drivers/of/device.c b/drivers/of/device.c
> > index 5957cd4fa262..daa075d87317 100644
> > --- a/drivers/of/device.c
> > +++ b/drivers/of/device.c
> > @@ -219,7 +219,7 @@ static ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len
> >               return -ENODEV;
> >
> >       /* Name & Type */
> > -     csize = snprintf(str, len, "of:N%sT%s", dev->of_node->name,
> > +     csize = snprintf(str, len, "of:N%pOFnT%s", dev->of_node,
> >                        dev->of_node->type);
> >       tsize = csize;
> >       len -= csize;
>
> This seems to cause the modalias to be improperly constructed. As a
> consequence, automatic module loading at boot time is now broken. I
> think the reason why this fails is because vsnprintf() will skip all
> alpha-numeric characters after a call to pointer(). Presumably this
> is meant to be a generic way of skipping whatever specifiers we throw
> at it.
>
> Unfortunately for the case of OF modaliases, this means that the 'T'
> character gets eaten, so we end up with something like this:
>
>         # udevadm info /sys/bus/platform/devices/54200000.dc
>         [...]
>         E: MODALIAS=of:Ndc<NULL>Cnvidia,tegra124-dc
>         [...]
>
> instead of this:
>
>         # udevadm info /sys/bus/platform/devices/54200000.dc
>         [...]
>         E: MODALIAS=of:NdcT<NULL>Cnvidia,tegra124-dc
>         [...]

Oops. Thanks for finding this.

> Everything is back to normal if I revert this patch. However, since
> that's obviously not what we want, I think perhaps what we need is a
> way for pointer() (and its implementations) to report back how many
> characters in the format string it consumed so that we can support
> these kinds of back-to-back strings.

I don't think we can change it because if I have something like
%pOFMoreWords and then later on want to add 'M' as a new modifier we'd
break any existing cases with 'M'. Of course, I could search the tree
for that case and find unused characters, but that seems fragile
(though silently throwing away the characters does too).

> If nobody else has the time I can look into coding up a fix, but in the
> meantime it might be best to back this one out until we can handle the
> OF modalias format string.

There's an easy fix though. Just replace the 'T' with a '%c'.

I found one other case in the clock code and one in soundbus (which I
haven't posted yet).

Rob

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/4] of: Convert to using %pOFn instead of device_node.name
  2018-09-07 12:29   ` Thierry Reding
  2018-09-07 14:58     ` Rob Herring
@ 2018-09-08  0:30     ` Joe Perches
  2018-09-10  9:06       ` Thierry Reding
  1 sibling, 1 reply; 10+ messages in thread
From: Joe Perches @ 2018-09-08  0:30 UTC (permalink / raw)
  To: Thierry Reding, Rob Herring
  Cc: Frank Rowand, devicetree, linux-kernel, Andrew Lunn,
	Florian Fainelli, netdev

On Fri, 2018-09-07 at 14:29 +0200, Thierry Reding wrote:
> On Tue, Aug 28, 2018 at 10:52:53AM -0500, Rob Herring wrote:
> > In preparation to remove the node name pointer from struct device_node,
> > convert printf users to use the %pOFn format specifier.
> > 
> > Cc: Frank Rowand <frowand.list@gmail.com>
> > Cc: Andrew Lunn <andrew@lunn.ch>
> > Cc: Florian Fainelli <f.fainelli@gmail.com>
> > Cc: devicetree@vger.kernel.org
> > Cc: netdev@vger.kernel.org
> > Signed-off-by: Rob Herring <robh@kernel.org>
> > ---
> >  drivers/of/device.c   |  4 ++--
> >  drivers/of/of_mdio.c  | 12 ++++++------
> >  drivers/of/of_numa.c  |  4 ++--
> >  drivers/of/overlay.c  |  4 ++--
> >  drivers/of/platform.c |  8 ++++----
> >  drivers/of/unittest.c | 12 ++++++------
> >  6 files changed, 22 insertions(+), 22 deletions(-)
> > 
> > diff --git a/drivers/of/device.c b/drivers/of/device.c
> > index 5957cd4fa262..daa075d87317 100644
> > --- a/drivers/of/device.c
> > +++ b/drivers/of/device.c
> > @@ -219,7 +219,7 @@ static ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len
> >  		return -ENODEV;
> >  
> >  	/* Name & Type */
> > -	csize = snprintf(str, len, "of:N%sT%s", dev->of_node->name,
> > +	csize = snprintf(str, len, "of:N%pOFnT%s", dev->of_node,
> >  			 dev->of_node->type);
> >  	tsize = csize;
> >  	len -= csize;
> 
> This seems to cause the modalias to be improperly constructed. As a
> consequence, automatic module loading at boot time is now broken. I
> think the reason why this fails is because vsnprintf() will skip all
> alpha-numeric characters after a call to pointer(). Presumably this
> is meant to be a generic way of skipping whatever specifiers we throw
> at it.
> 
> Unfortunately for the case of OF modaliases, this means that the 'T'
> character gets eaten, so we end up with something like this:
> 
> 	# udevadm info /sys/bus/platform/devices/54200000.dc
> 	[...]
> 	E: MODALIAS=of:Ndc<NULL>Cnvidia,tegra124-dc
> 	[...]
> 
> instead of this:
> 
> 	# udevadm info /sys/bus/platform/devices/54200000.dc
> 	[...]
> 	E: MODALIAS=of:NdcT<NULL>Cnvidia,tegra124-dc
> 	[...]
> 
> Everything is back to normal if I revert this patch. However, since
> that's obviously not what we want, I think perhaps what we need is a
> way for pointer() (and its implementations) to report back how many
> characters in the format string it consumed so that we can support
> these kinds of back-to-back strings.
> 
> If nobody else has the time I can look into coding up a fix, but in the
> meantime it might be best to back this one out until we can handle the
> OF modalias format string.

Or just use 2 consecutive snprintf calls

	csize = snprintf(str, len, "of:N%pOFn", dev->of_node);
	csize += snprintf(str + csize, len - csize, "T%s",
			  dev->of_node->type);


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/4] of: Convert to using %pOFn instead of device_node.name
  2018-09-08  0:30     ` Joe Perches
@ 2018-09-10  9:06       ` Thierry Reding
  0 siblings, 0 replies; 10+ messages in thread
From: Thierry Reding @ 2018-09-10  9:06 UTC (permalink / raw)
  To: Joe Perches
  Cc: Rob Herring, Frank Rowand, devicetree, linux-kernel, Andrew Lunn,
	Florian Fainelli, netdev

[-- Attachment #1: Type: text/plain, Size: 3223 bytes --]

On Fri, Sep 07, 2018 at 05:30:23PM -0700, Joe Perches wrote:
> On Fri, 2018-09-07 at 14:29 +0200, Thierry Reding wrote:
> > On Tue, Aug 28, 2018 at 10:52:53AM -0500, Rob Herring wrote:
> > > In preparation to remove the node name pointer from struct device_node,
> > > convert printf users to use the %pOFn format specifier.
> > > 
> > > Cc: Frank Rowand <frowand.list@gmail.com>
> > > Cc: Andrew Lunn <andrew@lunn.ch>
> > > Cc: Florian Fainelli <f.fainelli@gmail.com>
> > > Cc: devicetree@vger.kernel.org
> > > Cc: netdev@vger.kernel.org
> > > Signed-off-by: Rob Herring <robh@kernel.org>
> > > ---
> > >  drivers/of/device.c   |  4 ++--
> > >  drivers/of/of_mdio.c  | 12 ++++++------
> > >  drivers/of/of_numa.c  |  4 ++--
> > >  drivers/of/overlay.c  |  4 ++--
> > >  drivers/of/platform.c |  8 ++++----
> > >  drivers/of/unittest.c | 12 ++++++------
> > >  6 files changed, 22 insertions(+), 22 deletions(-)
> > > 
> > > diff --git a/drivers/of/device.c b/drivers/of/device.c
> > > index 5957cd4fa262..daa075d87317 100644
> > > --- a/drivers/of/device.c
> > > +++ b/drivers/of/device.c
> > > @@ -219,7 +219,7 @@ static ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len
> > >  		return -ENODEV;
> > >  
> > >  	/* Name & Type */
> > > -	csize = snprintf(str, len, "of:N%sT%s", dev->of_node->name,
> > > +	csize = snprintf(str, len, "of:N%pOFnT%s", dev->of_node,
> > >  			 dev->of_node->type);
> > >  	tsize = csize;
> > >  	len -= csize;
> > 
> > This seems to cause the modalias to be improperly constructed. As a
> > consequence, automatic module loading at boot time is now broken. I
> > think the reason why this fails is because vsnprintf() will skip all
> > alpha-numeric characters after a call to pointer(). Presumably this
> > is meant to be a generic way of skipping whatever specifiers we throw
> > at it.
> > 
> > Unfortunately for the case of OF modaliases, this means that the 'T'
> > character gets eaten, so we end up with something like this:
> > 
> > 	# udevadm info /sys/bus/platform/devices/54200000.dc
> > 	[...]
> > 	E: MODALIAS=of:Ndc<NULL>Cnvidia,tegra124-dc
> > 	[...]
> > 
> > instead of this:
> > 
> > 	# udevadm info /sys/bus/platform/devices/54200000.dc
> > 	[...]
> > 	E: MODALIAS=of:NdcT<NULL>Cnvidia,tegra124-dc
> > 	[...]
> > 
> > Everything is back to normal if I revert this patch. However, since
> > that's obviously not what we want, I think perhaps what we need is a
> > way for pointer() (and its implementations) to report back how many
> > characters in the format string it consumed so that we can support
> > these kinds of back-to-back strings.
> > 
> > If nobody else has the time I can look into coding up a fix, but in the
> > meantime it might be best to back this one out until we can handle the
> > OF modalias format string.
> 
> Or just use 2 consecutive snprintf calls
> 
> 	csize = snprintf(str, len, "of:N%pOFn", dev->of_node);
> 	csize += snprintf(str + csize, len - csize, "T%s",
> 			  dev->of_node->type);

Yeah, that's what I ended up doing. Rob came up with another alternative
which is to output the 'T' via %c, which also works around the issue.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-09-10  9:06 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-28 15:52 [PATCH 0/4] of: Convert to using %pOFn for node name printf Rob Herring
2018-08-28 15:52 ` [PATCH 1/4] of/unittest: remove use of node name pointer in overlay high level test Rob Herring
2018-08-28 15:52 ` [PATCH 2/4] of/unittest: add printf tests for node name Rob Herring
2018-08-28 15:52 ` [PATCH 3/4] of: Convert to using %pOFn instead of device_node.name Rob Herring
2018-09-07 12:29   ` Thierry Reding
2018-09-07 14:58     ` Rob Herring
2018-09-08  0:30     ` Joe Perches
2018-09-10  9:06       ` Thierry Reding
2018-08-28 15:52 ` [PATCH 4/4] vsprintf: print OF node name using full_name Rob Herring
2018-08-31 23:51 ` [PATCH 0/4] of: Convert to using %pOFn for node name printf Frank Rowand

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).