* [PATCH] Fix _IOC_TYPECHECK sparse error
@ 2014-04-01 7:04 Hans Verkuil
2014-04-01 14:28 ` Josh Triplett
0 siblings, 1 reply; 5+ messages in thread
From: Hans Verkuil @ 2014-04-01 7:04 UTC (permalink / raw)
To: Linus Torvalds, LKML
Cc: Sparse Mailing-list, Linux Media Mailing List, Christopher Li
When running sparse over drivers/media/v4l2-core/v4l2-ioctl.c I get these
errors:
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 (as is already done if __KERNEL__ is not defined):
#define _IOC_TYPECHECK(t) (sizeof(t))
then all is well with the world.
This patch allows sparse to work correctly.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
diff --git a/include/asm-generic/ioctl.h b/include/asm-generic/ioctl.h
index d17295b..297fb0d 100644
--- a/include/asm-generic/ioctl.h
+++ b/include/asm-generic/ioctl.h
@@ -3,10 +3,15 @@
#include <uapi/asm-generic/ioctl.h>
+#ifdef __CHECKER__
+#define _IOC_TYPECHECK(t) (sizeof(t))
+#else
/* 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)
+#endif
+
#endif /* _ASM_GENERIC_IOCTL_H */
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix _IOC_TYPECHECK sparse error
2014-04-01 7:04 [PATCH] Fix _IOC_TYPECHECK sparse error Hans Verkuil
@ 2014-04-01 14:28 ` Josh Triplett
0 siblings, 0 replies; 5+ messages in thread
From: Josh Triplett @ 2014-04-01 14:28 UTC (permalink / raw)
To: Hans Verkuil
Cc: Linus Torvalds, LKML, Sparse Mailing-list,
Linux Media Mailing List, Christopher Li
On Tue, Apr 01, 2014 at 09:04:12AM +0200, Hans Verkuil wrote:
> When running sparse over drivers/media/v4l2-core/v4l2-ioctl.c I get these
> errors:
>
> 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 (as is already done if __KERNEL__ is not defined):
>
> #define _IOC_TYPECHECK(t) (sizeof(t))
>
> then all is well with the world.
>
> This patch allows sparse to work correctly.
>
> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Reviewed-by: Josh Triplett <josh@joshtriplett.org>
> diff --git a/include/asm-generic/ioctl.h b/include/asm-generic/ioctl.h
> index d17295b..297fb0d 100644
> --- a/include/asm-generic/ioctl.h
> +++ b/include/asm-generic/ioctl.h
> @@ -3,10 +3,15 @@
>
> #include <uapi/asm-generic/ioctl.h>
>
> +#ifdef __CHECKER__
> +#define _IOC_TYPECHECK(t) (sizeof(t))
> +#else
> /* 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)
> +#endif
> +
> #endif /* _ASM_GENERIC_IOCTL_H */
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix _IOC_TYPECHECK sparse error
2014-05-09 20:59 ` Andrew Morton
@ 2014-05-12 13:17 ` Hans Verkuil
0 siblings, 0 replies; 5+ messages in thread
From: Hans Verkuil @ 2014-05-12 13:17 UTC (permalink / raw)
To: Andrew Morton; +Cc: Linux Media Mailing List, LKML
On 05/09/2014 10:59 PM, Andrew Morton wrote:
> On Fri, 09 May 2014 09:43:58 +0200 Hans Verkuil <hverkuil@xs4all.nl> wrote:
>
>> Andrew, can you merge this for 3.15 or 3.16 (you decide)? While it fixes a sparse error
>> for the media subsystem, it is not really appropriate to go through our media tree.
>>
>> Thanks,
>>
>> Hans
>>
>>
>> When running sparse over drivers/media/v4l2-core/v4l2-ioctl.c I get these
>> errors:
>>
>> 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 (as is already done if __KERNEL__ is not defined):
>>
>> #define _IOC_TYPECHECK(t) (sizeof(t))
>>
>> then all is well with the world.
>>
>> This patch allows sparse to work correctly.
>>
>> --- a/include/asm-generic/ioctl.h
>> +++ b/include/asm-generic/ioctl.h
>> @@ -3,10 +3,15 @@
>>
>> #include <uapi/asm-generic/ioctl.h>
>>
>> +#ifdef __CHECKER__
>> +#define _IOC_TYPECHECK(t) (sizeof(t))
>> +#else
>> /* 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)
>> +#endif
>> +
>> #endif /* _ASM_GENERIC_IOCTL_H */
>
> Can't we use BUILD_BUG_ON() here? That's neater, more standard and
> BUILD_BUG_ON() already has sparse handling.
I don't think so. BUILD_BUG_ON is not meant to be used in an expression, whereas
_IOC_TYPECHECK(t) is (it should return sizeof(t)).
This looked promising at first sight:
#define _IOC_TYPECHECK(t) \
({BUILD_BUG_ON(sizeof(t) == sizeof(t[1]) && sizeof(t) < (1 << _IOC_SIZEBITS)); \
sizeof(t);})
But it leads to 'case label does not reduce to an integer constant' compile errors.
And a typical ioctl define expands to this horror:
case (((2U) << (((0 +8)+8)+14)) | ((('M')) << (0 +8)) | (((1)) << 0) | (((({do { bool __cond = !(!(sizeof(int) == sizeof(int[1]) && sizeof(int) < (1 << 14))); extern void __compiletime_assert_1909(void) __attribute__((error("BUILD_BUG_ON failed: " "sizeof(int) == sizeof(int[1]) && sizeof(int) < (1 << _IOC_SIZEBITS)"))); if (__cond) __compiletime_assert_1909(); do { } while (0); } while (0); sizeof(int);}))) << ((0 +8)+8))):
which also explains the errors: case labels with function calls in them won't compile.
So I think my proposed patch is the best approach.
Regards,
Hans
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix _IOC_TYPECHECK sparse error
2014-05-09 7:43 Hans Verkuil
@ 2014-05-09 20:59 ` Andrew Morton
2014-05-12 13:17 ` Hans Verkuil
0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2014-05-09 20:59 UTC (permalink / raw)
To: Hans Verkuil; +Cc: Linux Media Mailing List, LKML
On Fri, 09 May 2014 09:43:58 +0200 Hans Verkuil <hverkuil@xs4all.nl> wrote:
> Andrew, can you merge this for 3.15 or 3.16 (you decide)? While it fixes a sparse error
> for the media subsystem, it is not really appropriate to go through our media tree.
>
> Thanks,
>
> Hans
>
>
> When running sparse over drivers/media/v4l2-core/v4l2-ioctl.c I get these
> errors:
>
> 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 (as is already done if __KERNEL__ is not defined):
>
> #define _IOC_TYPECHECK(t) (sizeof(t))
>
> then all is well with the world.
>
> This patch allows sparse to work correctly.
>
> --- a/include/asm-generic/ioctl.h
> +++ b/include/asm-generic/ioctl.h
> @@ -3,10 +3,15 @@
>
> #include <uapi/asm-generic/ioctl.h>
>
> +#ifdef __CHECKER__
> +#define _IOC_TYPECHECK(t) (sizeof(t))
> +#else
> /* 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)
> +#endif
> +
> #endif /* _ASM_GENERIC_IOCTL_H */
Can't we use BUILD_BUG_ON() here? That's neater, more standard and
BUILD_BUG_ON() already has sparse handling.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] Fix _IOC_TYPECHECK sparse error
@ 2014-05-09 7:43 Hans Verkuil
2014-05-09 20:59 ` Andrew Morton
0 siblings, 1 reply; 5+ messages in thread
From: Hans Verkuil @ 2014-05-09 7:43 UTC (permalink / raw)
To: Linux Media Mailing List, LKML, Andrew Morton
Andrew, can you merge this for 3.15 or 3.16 (you decide)? While it fixes a sparse error
for the media subsystem, it is not really appropriate to go through our media tree.
Thanks,
Hans
When running sparse over drivers/media/v4l2-core/v4l2-ioctl.c I get these
errors:
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 (as is already done if __KERNEL__ is not defined):
#define _IOC_TYPECHECK(t) (sizeof(t))
then all is well with the world.
This patch allows sparse to work correctly.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Reviewed-by: Josh Triplett <josh@joshtriplett.org>
---
include/asm-generic/ioctl.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/include/asm-generic/ioctl.h b/include/asm-generic/ioctl.h
index d17295b..297fb0d 100644
--- a/include/asm-generic/ioctl.h
+++ b/include/asm-generic/ioctl.h
@@ -3,10 +3,15 @@
#include <uapi/asm-generic/ioctl.h>
+#ifdef __CHECKER__
+#define _IOC_TYPECHECK(t) (sizeof(t))
+#else
/* 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)
+#endif
+
#endif /* _ASM_GENERIC_IOCTL_H */
--
2.0.0.rc0
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-05-12 13:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-01 7:04 [PATCH] Fix _IOC_TYPECHECK sparse error Hans Verkuil
2014-04-01 14:28 ` Josh Triplett
2014-05-09 7:43 Hans Verkuil
2014-05-09 20:59 ` Andrew Morton
2014-05-12 13:17 ` Hans Verkuil
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).