From: Christopher Li <sparse@chrisli.org>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
kbuild test robot <fengguang.wu@intel.com>,
Jingoo Han <jg1.han@samsung.com>,
kbuild-all@01.org, Linux-Sparse <linux-sparse@vger.kernel.org>,
linux-kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH] forced argument Was Re: sparse: incorrect type in argument 1 (different address spaces)
Date: Thu, 25 Apr 2013 19:09:37 -0700 [thread overview]
Message-ID: <5179E1E1.4050304@chrisli.org> (raw)
In-Reply-To: <20130423061600.GN6638@mwanda>
[-- Attachment #1: Type: text/plain, Size: 722 bytes --]
On 04/22/2013 11:16 PM, Dan Carpenter wrote:
> That didn't work. It's the the void * in the parameter list that's
> the problem. We'd need to do something like the patch below:
>
> Otherwise we could add "__ok_to_cast" thing to Sparse maybe?
Thanks for the insight. I make a small patch to test the __ok_to_cast
feature. The syntax is adding the force attribute to the argument
declaration.
it will look like this:
static inline long __must_check PTR_ERR( __force const void *ptr)
That means the "ptr" argument will perform a forced cast when receiving
the argument. It is OK to pass __iomem pointer to "ptr".
The example are in the patch. It need to patch both sparse and the
Linux tree.
What do you say?
Chris
[-- Attachment #2: 0001-Allow-forced-attribute-in-function-argument.patch --]
[-- Type: text/x-patch, Size: 2072 bytes --]
>From a0974ed0fc1e67c41608c780b748c205622956b8 Mon Sep 17 00:00:00 2001
From: Christopher Li <sparse@chrisli.org>
Date: Thu, 25 Apr 2013 18:09:43 -0700
Subject: [PATCH] Allow forced attribute in function argument
It will indicate this argument will skip the compatible check.
---
evaluate.c | 2 +-
parse.c | 1 +
symbol.h | 3 ++-
validation/fored_arg.c | 18 ++++++++++++++++++
4 files changed, 22 insertions(+), 2 deletions(-)
create mode 100644 validation/fored_arg.c
diff --git a/evaluate.c b/evaluate.c
index 9f2c4ac..0dfa519 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -2137,7 +2137,7 @@ static int evaluate_arguments(struct symbol *f, struct symbol *fn, struct expres
else
degenerate(expr);
}
- } else {
+ } else if (!target->forced_arg){
static char where[30];
examine_symbol_type(target);
sprintf(where, "argument %d", i);
diff --git a/parse.c b/parse.c
index 45ffc10..890e56b 100644
--- a/parse.c
+++ b/parse.c
@@ -1841,6 +1841,7 @@ static struct token *parameter_declaration(struct token *token, struct symbol *s
sym->ctype = ctx.ctype;
sym->ctype.modifiers |= storage_modifiers(&ctx);
sym->endpos = token->pos;
+ sym->forced_arg = ctx.storage_class == SForced;
return token;
}
diff --git a/symbol.h b/symbol.h
index 1e74579..1c6ad66 100644
--- a/symbol.h
+++ b/symbol.h
@@ -157,7 +157,8 @@ struct symbol {
expanding:1,
evaluated:1,
string:1,
- designated_init:1;
+ designated_init:1,
+ forced_arg:1;
struct expression *array_size;
struct ctype ctype;
struct symbol_list *arguments;
diff --git a/validation/fored_arg.c b/validation/fored_arg.c
new file mode 100644
index 0000000..4ab7141
--- /dev/null
+++ b/validation/fored_arg.c
@@ -0,0 +1,18 @@
+/*
+ * check-name: Forced function argument type.
+ */
+
+#define __iomem __attribute__((noderef, address_space(2)))
+#define __force __attribute__((force))
+
+static void foo(__force void * addr)
+{
+}
+
+
+static void bar(void)
+{
+ void __iomem *a;
+ foo(a);
+}
+
--
1.8.1.4
next prev parent reply other threads:[~2013-04-26 2:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <5171d93a.0NZAGYYKNj8hjsAs%fengguang.wu@intel.com>
2013-04-22 23:56 ` [next:akpm 798/1000] drivers/rtc/rtc-ds1286.c:343:24: sparse: incorrect type in argument 1 (different address spaces) Andrew Morton
2013-04-23 2:51 ` Fengguang Wu
2013-04-23 2:56 ` Christopher Li
2013-04-23 6:16 ` Dan Carpenter
2013-04-26 2:09 ` Christopher Li [this message]
2013-04-26 6:35 ` [PATCH] forced argument Was " 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=5179E1E1.4050304@chrisli.org \
--to=sparse@chrisli.org \
--cc=akpm@linux-foundation.org \
--cc=dan.carpenter@oracle.com \
--cc=fengguang.wu@intel.com \
--cc=jg1.han@samsung.com \
--cc=kbuild-all@01.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sparse@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox