All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] of: Split up name & type in modalias generation
@ 2018-09-07 14:22 Thierry Reding
  2018-09-07 18:35 ` Frank Rowand
  2018-09-07 18:49 ` Rob Herring
  0 siblings, 2 replies; 5+ messages in thread
From: Thierry Reding @ 2018-09-07 14:22 UTC (permalink / raw)
  To: Rob Herring; +Cc: Frank Rowand, devicetree, linux-kernel

From: Thierry Reding <treding@nvidia.com>

The kernel's vsnprintf() implementation discards all alpha-numeric
characters following a %p conversion specifier. This is done in order to
generically skip any of the various modifiers that the kernel supports.
Unfortunately, the OF modalias is generated with a format string that
violates the assumption made by vsnprintf():

	of:N%pOFnT%s

While processing the above format string, vsnprintf() will eat the 'T'
character, assuming that it belongs to the preceeding %p specifier. This
results in a modalias with an incompatible format, which in turn causes
the automatic loading of drivers based on modalias to no longer work.

To fix this, split up the generation of the name & type fields into two
separate snprintf() calls to avoid confusing the parser.

Fixes: 73813f8483b1 ("of: Convert to using %pOFn instead of device_node.name")
Signed-off-by: Thierry Reding <treding@nvidia.com>
---
Note that a more elegant fix would be to make the %p format specifier
parser report back the exact number of characters consumed. I briefly
tried to implement it, but quickly ran into numerous special cases
that make this solution rather involved.

I can spend some more time to improve this in general if that's what we
ultimately want, but I think this patch is a better short-term fix to
workaround the issue.
---
 drivers/of/device.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/of/device.c b/drivers/of/device.c
index daa075d87317..dabef9fc8538 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -218,14 +218,20 @@ static ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len
 	if ((!dev) || (!dev->of_node))
 		return -ENODEV;
 
-	/* Name & Type */
-	csize = snprintf(str, len, "of:N%pOFnT%s", dev->of_node,
-			 dev->of_node->type);
+	/* Name */
+	csize = snprintf(str, len, "of:N%pOFn", dev->of_node);
 	tsize = csize;
 	len -= csize;
 	if (str)
 		str += csize;
 
+	/* Type */
+	csize = snprintf(str, len, "T%s", dev->of_node->type);
+	tsize += csize;
+	len -= csize;
+	if (str)
+		str += csize;
+
 	of_property_for_each_string(dev->of_node, "compatible", p, compat) {
 		csize = strlen(compat) + 1;
 		tsize += csize;
-- 
2.18.0


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

* Re: [PATCH] of: Split up name & type in modalias generation
  2018-09-07 14:22 [PATCH] of: Split up name & type in modalias generation Thierry Reding
@ 2018-09-07 18:35 ` Frank Rowand
  2018-09-07 18:49 ` Rob Herring
  1 sibling, 0 replies; 5+ messages in thread
From: Frank Rowand @ 2018-09-07 18:35 UTC (permalink / raw)
  To: Thierry Reding, Rob Herring; +Cc: devicetree, linux-kernel

On 09/07/18 07:22, Thierry Reding wrote:
> From: Thierry Reding <treding@nvidia.com>
> 
> The kernel's vsnprintf() implementation discards all alpha-numeric
> characters following a %p conversion specifier. This is done in order to
> generically skip any of the various modifiers that the kernel supports.
> Unfortunately, the OF modalias is generated with a format string that
> violates the assumption made by vsnprintf():
> 
> 	of:N%pOFnT%s
> 
> While processing the above format string, vsnprintf() will eat the 'T'
> character, assuming that it belongs to the preceeding %p specifier. This
> results in a modalias with an incompatible format, which in turn causes
> the automatic loading of drivers based on modalias to no longer work.
> 
> To fix this, split up the generation of the name & type fields into two
> separate snprintf() calls to avoid confusing the parser.
> 
> Fixes: 73813f8483b1 ("of: Convert to using %pOFn instead of device_node.name")
> Signed-off-by: Thierry Reding <treding@nvidia.com>
> ---
> Note that a more elegant fix would be to make the %p format specifier
> parser report back the exact number of characters consumed. I briefly
> tried to implement it, but quickly ran into numerous special cases
> that make this solution rather involved.
> 
> I can spend some more time to improve this in general if that's what we
> ultimately want, but I think this patch is a better short-term fix to
> workaround the issue.
> ---
>  drivers/of/device.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/of/device.c b/drivers/of/device.c
> index daa075d87317..dabef9fc8538 100644
> --- a/drivers/of/device.c
> +++ b/drivers/of/device.c
> @@ -218,14 +218,20 @@ static ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len
>  	if ((!dev) || (!dev->of_node))
>  		return -ENODEV;
>  
> -	/* Name & Type */
> -	csize = snprintf(str, len, "of:N%pOFnT%s", dev->of_node,
> -			 dev->of_node->type);
> +	/* Name */
> +	csize = snprintf(str, len, "of:N%pOFn", dev->of_node);
>  	tsize = csize;
>  	len -= csize;
>  	if (str)
>  		str += csize;
>  
> +	/* Type */
> +	csize = snprintf(str, len, "T%s", dev->of_node->type);
> +	tsize += csize;
> +	len -= csize;
> +	if (str)
> +		str += csize;
> +
>  	of_property_for_each_string(dev->of_node, "compatible", p, compat) {
>  		csize = strlen(compat) + 1;
>  		tsize += csize;
> 

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

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

* Re: [PATCH] of: Split up name & type in modalias generation
  2018-09-07 14:22 [PATCH] of: Split up name & type in modalias generation Thierry Reding
  2018-09-07 18:35 ` Frank Rowand
@ 2018-09-07 18:49 ` Rob Herring
  2018-09-07 19:56   ` Frank Rowand
  1 sibling, 1 reply; 5+ messages in thread
From: Rob Herring @ 2018-09-07 18:49 UTC (permalink / raw)
  To: Thierry Reding; +Cc: Frank Rowand, devicetree, linux-kernel

On Fri, Sep 7, 2018 at 9:22 AM Thierry Reding <thierry.reding@gmail.com> wrote:
>
> From: Thierry Reding <treding@nvidia.com>
>
> The kernel's vsnprintf() implementation discards all alpha-numeric
> characters following a %p conversion specifier. This is done in order to
> generically skip any of the various modifiers that the kernel supports.
> Unfortunately, the OF modalias is generated with a format string that
> violates the assumption made by vsnprintf():
>
>         of:N%pOFnT%s
>
> While processing the above format string, vsnprintf() will eat the 'T'
> character, assuming that it belongs to the preceeding %p specifier. This
> results in a modalias with an incompatible format, which in turn causes
> the automatic loading of drivers based on modalias to no longer work.
>
> To fix this, split up the generation of the name & type fields into two
> separate snprintf() calls to avoid confusing the parser.
>
> Fixes: 73813f8483b1 ("of: Convert to using %pOFn instead of device_node.name")
> Signed-off-by: Thierry Reding <treding@nvidia.com>
> ---
> Note that a more elegant fix would be to make the %p format specifier
> parser report back the exact number of characters consumed. I briefly
> tried to implement it, but quickly ran into numerous special cases
> that make this solution rather involved.
>
> I can spend some more time to improve this in general if that's what we
> ultimately want, but I think this patch is a better short-term fix to
> workaround the issue.

See my reply on the original patch. I've updated the patch in my
dt/next branch with the fix to use %c.

Rob

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

* Re: [PATCH] of: Split up name & type in modalias generation
  2018-09-07 18:49 ` Rob Herring
@ 2018-09-07 19:56   ` Frank Rowand
  2018-09-10  9:08     ` Thierry Reding
  0 siblings, 1 reply; 5+ messages in thread
From: Frank Rowand @ 2018-09-07 19:56 UTC (permalink / raw)
  To: Rob Herring, Thierry Reding; +Cc: devicetree, linux-kernel

On 09/07/18 11:49, Rob Herring wrote:
> On Fri, Sep 7, 2018 at 9:22 AM Thierry Reding <thierry.reding@gmail.com> wrote:
>>
>> From: Thierry Reding <treding@nvidia.com>
>>
>> The kernel's vsnprintf() implementation discards all alpha-numeric
>> characters following a %p conversion specifier. This is done in order to
>> generically skip any of the various modifiers that the kernel supports.
>> Unfortunately, the OF modalias is generated with a format string that
>> violates the assumption made by vsnprintf():
>>
>>         of:N%pOFnT%s
>>
>> While processing the above format string, vsnprintf() will eat the 'T'
>> character, assuming that it belongs to the preceeding %p specifier. This
>> results in a modalias with an incompatible format, which in turn causes
>> the automatic loading of drivers based on modalias to no longer work.
>>
>> To fix this, split up the generation of the name & type fields into two
>> separate snprintf() calls to avoid confusing the parser.
>>
>> Fixes: 73813f8483b1 ("of: Convert to using %pOFn instead of device_node.name")
>> Signed-off-by: Thierry Reding <treding@nvidia.com>
>> ---
>> Note that a more elegant fix would be to make the %p format specifier
>> parser report back the exact number of characters consumed. I briefly
>> tried to implement it, but quickly ran into numerous special cases
>> that make this solution rather involved.
>>
>> I can spend some more time to improve this in general if that's what we
>> ultimately want, but I think this patch is a better short-term fix to
>> workaround the issue.
> 
> See my reply on the original patch. I've updated the patch in my
> dt/next branch with the fix to use %c.
> 
> Rob
> 

Agreed, your updated patch is more compact and looks cleaner.

-Frank

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

* Re: [PATCH] of: Split up name & type in modalias generation
  2018-09-07 19:56   ` Frank Rowand
@ 2018-09-10  9:08     ` Thierry Reding
  0 siblings, 0 replies; 5+ messages in thread
From: Thierry Reding @ 2018-09-10  9:08 UTC (permalink / raw)
  To: Frank Rowand; +Cc: Rob Herring, devicetree, linux-kernel

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

On Fri, Sep 07, 2018 at 12:56:09PM -0700, Frank Rowand wrote:
> On 09/07/18 11:49, Rob Herring wrote:
> > On Fri, Sep 7, 2018 at 9:22 AM Thierry Reding <thierry.reding@gmail.com> wrote:
> >>
> >> From: Thierry Reding <treding@nvidia.com>
> >>
> >> The kernel's vsnprintf() implementation discards all alpha-numeric
> >> characters following a %p conversion specifier. This is done in order to
> >> generically skip any of the various modifiers that the kernel supports.
> >> Unfortunately, the OF modalias is generated with a format string that
> >> violates the assumption made by vsnprintf():
> >>
> >>         of:N%pOFnT%s
> >>
> >> While processing the above format string, vsnprintf() will eat the 'T'
> >> character, assuming that it belongs to the preceeding %p specifier. This
> >> results in a modalias with an incompatible format, which in turn causes
> >> the automatic loading of drivers based on modalias to no longer work.
> >>
> >> To fix this, split up the generation of the name & type fields into two
> >> separate snprintf() calls to avoid confusing the parser.
> >>
> >> Fixes: 73813f8483b1 ("of: Convert to using %pOFn instead of device_node.name")
> >> Signed-off-by: Thierry Reding <treding@nvidia.com>
> >> ---
> >> Note that a more elegant fix would be to make the %p format specifier
> >> parser report back the exact number of characters consumed. I briefly
> >> tried to implement it, but quickly ran into numerous special cases
> >> that make this solution rather involved.
> >>
> >> I can spend some more time to improve this in general if that's what we
> >> ultimately want, but I think this patch is a better short-term fix to
> >> workaround the issue.
> > 
> > See my reply on the original patch. I've updated the patch in my
> > dt/next branch with the fix to use %c.
> > 
> > Rob
> > 
> 
> Agreed, your updated patch is more compact and looks cleaner.

Not sure about "cleaner", but yeah, that works as well.

Thierry

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

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

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-07 14:22 [PATCH] of: Split up name & type in modalias generation Thierry Reding
2018-09-07 18:35 ` Frank Rowand
2018-09-07 18:49 ` Rob Herring
2018-09-07 19:56   ` Frank Rowand
2018-09-10  9:08     ` Thierry Reding

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.