Skip to contentSkip to conversation

lib/vsprintf: use bool for local decode variable

PATCH In review Thorsten Blum 4 participants 6 messages Apr 7 – Apr 14

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/vsprintf: use bool for local decode variable

The local variable 'decode' is only used as a boolean value - change its data type from int to bool accordingly.

---
 lib/vsprintf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/vsprintf.c +2 -2
index 800b8ac49f53..9f359b31c8d1 100644
@@ -1107,7 +1107,7 @@ char *resource_string(char *buf, char *end, struct resource *res,
 		     2*RSRC_BUF_SIZE + FLAG_BUF_SIZE + RAW_BUF_SIZE)];
 
 	char *p = sym, *pend = sym + sizeof(sym);
-	int decode = (fmt[0] == 'R') ? 1 : 0;
+	bool decode = fmt[0] == 'R';
 	const struct printf_spec *specp;
 
 	if (check_pointer(&buf, end, res, spec))
@@ -1132,7 +1132,7 @@ char *resource_string(char *buf, char *end, struct resource *res,
 	} else {
 		p = string_nocheck(p, pend, "??? ", str_spec);
 		specp = &mem_spec;
-		decode = 0;
+		decode = false;
 	}
 	if (decode && res->flags & IORESOURCE_UNSET) {
 		p = string_nocheck(p, pend, "size ", str_spec);
#1 lore raw
Quoted 2 lines · On Tue, 7 Apr 2026 20:18:36 +0200 Thorsten Blum <[email protected]>…

The local variable 'decode' is only used as a boolean value - change its data type from int to bool accordingly.

Hopefully the compiler actually does:

	int decode = fmt[0];

and then compares against 'R' later on.
But this change ought to make absolutely no difference to the code.

David

Quoted 29 lines
---
 lib/vsprintf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/vsprintf.c +2 -2
index 800b8ac49f53..9f359b31c8d1 100644
@@ -1107,7 +1107,7 @@ char *resource_string(char *buf, char *end, struct resource *res,
 		     2*RSRC_BUF_SIZE + FLAG_BUF_SIZE + RAW_BUF_SIZE)];
 
 	char *p = sym, *pend = sym + sizeof(sym);
-	int decode = (fmt[0] == 'R') ? 1 : 0;
+	bool decode = fmt[0] == 'R';
 	const struct printf_spec *specp;
 
 	if (check_pointer(&buf, end, res, spec))
@@ -1132,7 +1132,7 @@ char *resource_string(char *buf, char *end, struct resource *res,
 	} else {
 		p = string_nocheck(p, pend, "??? ", str_spec);
 		specp = &mem_spec;
-		decode = 0;
+		decode = false;
 	}
 	if (decode && res->flags & IORESOURCE_UNSET) {
 		p = string_nocheck(p, pend, "size ", str_spec);
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Thorsten Blum
Quoted 15 lines · Thorsten Blum

The local variable 'decode' is only used as a boolean value - change its data type from int to bool accordingly.

lib/vsprintf.c +1 -1
@@ -1107,7 +1107,7 @@ char *resource_string(char *buf, char *end, struct resource *res,
 		     2*RSRC_BUF_SIZE + FLAG_BUF_SIZE + RAW_BUF_SIZE)];
 
 	char *p = sym, *pend = sym + sizeof(sym);
-	int decode = (fmt[0] == 'R') ? 1 : 0;
+	bool decode = fmt[0] == 'R';
 	const struct printf_spec *specp;
 
 	if (check_pointer(&buf, end, res, spec))

lib/vsprintf.c char *resource_string(char *buf, char *end, struct resource *res, · line 1138

Quoted 8 lines
lib/vsprintf.c +1 -1
@@ -1132,7 +1132,7 @@ char *resource_string(char *buf, char *end, struct resource *res,
 	} else {
 		p = string_nocheck(p, pend, "??? ", str_spec);
 		specp = &mem_spec;
-		decode = 0;
+		decode = false;
 	}
 	if (decode && res->flags & IORESOURCE_UNSET) {
 		p = string_nocheck(p, pend, "size ", str_spec);

I have mixed feeling about this patch. I agree that it might slightly improve code readability. But cosmetic changes are usually about personal preferences and often just pollute code history.

IMHO, this is really just about "code readability" vs "code history pollution" problem. I believe that compilers would handle both variants the same way.

As I said, I agree that this this slightly improves the code readability and it is trivial. So I am going to wait few more days and take this patch unless there is a strong push back from others.

Best Regards,
Petr

#3 lore raw
Quoted 1 line · Petr Mladek

On Tue 2026-04-07 20:18:36, Thorsten Blum wrote:

...

Quoted 1 line

I have mixed feeling about this patch

Same here.

Quoted 4 lines

I agree that it might slightly
improve code readability. But cosmetic changes are usually about personal preferences and often just pollute code history.

Quoted 8 lines

IMHO, this is really just about "code readability" vs "code history pollution" problem. I believe that compilers would handle both variants the same way.

As I said, I agree that this this slightly improves the code readability and it is trivial. So I am going to wait few more days and take this patch unless there is a strong push back from others.

Up to you, no pushback from me, and no tag as well. Personally I consider it's a churn, but we have tons of a such in the kernel (I mean int as boolean cases).

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw
Quoted 8 lines · Petr Mladek
Quoted 4 lines · Thorsten Blum

The local variable 'decode' is only used as a boolean value - change its data type from int to bool accordingly.

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

Thank you!

Quoted 2 lines

Best Regards,
Petr