Skip to content

Commit c6517b7

Browse files
labbottJonathan Corbet
authored andcommitted
doc: ioctl: Add some clarifications to botching-up-ioctls
- The guide currently says to pad the structure to a multiple of 64-bits. This is not necessary in cases where the structure contains no 64-bit types. Clarify this concept to avoid unnecessary padding. - When using __u64 to hold user pointers, blindly trying to do a cast to a void __user * may generate a warning on 32-bit systems about a cast from an integer to a pointer of different size. There is a macro to deal with this which hides an ugly double cast. Add a reference to this macro. Signed-off-by: Laura Abbott <labbott@redhat.com> Acked-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Jonathan Corbet <corbet@lwn.net>
1 parent 9514997 commit c6517b7

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎Documentation/ioctl/botching-up-ioctls.txt‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,18 @@ will need to add a a 32-bit compat layer:
3434
64-bit platforms do. So we always need padding to the natural size to get
3535
this right.
3636

37-
* Pad the entire struct to a multiple of 64-bits - the structure size will
38-
otherwise differ on 32-bit versus 64-bit. Having a different structure size
39-
hurts when passing arrays of structures to the kernel, or if the kernel
40-
checks the structure size, which e.g. the drm core does.
37+
* Pad the entire struct to a multiple of 64-bits if the structure contains
38+
64-bit types - the structure size will otherwise differ on 32-bit versus
39+
64-bit. Having a different structure size hurts when passing arrays of
40+
structures to the kernel, or if the kernel checks the structure size, which
41+
e.g. the drm core does.
4142

4243
* Pointers are __u64, cast from/to a uintprt_t on the userspace side and
4344
from/to a void __user * in the kernel. Try really hard not to delay this
4445
conversion or worse, fiddle the raw __u64 through your code since that
45-
diminishes the checking tools like sparse can provide.
46+
diminishes the checking tools like sparse can provide. The macro
47+
u64_to_user_ptr can be used in the kernel to avoid warnings about integers
48+
and pointres of different sizes.
4649

4750

4851
Basics

0 commit comments

Comments
 (0)