Skip to contentSkip to conversation

lib/vsprintf: Unify FORMAT_STATE_NUM handlers

PATCH In review Andy Shevchenko 2 participants 3 messages Nov 20, 2025 – Nov 25, 2025

Subsystems (2)
lore
Share & tools
lore

Andy Shevchenko

author reviewer
#0 lore raw

PATCH 1/1 lib/vsprintf: Unify FORMAT_STATE_NUM handlers

We have two almost identical pieces that handle FORMAT_STATE_NUM case. The differences are:
- redundant {} for one-line if-else conditional
- missing blank line after variable definitions
- inverted conditional

Unify the style of two.

---
 lib/vsprintf.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
lib/vsprintf.c +6 -6
index 1591dcf0e211..822a18747908 100644
@@ -3015,10 +3015,11 @@ int vsnprintf(char *buf, size_t size, const char *fmt_str, va_list args)
 
 		case FORMAT_STATE_NUM: {
 			unsigned long long num;
-			if (fmt.size <= sizeof(int))
-				num = convert_num_spec(va_arg(args, int), fmt.size, spec);
-			else
+
+			if (fmt.size > sizeof(int))
 				num = va_arg(args, long long);
+			else
+				num = convert_num_spec(va_arg(args, int), fmt.size, spec);
 			str = number(str, end, num, spec);
 			continue;
 		}
@@ -3526,11 +3527,10 @@ int bstr_printf(char *buf, size_t size, const char *fmt_str, const u32 *bin_buf)
 			goto out;
 
 		case FORMAT_STATE_NUM:
-			if (fmt.size > sizeof(int)) {
+			if (fmt.size > sizeof(int))
 				num = get_arg(long long);
-			} else {
+			else
 				num = convert_num_spec(get_arg(int), fmt.size, spec);
-			}
 			str = number(str, end, num, spec);
 			continue;
 		}
Signature · 1 line
2.50.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Andy Shevchenko

We have two almost identical pieces that handle FORMAT_STATE_NUM case. The differences are:
- redundant {} for one-line if-else conditional
- missing blank line after variable definitions
- inverted conditional

Unify the style of two.

Looks good to me:

It is a trivial change. I am going to push it right away...

Best Regards,
Petr

maintainer
#2 lore raw
In reply to Andy Shevchenko
Quoted 9 lines · Andy Shevchenko

We have two almost identical pieces that handle FORMAT_STATE_NUM case. The differences are:
- redundant {} for one-line if-else conditional
- missing blank line after variable definitions
- inverted conditional

Unify the style of two.

JFYI, the patch has been comitted into printk/linux.git, branch for-6.19.

Best Regards,
Petr