All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/1] vsprintf: Move space out of string literals in fourcc_string()
@ 2022-01-10 20:55 Andy Shevchenko
  2022-01-10 22:13 ` Sakari Ailus
  2022-01-11 10:26 ` Rasmus Villemoes
  0 siblings, 2 replies; 6+ messages in thread
From: Andy Shevchenko @ 2022-01-10 20:55 UTC (permalink / raw)
  To: Petr Mladek, linux-kernel
  Cc: Steven Rostedt, Sergey Senozhatsky, Andy Shevchenko,
	Rasmus Villemoes, Sakari Ailus

The literals "big-endian" and "little-endian" may be potentially
occurred in other places. Dropping space allows compiler to
"compress" them by using only a single copy.

Cc: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---

Depends on the
https://lore.kernel.org/lkml/20220110205049.11696-1-andriy.shevchenko@linux.intel.com/T/#u
but not to be critical or fix-like.

 lib/vsprintf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index b02f01366acb..5818856d5626 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1780,7 +1780,8 @@ char *fourcc_string(char *buf, char *end, const u32 *fourcc,
 		*p++ = isascii(c) && isprint(c) ? c : '.';
 	}
 
-	strcpy(p, orig & BIT(31) ? " big-endian" : " little-endian");
+	*p++ = ' ';
+	strcpy(p, orig & BIT(31) ? "big-endian" : "little-endian");
 	p += strlen(p);
 
 	*p++ = ' ';
-- 
2.34.1


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

* Re: [PATCH v1 1/1] vsprintf: Move space out of string literals in fourcc_string()
  2022-01-10 20:55 [PATCH v1 1/1] vsprintf: Move space out of string literals in fourcc_string() Andy Shevchenko
@ 2022-01-10 22:13 ` Sakari Ailus
  2022-01-11 10:26 ` Rasmus Villemoes
  1 sibling, 0 replies; 6+ messages in thread
From: Sakari Ailus @ 2022-01-10 22:13 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Petr Mladek, linux-kernel, Steven Rostedt, Sergey Senozhatsky,
	Rasmus Villemoes

On Mon, Jan 10, 2022 at 10:55:58PM +0200, Andy Shevchenko wrote:
> The literals "big-endian" and "little-endian" may be potentially
> occurred in other places. Dropping space allows compiler to
> "compress" them by using only a single copy.
> 
> Cc: Sakari Ailus <sakari.ailus@linux.intel.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>

-- 
Sakari Ailus

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

* Re: [PATCH v1 1/1] vsprintf: Move space out of string literals in fourcc_string()
  2022-01-10 20:55 [PATCH v1 1/1] vsprintf: Move space out of string literals in fourcc_string() Andy Shevchenko
  2022-01-10 22:13 ` Sakari Ailus
@ 2022-01-11 10:26 ` Rasmus Villemoes
  2022-01-11 11:28   ` Andy Shevchenko
  1 sibling, 1 reply; 6+ messages in thread
From: Rasmus Villemoes @ 2022-01-11 10:26 UTC (permalink / raw)
  To: Andy Shevchenko, Petr Mladek, linux-kernel
  Cc: Steven Rostedt, Sergey Senozhatsky, Sakari Ailus

On 10/01/2022 21.55, Andy Shevchenko wrote:
> The literals "big-endian" and "little-endian" may be potentially
> occurred in other places. Dropping space allows compiler to
> "compress" them by using only a single copy.

Nit: it's not the compiler which does that, but the linker.

> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index b02f01366acb..5818856d5626 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -1780,7 +1780,8 @@ char *fourcc_string(char *buf, char *end, const u32 *fourcc,
>  		*p++ = isascii(c) && isprint(c) ? c : '.';
>  	}
>  
> -	strcpy(p, orig & BIT(31) ? " big-endian" : " little-endian");
> +	*p++ = ' ';
> +	strcpy(p, orig & BIT(31) ? "big-endian" : "little-endian");
>  	p += strlen(p);

Hm, ok, those two strings do occur a lot with of_property_read_bool()
and friends. But if you're micro-optimizing anyway, why not drop the
strlen() and say p = stpcpy(...) instead?
Rasmus

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

* Re: [PATCH v1 1/1] vsprintf: Move space out of string literals in fourcc_string()
  2022-01-11 10:26 ` Rasmus Villemoes
@ 2022-01-11 11:28   ` Andy Shevchenko
  2022-01-11 15:10     ` Petr Mladek
  0 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2022-01-11 11:28 UTC (permalink / raw)
  To: Rasmus Villemoes
  Cc: Petr Mladek, linux-kernel, Steven Rostedt, Sergey Senozhatsky,
	Sakari Ailus

On Tue, Jan 11, 2022 at 11:26:21AM +0100, Rasmus Villemoes wrote:
> On 10/01/2022 21.55, Andy Shevchenko wrote:
> > The literals "big-endian" and "little-endian" may be potentially
> > occurred in other places. Dropping space allows compiler to
> > "compress" them by using only a single copy.
> 
> Nit: it's not the compiler which does that, but the linker.

Ah, I stand corrected, thanks!

> > -	strcpy(p, orig & BIT(31) ? " big-endian" : " little-endian");
> > +	*p++ = ' ';
> > +	strcpy(p, orig & BIT(31) ? "big-endian" : "little-endian");
> >  	p += strlen(p);
> 
> Hm, ok, those two strings do occur a lot with of_property_read_bool()
> and friends. But if you're micro-optimizing anyway, why not drop the
> strlen() and say p = stpcpy(...) instead?

Why not? I'll do it for v2.

Any thoughts / comments on the
https://lore.kernel.org/lkml/20220110205049.11696-1-andriy.shevchenko@linux.intel.com/T/#u?
I'm asking since dependency and I would like to know if we still want that
fix or not.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v1 1/1] vsprintf: Move space out of string literals in fourcc_string()
  2022-01-11 11:28   ` Andy Shevchenko
@ 2022-01-11 15:10     ` Petr Mladek
  2022-01-11 16:14       ` Rasmus Villemoes
  0 siblings, 1 reply; 6+ messages in thread
From: Petr Mladek @ 2022-01-11 15:10 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Rasmus Villemoes, linux-kernel, Steven Rostedt,
	Sergey Senozhatsky, Sakari Ailus

On Tue 2022-01-11 13:28:21, Andy Shevchenko wrote:
> On Tue, Jan 11, 2022 at 11:26:21AM +0100, Rasmus Villemoes wrote:
> > On 10/01/2022 21.55, Andy Shevchenko wrote:
> > > The literals "big-endian" and "little-endian" may be potentially
> > > occurred in other places. Dropping space allows compiler to
> > > "compress" them by using only a single copy.
> > 
> > Nit: it's not the compiler which does that, but the linker.
> 
> Ah, I stand corrected, thanks!
> 
> > > -	strcpy(p, orig & BIT(31) ? " big-endian" : " little-endian");
> > > +	*p++ = ' ';
> > > +	strcpy(p, orig & BIT(31) ? "big-endian" : "little-endian");
> > >  	p += strlen(p);
> > 
> > Hm, ok, those two strings do occur a lot with of_property_read_bool()
> > and friends. But if you're micro-optimizing anyway, why not drop the
> > strlen() and say p = stpcpy(...) instead?
> 
> Why not? I'll do it for v2.

It is safe here. I just hope that it will not trigger reports from
some tools looking for potential security issues ;-)

> Any thoughts / comments on the
> https://lore.kernel.org/lkml/20220110205049.11696-1-andriy.shevchenko@linux.intel.com/T/#u?
> I'm asking since dependency and I would like to know if we still want that
> fix or not.

Just commented there. It looks fine to me.

Best Regards,
Petr

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

* Re: [PATCH v1 1/1] vsprintf: Move space out of string literals in fourcc_string()
  2022-01-11 15:10     ` Petr Mladek
@ 2022-01-11 16:14       ` Rasmus Villemoes
  0 siblings, 0 replies; 6+ messages in thread
From: Rasmus Villemoes @ 2022-01-11 16:14 UTC (permalink / raw)
  To: Petr Mladek, Andy Shevchenko
  Cc: linux-kernel, Steven Rostedt, Sergey Senozhatsky, Sakari Ailus

On 11/01/2022 16.10, Petr Mladek wrote:
> On Tue 2022-01-11 13:28:21, Andy Shevchenko wrote:

>>>> -	strcpy(p, orig & BIT(31) ? " big-endian" : " little-endian");
>>>> +	*p++ = ' ';
>>>> +	strcpy(p, orig & BIT(31) ? "big-endian" : "little-endian");
>>>>  	p += strlen(p);
>>>
>>> Hm, ok, those two strings do occur a lot with of_property_read_bool()
>>> and friends. But if you're micro-optimizing anyway, why not drop the
>>> strlen() and say p = stpcpy(...) instead?
>>
>> Why not? I'll do it for v2.
> 
> It is safe here. I just hope that it will not trigger reports from
> some tools looking for potential security issues ;-)
> 

strcpy() and stpcpy() have exactly the same preconditions and are safe
in exactly the same circumstances, they only differ in their return
value, so I don't see how any tool would warn about a use of (the
only-recently-standardized) stpcpy if it didn't already warn about strcpy.

Rasmus

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

end of thread, other threads:[~2022-01-11 16:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-10 20:55 [PATCH v1 1/1] vsprintf: Move space out of string literals in fourcc_string() Andy Shevchenko
2022-01-10 22:13 ` Sakari Ailus
2022-01-11 10:26 ` Rasmus Villemoes
2022-01-11 11:28   ` Andy Shevchenko
2022-01-11 15:10     ` Petr Mladek
2022-01-11 16:14       ` Rasmus Villemoes

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.