doc: ioctl: Add some clarifications to botching-up-ioctls
PATCH 1/1 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.
---
I can split these into two separate patches if necessary but it seemed simpler just to colapse them into a single patch.
--- Documentation/ioctl/botching-up-ioctls.txt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
Documentation/ioctl/botching-up-ioctls.txt +8 -5
@@ -34,15 +34,18 @@ will need to add a a 32-bit compat layer: 64-bit platforms do. So we always need padding to the natural size to get this right. - * Pad the entire struct to a multiple of 64-bits - the structure size will - otherwise differ on 32-bit versus 64-bit. Having a different structure size - hurts when passing arrays of structures to the kernel, or if the kernel - checks the structure size, which e.g. the drm core does. + * Pad the entire struct to a multiple of 64-bits if the structure contains + 64-bit types - the structure size will otherwise differ on 32-bit versus + 64-bit. Having a different structure size hurts when passing arrays of + structures to the kernel, or if the kernel checks the structure size, which + e.g. the drm core does. * Pointers are __u64, cast from/to a uintprt_t on the userspace side and from/to a void __user * in the kernel. Try really hard not to delay this conversion or worse, fiddle the raw __u64 through your code since that - diminishes the checking tools like sparse can provide. + diminishes the checking tools like sparse can provide. The macro + u64_to_user_ptr can be used in the kernel to avoid warnings about integers + and pointres of different sizes. Basics
Signature · 1 line
2.7.4
Quoted 11 lines · CEST Laura Abbott
- 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__u64to 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 <[email protected]>
Looks good to me,
Quoted 10 lines · On Sat, 03 Sep 2016 00:44:02 +0200 Arnd Bergmann <[email protected]> wrote:
Quoted 9 lines · CEST Laura Abbott
- 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__u64to 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.
Quoted 6 lines
Quoted 2 lines
Signed-off-by Laura Abbott <[email protected]>Looks good to me,
Acked-by Arnd Bergmann <[email protected]>
Applied to the docs tree, thanks.
jon