linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* sparse: ioctl defines and "error: bad integer constant expression"
@ 2014-03-15 11:59 Hans Verkuil
  2014-03-31  8:06 ` Hans Verkuil
  0 siblings, 1 reply; 6+ messages in thread
From: Hans Verkuil @ 2014-03-15 11:59 UTC (permalink / raw)
  To: linux-sparse; +Cc: Linux Media Mailing List

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.

Regards,

	Hans

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: sparse: ioctl defines and "error: bad integer constant expression"
  2014-03-15 11:59 sparse: ioctl defines and "error: bad integer constant expression" Hans Verkuil
@ 2014-03-31  8:06 ` Hans Verkuil
  2014-03-31 17:22   ` Linus Torvalds
  0 siblings, 1 reply; 6+ messages in thread
From: Hans Verkuil @ 2014-03-31  8:06 UTC (permalink / raw)
  To: linux-sparse; +Cc: Linux Media Mailing List

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: sparse: ioctl defines and "error: bad integer constant expression"
  2014-03-31  8:06 ` Hans Verkuil
@ 2014-03-31 17:22   ` Linus Torvalds
  2014-04-01 16:48     ` Christopher Li
  0 siblings, 1 reply; 6+ messages in thread
From: Linus Torvalds @ 2014-03-31 17:22 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: Sparse Mailing-list, Linux Media Mailing List

On Mon, Mar 31, 2014 at 1:06 AM, Hans Verkuil <hverkuil@xs4all.nl> wrote:
>
> Running sparse over this gives:
>
> error: bad integer constant expression

So technically sparse is correct in this case. The kernel ends up
doing some questionable things that gcc allows. The index in an
assignment initializer is supposed to be a true constant expression,
not "constant expression after simplification and optimization".

So sparse warns about us playing games that just happen to work with
gcc. I'm not sure we should fix sparse for this case.

I'll think about it, but not right now (I did the previous one because
it was trivial, but now I'm in merge window mode, so I'd better go
back and look at kernel pull requests)

Chris, can you please add this to the test cases since Hans did the
work to create a nice small test-case?

            Linus

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: sparse: ioctl defines and "error: bad integer constant expression"
  2014-03-31 17:22   ` Linus Torvalds
@ 2014-04-01 16:48     ` Christopher Li
  2014-04-01 17:06       ` Hans Verkuil
  0 siblings, 1 reply; 6+ messages in thread
From: Christopher Li @ 2014-04-01 16:48 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Hans Verkuil, Sparse Mailing-list, Linux Media Mailing List

On Mon, Mar 31, 2014 at 10:22 AM, Linus Torvalds
<torvalds@linux-foundation.org> wrote:
> On Mon, Mar 31, 2014 at 1:06 AM, Hans Verkuil <hverkuil@xs4all.nl> wrote:
>
> Chris, can you please add this to the test cases since Hans did the
> work to create a nice small test-case?

Sure, I want to add them to the test case.

Hans, May I get a signed-off for your test cases?

Chris

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: sparse: ioctl defines and "error: bad integer constant expression"
  2014-04-01 16:48     ` Christopher Li
@ 2014-04-01 17:06       ` Hans Verkuil
  2014-04-03 19:12         ` Christopher Li
  0 siblings, 1 reply; 6+ messages in thread
From: Hans Verkuil @ 2014-04-01 17:06 UTC (permalink / raw)
  To: Christopher Li, Linus Torvalds
  Cc: Sparse Mailing-list, Linux Media Mailing List

On 04/01/2014 06:48 PM, Christopher Li wrote:
> On Mon, Mar 31, 2014 at 10:22 AM, Linus Torvalds
> <torvalds@linux-foundation.org> wrote:
>> On Mon, Mar 31, 2014 at 1:06 AM, Hans Verkuil <hverkuil@xs4all.nl> wrote:
>>
>> Chris, can you please add this to the test cases since Hans did the
>> work to create a nice small test-case?
> 
> Sure, I want to add them to the test case.
> 
> Hans, May I get a signed-off for your test cases?

For all my test cases:

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>

Regards,

	Hans

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: sparse: ioctl defines and "error: bad integer constant expression"
  2014-04-01 17:06       ` Hans Verkuil
@ 2014-04-03 19:12         ` Christopher Li
  0 siblings, 0 replies; 6+ messages in thread
From: Christopher Li @ 2014-04-03 19:12 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: Linus Torvalds, Sparse Mailing-list, Linux Media Mailing List

On Tue, Apr 1, 2014 at 10:06 AM, Hans Verkuil <hverkuil@xs4all.nl> wrote:
>
> For all my test cases:
>
> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
>

All 3 test cases added.

Chris

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-04-03 19:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-15 11:59 sparse: ioctl defines and "error: bad integer constant expression" Hans Verkuil
2014-03-31  8:06 ` Hans Verkuil
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).