* [PATCH] kernel-printf: add printf format %pra for struct range
@ 2025-02-07 3:17 alison.schofield
2025-02-07 8:20 ` Dan Carpenter
0 siblings, 1 reply; 2+ messages in thread
From: alison.schofield @ 2025-02-07 3:17 UTC (permalink / raw)
To: smatch; +Cc: Alison Schofield, ira.weiny
From: Alison Schofield <alison.schofield@intel.com>
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.
Signed-off-by: Alison Schofield <alison.schofield@intel.com>
---
check_kernel_printf.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/check_kernel_printf.c b/check_kernel_printf.c
index b92ac760a335..da70030ae846 100644
--- a/check_kernel_printf.c
+++ b/check_kernel_printf.c
@@ -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
--
2.37.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] kernel-printf: add printf format %pra for struct range
2025-02-07 3:17 [PATCH] kernel-printf: add printf format %pra for struct range alison.schofield
@ 2025-02-07 8:20 ` Dan Carpenter
0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2025-02-07 8:20 UTC (permalink / raw)
To: alison.schofield; +Cc: smatch, ira.weiny
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-02-07 8:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-07 3:17 [PATCH] kernel-printf: add printf format %pra for struct range alison.schofield
2025-02-07 8:20 ` Dan Carpenter
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.