From: Hans Verkuil <hverkuil@xs4all.nl>
To: linux-sparse@vger.kernel.org
Cc: Linux Media Mailing List <linux-media@vger.kernel.org>
Subject: Re: sparse: ioctl defines and "error: bad integer constant expression"
Date: Mon, 31 Mar 2014 10:06:16 +0200 [thread overview]
Message-ID: <533921F8.1000508@xs4all.nl> (raw)
In-Reply-To: <53244092.6010906@xs4all.nl>
On 03/15/2014 12:59 PM, Hans Verkuil wrote:
> Hi!
>
> Here is another sparse error that I get when running sparse over
> drivers/media/v4l2-core/v4l2-ioctl.c:
>
> drivers/media/v4l2-core/v4l2-ioctl.c:2043:9: error: bad integer constant expression
> drivers/media/v4l2-core/v4l2-ioctl.c:2044:9: error: bad integer constant expression
> drivers/media/v4l2-core/v4l2-ioctl.c:2045:9: error: bad integer constant expression
> drivers/media/v4l2-core/v4l2-ioctl.c:2046:9: error: bad integer constant expression
>
> etc.
>
> The root cause of that turns out to be in include/asm-generic/ioctl.h:
>
> #include <uapi/asm-generic/ioctl.h>
>
> /* provoke compile error for invalid uses of size argument */
> extern unsigned int __invalid_size_argument_for_IOC;
> #define _IOC_TYPECHECK(t) \
> ((sizeof(t) == sizeof(t[1]) && \
> sizeof(t) < (1 << _IOC_SIZEBITS)) ? \
> sizeof(t) : __invalid_size_argument_for_IOC)
>
> If it is defined as this:
>
> #define _IOC_TYPECHECK(t) (sizeof(t))
>
> then all is well with the world.
>
> I can patch v4l2-ioctl.c to redefine _IOC_TYPECHECK if __CHECKER__ is defined, but
> shouldn't sparse understand this instead? There was a similar situation with
> ARRAY_SIZE in the past that sparse now understands.
Here is a small test case for this problem:
====== ioc-typecheck.c ======
extern unsigned int __invalid_size_argument_for_IOC;
#define _IOC_TYPECHECK(t) \
((sizeof(t) == sizeof(t[1]) && \
sizeof(t) < (1 << 14)) ? \
sizeof(t) : __invalid_size_argument_for_IOC)
#define TEST_IOCTL (50 | (_IOC_TYPECHECK(unsigned) << 8))
static unsigned iocnrs[] = {
[TEST_IOCTL & 0xff] = 1,
};
/*
* check-name: correct handling of _IOC_TYPECHECK
*
* check-error-start
* check-error-end
*/
====== ioc-typecheck.c ======
Running sparse over this gives:
error: bad integer constant expression
Regards,
Hans
next prev parent reply other threads:[~2014-03-31 8:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-15 11:59 sparse: ioctl defines and "error: bad integer constant expression" Hans Verkuil
2014-03-31 8:06 ` Hans Verkuil [this message]
2014-03-31 17:22 ` Linus Torvalds
2014-04-01 16:48 ` Christopher Li
2014-04-01 17:06 ` Hans Verkuil
2014-04-03 19:12 ` Christopher Li
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=533921F8.1000508@xs4all.nl \
--to=hverkuil@xs4all.nl \
--cc=linux-media@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 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.