public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] of: module: remove strlen() call in of_modalias()
@ 2024-10-15 20:15 Sergey Shtylyov
  2024-10-15 20:18 ` Sergey Shtylyov
  2024-10-16 17:12 ` Rob Herring (Arm)
  0 siblings, 2 replies; 3+ messages in thread
From: Sergey Shtylyov @ 2024-10-15 20:15 UTC (permalink / raw)
  To: devicetree, Saravana Kannan, Rob Herring

In of_modalias(), there's no dire need to call strlen() (and then add 1
to its result to account for the 'C' char preceding the compat string).
Replace that strlen() with snprintf() (currently below it) -- this way,
we always try to print the compat string but then only advance the str
and len parameters iff the comapt string fit into the remaining buffer
space...

Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>

---
The patch is against the dt/next branch of Rob Herring's linux.git repo...

 drivers/of/module.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Index: linux/drivers/of/module.c
===================================================================
--- linux.orig/drivers/of/module.c
+++ linux/drivers/of/module.c
@@ -35,12 +35,10 @@ ssize_t of_modalias(const struct device_
 	str += csize;
 
 	of_property_for_each_string(np, "compatible", p, compat) {
-		csize = strlen(compat) + 1;
+		csize = snprintf(str, len, "C%s", compat);
 		tsize += csize;
 		if (csize >= len)
 			continue;
-
-		csize = snprintf(str, len, "C%s", compat);
 		for (c = str; c; ) {
 			c = strchr(c, ' ');
 			if (c)

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

* Re: [PATCH] of: module: remove strlen() call in of_modalias()
  2024-10-15 20:15 [PATCH] of: module: remove strlen() call in of_modalias() Sergey Shtylyov
@ 2024-10-15 20:18 ` Sergey Shtylyov
  2024-10-16 17:12 ` Rob Herring (Arm)
  1 sibling, 0 replies; 3+ messages in thread
From: Sergey Shtylyov @ 2024-10-15 20:18 UTC (permalink / raw)
  To: devicetree, Saravana Kannan, Rob Herring

On 10/15/24 11:15 PM, Sergey Shtylyov wrote:

> In of_modalias(), there's no dire need to call strlen() (and then add 1
> to its result to account for the 'C' char preceding the compat string).
> Replace that strlen() with snprintf() (currently below it) -- this way,
> we always try to print the compat string but then only advance the str
> and len parameters iff the comapt string fit into the remaining buffer

    Oops, compat! :-)

> space...
> 
> Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>
[...]

MBR, Sergey


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

* Re: [PATCH] of: module: remove strlen() call in of_modalias()
  2024-10-15 20:15 [PATCH] of: module: remove strlen() call in of_modalias() Sergey Shtylyov
  2024-10-15 20:18 ` Sergey Shtylyov
@ 2024-10-16 17:12 ` Rob Herring (Arm)
  1 sibling, 0 replies; 3+ messages in thread
From: Rob Herring (Arm) @ 2024-10-16 17:12 UTC (permalink / raw)
  To: Sergey Shtylyov; +Cc: devicetree, Saravana Kannan


On Tue, 15 Oct 2024 23:15:04 +0300, Sergey Shtylyov wrote:
> In of_modalias(), there's no dire need to call strlen() (and then add 1
> to its result to account for the 'C' char preceding the compat string).
> Replace that strlen() with snprintf() (currently below it) -- this way,
> we always try to print the compat string but then only advance the str
> and len parameters iff the comapt string fit into the remaining buffer
> space...
> 
> Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>
> 
> ---
> The patch is against the dt/next branch of Rob Herring's linux.git repo...
> 
>  drivers/of/module.c |    4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 

Fixed the typo and applied, thanks!

Rob

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

end of thread, other threads:[~2024-10-16 17:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-15 20:15 [PATCH] of: module: remove strlen() call in of_modalias() Sergey Shtylyov
2024-10-15 20:18 ` Sergey Shtylyov
2024-10-16 17:12 ` Rob Herring (Arm)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox