[0/4] of: Convert to using %pOFn for node name printf

Message ID 20180828155254.10709-1-robh@kernel.org
Headers show
Series
  • of: Convert to using %pOFn for node name printf
Related show

Message

Rob Herring Aug. 28, 2018, 3:52 p.m.
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

Comments

Frank Rowand Aug. 31, 2018, 11:51 p.m. | #1
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>
Thierry Reding Sept. 7, 2018, 12:29 p.m. | #2
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
Rob Herring Sept. 7, 2018, 2:58 p.m. | #3
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
Joe Perches Sept. 8, 2018, 12:30 a.m. | #4
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);
Thierry Reding Sept. 10, 2018, 9:06 a.m. | #5
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