* [PATCH v2 1/1] lib/vsprintf: Deduplicate special hex number specifier data
@ 2025-11-13 15:02 Andy Shevchenko
2025-11-14 9:45 ` Petr Mladek
2025-11-19 9:22 ` Petr Mladek
0 siblings, 2 replies; 3+ messages in thread
From: Andy Shevchenko @ 2025-11-13 15:02 UTC (permalink / raw)
To: linux-kernel
Cc: Petr Mladek, Steven Rostedt, Andy Shevchenko, Rasmus Villemoes,
Sergey Senozhatsky, Andrew Morton
Two functions use the same specifier data for the special hex number.
Almost the same as the field width is calculated on the size of the
given type. Due to that, make a compound literal macro in order to
deduplicate the rest.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v2: fixed prefix in the Subject line
lib/vsprintf.c | 26 ++++++++++----------------
1 file changed, 10 insertions(+), 16 deletions(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 3f99834fd788..11dbf1023391 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -582,17 +582,18 @@ char *number(char *buf, char *end, unsigned long long num,
return buf;
}
+#define special_hex_spec(size) \
+(struct printf_spec) { \
+ .field_width = 2 + 2 * (size), /* 0x + hex */ \
+ .flags = SPECIAL | SMALL | ZEROPAD, \
+ .base = 16, \
+ .precision = -1, \
+}
+
static noinline_for_stack
char *special_hex_number(char *buf, char *end, unsigned long long num, int size)
{
- struct printf_spec spec;
-
- spec.field_width = 2 + 2 * size; /* 0x + hex */
- spec.flags = SPECIAL | SMALL | ZEROPAD;
- spec.base = 16;
- spec.precision = -1;
-
- return number(buf, end, num, spec);
+ return number(buf, end, num, special_hex_spec(size));
}
static void move_right(char *buf, char *end, unsigned len, unsigned spaces)
@@ -1164,18 +1165,11 @@ char *range_string(char *buf, char *end, const struct range *range,
char sym[sizeof("[range 0x0123456789abcdef-0x0123456789abcdef]")];
char *p = sym, *pend = sym + sizeof(sym);
- struct printf_spec range_spec = {
- .field_width = 2 + 2 * sizeof(range->start), /* 0x + 2 * 8 */
- .flags = SPECIAL | SMALL | ZEROPAD,
- .base = 16,
- .precision = -1,
- };
-
if (check_pointer(&buf, end, range, spec))
return buf;
p = string_nocheck(p, pend, "[range ", default_str_spec);
- p = hex_range(p, pend, range->start, range->end, range_spec);
+ p = hex_range(p, pend, range->start, range->end, special_hex_spec(sizeof(range->start)));
*p++ = ']';
*p = '\0';
--
2.50.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2 1/1] lib/vsprintf: Deduplicate special hex number specifier data
2025-11-13 15:02 [PATCH v2 1/1] lib/vsprintf: Deduplicate special hex number specifier data Andy Shevchenko
@ 2025-11-14 9:45 ` Petr Mladek
2025-11-19 9:22 ` Petr Mladek
1 sibling, 0 replies; 3+ messages in thread
From: Petr Mladek @ 2025-11-14 9:45 UTC (permalink / raw)
To: Andy Shevchenko
Cc: linux-kernel, Steven Rostedt, Rasmus Villemoes,
Sergey Senozhatsky, Andrew Morton
On Thu 2025-11-13 16:02:59, Andy Shevchenko wrote:
> Two functions use the same specifier data for the special hex number.
> Almost the same as the field width is calculated on the size of the
> given type. Due to that, make a compound literal macro in order to
> deduplicate the rest.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Looks good to me:
Reviewed-by: Petr Mladek <pmladek@suse.com>
Tested-by: Petr Mladek <pmladek@suse.com>
I am going to wait few more days for potential feedback and push
it next Wednesday or so if nobody complained.
Best Regards,
Petr
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2 1/1] lib/vsprintf: Deduplicate special hex number specifier data
2025-11-13 15:02 [PATCH v2 1/1] lib/vsprintf: Deduplicate special hex number specifier data Andy Shevchenko
2025-11-14 9:45 ` Petr Mladek
@ 2025-11-19 9:22 ` Petr Mladek
1 sibling, 0 replies; 3+ messages in thread
From: Petr Mladek @ 2025-11-19 9:22 UTC (permalink / raw)
To: Andy Shevchenko
Cc: linux-kernel, Steven Rostedt, Rasmus Villemoes,
Sergey Senozhatsky, Andrew Morton
On Thu 2025-11-13 16:02:59, Andy Shevchenko wrote:
> Two functions use the same specifier data for the special hex number.
> Almost the same as the field width is calculated on the size of the
> given type. Due to that, make a compound literal macro in order to
> deduplicate the rest.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
JFYI, the patch has been comitted into printk/linux.git,
branch for-6.19.
Best Regards,
Petr
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-11-19 9:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-13 15:02 [PATCH v2 1/1] lib/vsprintf: Deduplicate special hex number specifier data Andy Shevchenko
2025-11-14 9:45 ` Petr Mladek
2025-11-19 9:22 ` Petr Mladek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox