* [PATCH v2] gpiolib: Switch to use compat_need_64bit_alignment_fixup() helper
@ 2020-10-08 13:41 Andy Shevchenko
2020-10-12 4:20 ` Kent Gibson
2020-10-12 13:07 ` Kent Gibson
0 siblings, 2 replies; 5+ messages in thread
From: Andy Shevchenko @ 2020-10-08 13:41 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, linux-gpio, Kent Gibson
Cc: Andy Shevchenko
The new compat_need_64bit_alignment_fixup() helper allows to avoid
ugly ifdeffery in IOCTL compatible code. Use it in GPIO cdev code.
Depends-on: 527c412519eb ("compat: add a compat_need_64bit_alignment_fixup() helper")
Depends-on: cc7886d25bca ("compat: lift compat_s64 and compat_u64 to <asm-generic/compat.h>")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v2: removed lineevent_get_size() completely, fixed typo in commit message
drivers/gpio/gpiolib-cdev.c | 24 ++++++++----------------
1 file changed, 8 insertions(+), 16 deletions(-)
diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index e9faeaf65d14..192721f829a3 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -1479,21 +1479,10 @@ static __poll_t lineevent_poll(struct file *file,
return events;
}
-static ssize_t lineevent_get_size(void)
-{
-#if defined(CONFIG_X86_64) && !defined(CONFIG_UML)
- /* i386 has no padding after 'id' */
- if (in_ia32_syscall()) {
- struct compat_gpioeevent_data {
- compat_u64 timestamp;
- u32 id;
- };
-
- return sizeof(struct compat_gpioeevent_data);
- }
-#endif
- return sizeof(struct gpioevent_data);
-}
+struct compat_gpioeevent_data {
+ compat_u64 timestamp;
+ u32 id;
+};
static ssize_t lineevent_read(struct file *file,
char __user *buf,
@@ -1515,7 +1504,10 @@ static ssize_t lineevent_read(struct file *file,
* actual sizeof() and pass this as an argument to copy_to_user() to
* drop unneeded bytes from the output.
*/
- ge_size = lineevent_get_size();
+ if (compat_need_64bit_alignment_fixup())
+ ge_size = sizeof(struct compat_gpioeevent_data);
+ else
+ ge_size = sizeof(struct gpioevent_data);
if (count < ge_size)
return -EINVAL;
--
2.28.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] gpiolib: Switch to use compat_need_64bit_alignment_fixup() helper
2020-10-08 13:41 [PATCH v2] gpiolib: Switch to use compat_need_64bit_alignment_fixup() helper Andy Shevchenko
@ 2020-10-12 4:20 ` Kent Gibson
2020-10-12 10:03 ` Andy Shevchenko
2020-10-12 13:07 ` Kent Gibson
1 sibling, 1 reply; 5+ messages in thread
From: Kent Gibson @ 2020-10-12 4:20 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: Linus Walleij, Bartosz Golaszewski, linux-gpio
On Thu, Oct 08, 2020 at 04:41:05PM +0300, Andy Shevchenko wrote:
> The new compat_need_64bit_alignment_fixup() helper allows to avoid
> ugly ifdeffery in IOCTL compatible code. Use it in GPIO cdev code.
>
> Depends-on: 527c412519eb ("compat: add a compat_need_64bit_alignment_fixup() helper")
> Depends-on: cc7886d25bca ("compat: lift compat_s64 and compat_u64 to <asm-generic/compat.h>")
Where can I find these?
Cheers,
Kent.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] gpiolib: Switch to use compat_need_64bit_alignment_fixup() helper
2020-10-12 4:20 ` Kent Gibson
@ 2020-10-12 10:03 ` Andy Shevchenko
0 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2020-10-12 10:03 UTC (permalink / raw)
To: Kent Gibson; +Cc: Linus Walleij, Bartosz Golaszewski, linux-gpio
On Mon, Oct 12, 2020 at 12:20:10PM +0800, Kent Gibson wrote:
> On Thu, Oct 08, 2020 at 04:41:05PM +0300, Andy Shevchenko wrote:
> > The new compat_need_64bit_alignment_fixup() helper allows to avoid
> > ugly ifdeffery in IOCTL compatible code. Use it in GPIO cdev code.
> >
> > Depends-on: 527c412519eb ("compat: add a compat_need_64bit_alignment_fixup() helper")
> > Depends-on: cc7886d25bca ("compat: lift compat_s64 and compat_u64 to <asm-generic/compat.h>")
>
> Where can I find these?
Soon in Linux upstream, but currently in Al Viro's tree: https://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs.git/log/?h=work.quota-compat
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] gpiolib: Switch to use compat_need_64bit_alignment_fixup() helper
2020-10-08 13:41 [PATCH v2] gpiolib: Switch to use compat_need_64bit_alignment_fixup() helper Andy Shevchenko
2020-10-12 4:20 ` Kent Gibson
@ 2020-10-12 13:07 ` Kent Gibson
2020-10-12 14:00 ` Andy Shevchenko
1 sibling, 1 reply; 5+ messages in thread
From: Kent Gibson @ 2020-10-12 13:07 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: Linus Walleij, Bartosz Golaszewski, linux-gpio
On Thu, Oct 08, 2020 at 04:41:05PM +0300, Andy Shevchenko wrote:
> The new compat_need_64bit_alignment_fixup() helper allows to avoid
> ugly ifdeffery in IOCTL compatible code. Use it in GPIO cdev code.
>
I'd re-arrange that checkin comment to
"Use the new compat_need_64bit_alignment_fixup() helper to avoid
ugly ifdeffery in IOCTL compatibility code."
but otherwise all good.
+1 on the deuglification, and it still works too.
Tested-by: Kent Gibson <warthog618@gmail.com>
> Depends-on: 527c412519eb ("compat: add a compat_need_64bit_alignment_fixup() helper")
> Depends-on: cc7886d25bca ("compat: lift compat_s64 and compat_u64 to <asm-generic/compat.h>")
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> v2: removed lineevent_get_size() completely, fixed typo in commit message
> drivers/gpio/gpiolib-cdev.c | 24 ++++++++----------------
> 1 file changed, 8 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
> index e9faeaf65d14..192721f829a3 100644
> --- a/drivers/gpio/gpiolib-cdev.c
> +++ b/drivers/gpio/gpiolib-cdev.c
> @@ -1479,21 +1479,10 @@ static __poll_t lineevent_poll(struct file *file,
> return events;
> }
>
> -static ssize_t lineevent_get_size(void)
> -{
> -#if defined(CONFIG_X86_64) && !defined(CONFIG_UML)
> - /* i386 has no padding after 'id' */
> - if (in_ia32_syscall()) {
> - struct compat_gpioeevent_data {
> - compat_u64 timestamp;
> - u32 id;
> - };
> -
> - return sizeof(struct compat_gpioeevent_data);
> - }
> -#endif
> - return sizeof(struct gpioevent_data);
> -}
> +struct compat_gpioeevent_data {
> + compat_u64 timestamp;
> + u32 id;
> +};
>
> static ssize_t lineevent_read(struct file *file,
> char __user *buf,
> @@ -1515,7 +1504,10 @@ static ssize_t lineevent_read(struct file *file,
> * actual sizeof() and pass this as an argument to copy_to_user() to
> * drop unneeded bytes from the output.
> */
> - ge_size = lineevent_get_size();
> + if (compat_need_64bit_alignment_fixup())
> + ge_size = sizeof(struct compat_gpioeevent_data);
> + else
> + ge_size = sizeof(struct gpioevent_data);
> if (count < ge_size)
> return -EINVAL;
>
> --
> 2.28.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] gpiolib: Switch to use compat_need_64bit_alignment_fixup() helper
2020-10-12 13:07 ` Kent Gibson
@ 2020-10-12 14:00 ` Andy Shevchenko
0 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2020-10-12 14:00 UTC (permalink / raw)
To: Kent Gibson; +Cc: Linus Walleij, Bartosz Golaszewski, linux-gpio
On Mon, Oct 12, 2020 at 09:07:41PM +0800, Kent Gibson wrote:
> On Thu, Oct 08, 2020 at 04:41:05PM +0300, Andy Shevchenko wrote:
> > The new compat_need_64bit_alignment_fixup() helper allows to avoid
> > ugly ifdeffery in IOCTL compatible code. Use it in GPIO cdev code.
> I'd re-arrange that checkin comment to
>
> "Use the new compat_need_64bit_alignment_fixup() helper to avoid
> ugly ifdeffery in IOCTL compatibility code."
OK!
> but otherwise all good.
>
> +1 on the deuglification, and it still works too.
>
> Tested-by: Kent Gibson <warthog618@gmail.com>
Thanks.
> > Depends-on: 527c412519eb ("compat: add a compat_need_64bit_alignment_fixup() helper")
> > Depends-on: cc7886d25bca ("compat: lift compat_s64 and compat_u64 to <asm-generic/compat.h>")
I'll also drop this one, since former is dependent on latter.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-10-12 14:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-08 13:41 [PATCH v2] gpiolib: Switch to use compat_need_64bit_alignment_fixup() helper Andy Shevchenko
2020-10-12 4:20 ` Kent Gibson
2020-10-12 10:03 ` Andy Shevchenko
2020-10-12 13:07 ` Kent Gibson
2020-10-12 14:00 ` Andy Shevchenko
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.