Skip to contentSkip to conversation

kernel-printf: add printf format %pra for struct range

PATCH In review [email protected] 2 participants 2 messages Feb 7, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel-printf: add printf format %pra for struct range

From: Alison Schofield <[email protected]>

A new kernel printf specifier was added for struct range. Since it shares the %pr with the existing struct resource format, new usages lead to smatch warnings. Explicitly check this new format.

---
 check_kernel_printf.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
check_kernel_printf.c +17 -1
index b92ac760a335..da70030ae846 100644
@@ -484,6 +484,17 @@ static void resource_string(const char *fmt, struct symbol *type, struct symbol
 		sm_warning("'%%p%c' cannot be followed by '%c'", fmt[0], fmt[1]);
 }
 
+static void range_string(const char *fmt, struct symbol *type, struct symbol *basetype, int vaidx)
+{
+	assert(fmt[0] == 'r' && fmt[1] == 'a');
+	if (!is_struct_tag(basetype, "range")) {
+		sm_error("'%%p%c' expects argument of type struct range *, "
+			"but argument %d has type '%s'", fmt[0], vaidx, type_to_str(type));
+	}
+	if (isalnum(fmt[2]))
+		sm_warning("'%%p%c%c' cannot be followed by '%c'", fmt[0], fmt[1], fmt[2]);
+}
+
 static void mac_address_string(const char *fmt, struct symbol *type, struct symbol *basetype, int vaidx)
 {
 	assert(tolower(fmt[0]) == 'm');
@@ -734,9 +745,14 @@ pointer(const char *fmt, struct expression *arg, int vaidx)
 		break;
 
 	case 'R':
-	case 'r':
 		resource_string(fmt, type, basetype, vaidx);
 		break;
+	case 'r':
+		if (fmt[1] == 'a')
+			range_string(fmt, type, basetype, vaidx);
+		else
+			resource_string(fmt, type, basetype, vaidx);
+		break;
 	case 'M':
 	case 'm':
 		mac_address_string(fmt, type, basetype, vaidx);

base-commit: b84a20732d9473a62627d89b5eea4f98b3640283

Signature · 1 line
2.37.3
#1 lore raw

Aw crap. Thanks, Alison. I had already patched this on my tree but I forgot to commit it. It's weird that the zero-day bot wasn't sending me warnings about this.

Anyway, your patch is better than mine so I'll push yours.

regards,
dan carpenter