From: alison.schofield@intel.com
To: smatch@vger.kernel.org
Cc: Alison Schofield <alison.schofield@intel.com>, ira.weiny@intel.com
Subject: [PATCH] kernel-printf: add printf format %pra for struct range
Date: Thu, 6 Feb 2025 19:17:33 -0800 [thread overview]
Message-ID: <20250207031736.1693607-1-alison.schofield@intel.com> (raw)
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
next reply other threads:[~2025-02-07 3:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-07 3:17 alison.schofield [this message]
2025-02-07 8:20 ` [PATCH] kernel-printf: add printf format %pra for struct range Dan Carpenter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250207031736.1693607-1-alison.schofield@intel.com \
--to=alison.schofield@intel.com \
--cc=ira.weiny@intel.com \
--cc=smatch@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.