vsprintf: Move space out of string literals in fourcc_string()
Subsystems (2)
Andy Shevchenko
reviewerPATCH 1/1 vsprintf: Move space out of string literals in fourcc_string()
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.
---
Depends on the
https://lore.kernel.org/lkml/[email protected]/T/#u
but not to be critical or fix-like.
lib/vsprintf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
lib/vsprintf.c +2 -1
@@ -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++ =' ' ;
Signature · 1 line
2.34.1
Quoted 6 lines · Andy Shevchenko
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 <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>
Signature · 1 line
Sakari Ailus
Rasmus Villemoes
reviewerQuoted 3 lines · Andy Shevchenko
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.
lib/vsprintf.c char *fourcc_string(char *buf, char *end, const u32 *fourcc, · line 1785
Quoted 12 lines
lib/vsprintf.c +2
-1@@ -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
Andy Shevchenko
reviewerQuoted 6 lines · Rasmus Villemoes
Quoted 3 lines · Andy Shevchenko
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!
Quoted 8 lines
lib/vsprintf.c char *fourcc_string(char *buf, char *end, const u32 *fourcc, · line 1785
Quoted 4 lines
lib/vsprintf.c +2
-1-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 thestrlen()and say p = stpcpy(...) instead?
Why not? I'll do it for v2.
Any thoughts / comments on the
https://lore.kernel.org/lkml/[email protected]/T/#u?
I'm asking since dependency and I would like to know if we still want that fix or not.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Petr Mladek
maintainerQuoted 19 lines · Andy Shevchenko
Quoted 6 lines · Rasmus Villemoes
Quoted 3 lines · Andy Shevchenko
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!
Quoted 8 lines
lib/vsprintf.c char *fourcc_string(char *buf, char *end, const u32 *fourcc, · line 1785
Quoted 4 lines
lib/vsprintf.c +2
-1-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 thestrlen()and say p = stpcpy(...) instead?
Quoted 1 line
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 ;-)
Quoted 4 lines
Any thoughts / comments on the
https://lore.kernel.org/lkml/[email protected]/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
Rasmus Villemoes
reviewerQuoted 11 lines · Petr Mladek
Quoted 9 lines · Andy Shevchenko
Quoted 8 lines
lib/vsprintf.c char *fourcc_string(char *buf, char *end, const u32 *fourcc, · line 1785
Quoted 4 lines
lib/vsprintf.c +2
-1-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 thestrlen()and say p = stpcpy(...) instead?
Quoted 5 lines
Quoted 1 line
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