[v3,26/26] kfifo: DECLARE_KIFO_PTR(fifo, u64) does not work on arm 32 bit

Message ID 1507622382.6064.2.camel@seibold.net (mailing list archive)
State Superseded, archived
Delegated to: Sean Young
Headers

Commit Message

Sean Young Oct. 10, 2017, 7:59 a.m. UTC
If you try to store u64 in a kfifo (or a struct with u64 members),
then the buf member of __STRUCT_KFIFO_PTR will cause 4 bytes
padding due to alignment (note that struct __kfifo is 20 bytes
on 32 bit).

That in turn causes the __is_kfifo_ptr() to fail, which is caught
by kfifo_alloc(), which now returns EINVAL.

So, ensure that __is_kfifo_ptr() compares to the right structure.

Signed-off-by: Sean Young <sean@mess.org>
Acked-by: Stefani Seibold <stefani@seibold.net>

---
 include/linux/kfifo.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Mauro Carvalho Chehab Nov. 30, 2017, 12:29 p.m. UTC | #1
Em Tue, 10 Oct 2017 09:59:42 +0200
Sean Young <sean@mess.org> escreveu:

> If you try to store u64 in a kfifo (or a struct with u64 members),
> then the buf member of __STRUCT_KFIFO_PTR will cause 4 bytes
> padding due to alignment (note that struct __kfifo is 20 bytes
> on 32 bit).
> 
> That in turn causes the __is_kfifo_ptr() to fail, which is caught
> by kfifo_alloc(), which now returns EINVAL.
> 
> So, ensure that __is_kfifo_ptr() compares to the right structure.
> 
> Signed-off-by: Sean Young <sean@mess.org>
> Acked-by: Stefani Seibold <stefani@seibold.net>

Hi Stefani/Andrew,

As this patch is required for the LIRC rework, would be ok if I would
merge it via the media tree?

Thanks!
Mauro


> 
> ---
>  include/linux/kfifo.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/kfifo.h b/include/linux/kfifo.h
> index 41eb6fdf87a8..86b5fb08e96c 100644
> --- a/include/linux/kfifo.h
> +++ b/include/linux/kfifo.h
> @@ -113,7 +113,8 @@ struct kfifo_rec_ptr_2 __STRUCT_KFIFO_PTR(unsigned char, 2, void);
>   * array is a part of the structure and the fifo type where the array is
>   * outside of the fifo structure.
>   */
> -#define	__is_kfifo_ptr(fifo)	(sizeof(*fifo) == sizeof(struct __kfifo))
> +#define	__is_kfifo_ptr(fifo) \
> +	(sizeof(*fifo) == sizeof(STRUCT_KFIFO_PTR(typeof(*(fifo)->type))))
>  
>  /**
>   * DECLARE_KFIFO_PTR - macro to declare a fifo pointer object



Thanks,
Mauro
  
Stefani Seibold Nov. 30, 2017, 12:34 p.m. UTC | #2
On Thu, 2017-11-30 at 10:29 -0200, Mauro Carvalho Chehab wrote:
> Em Tue, 10 Oct 2017 09:59:42 +0200
> Sean Young <sean@mess.org> escreveu:
> 
> > If you try to store u64 in a kfifo (or a struct with u64 members),
> > then the buf member of __STRUCT_KFIFO_PTR will cause 4 bytes
> > padding due to alignment (note that struct __kfifo is 20 bytes
> > on 32 bit).
> > 
> > That in turn causes the __is_kfifo_ptr() to fail, which is caught
> > by kfifo_alloc(), which now returns EINVAL.
> > 
> > So, ensure that __is_kfifo_ptr() compares to the right structure.
> > 
> > Signed-off-by: Sean Young <sean@mess.org>
> > Acked-by: Stefani Seibold <stefani@seibold.net>
> 
> Hi Stefani/Andrew,
> 
> As this patch is required for the LIRC rework, would be ok if I would
> merge it via the media tree?
> 

It is okay by me. But the question remains why this patch wasn't
already merged?

Andrew: Any objections against this patch?


> > 
> > ---
> >  include/linux/kfifo.h | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/include/linux/kfifo.h b/include/linux/kfifo.h
> > index 41eb6fdf87a8..86b5fb08e96c 100644
> > --- a/include/linux/kfifo.h
> > +++ b/include/linux/kfifo.h
> > @@ -113,7 +113,8 @@ struct kfifo_rec_ptr_2
> > __STRUCT_KFIFO_PTR(unsigned char, 2, void);
> >   * array is a part of the structure and the fifo type where the
> > array is
> >   * outside of the fifo structure.
> >   */
> > -#define	__is_kfifo_ptr(fifo)	(sizeof(*fifo) ==
> > sizeof(struct __kfifo))
> > +#define	__is_kfifo_ptr(fifo) \
> > +	(sizeof(*fifo) == sizeof(STRUCT_KFIFO_PTR(typeof(*(fifo)-
> > >type))))
> >  
> >  /**
> >   * DECLARE_KFIFO_PTR - macro to declare a fifo pointer object
> 
> 
> 
> Thanks,
> Mauro
  
Mauro Carvalho Chehab Dec. 8, 2017, 2:07 p.m. UTC | #3
Em Thu, 30 Nov 2017 13:34:10 +0100
Stefani Seibold <stefani@seibold.net> escreveu:

> On Thu, 2017-11-30 at 10:29 -0200, Mauro Carvalho Chehab wrote:
> > Em Tue, 10 Oct 2017 09:59:42 +0200
> > Sean Young <sean@mess.org> escreveu:
> >   
> > > If you try to store u64 in a kfifo (or a struct with u64 members),
> > > then the buf member of __STRUCT_KFIFO_PTR will cause 4 bytes
> > > padding due to alignment (note that struct __kfifo is 20 bytes
> > > on 32 bit).
> > > 
> > > That in turn causes the __is_kfifo_ptr() to fail, which is caught
> > > by kfifo_alloc(), which now returns EINVAL.
> > > 
> > > So, ensure that __is_kfifo_ptr() compares to the right structure.
> > > 
> > > Signed-off-by: Sean Young <sean@mess.org>
> > > Acked-by: Stefani Seibold <stefani@seibold.net>  
> > 
> > Hi Stefani/Andrew,
> > 
> > As this patch is required for the LIRC rework, would be ok if I would
> > merge it via the media tree?
> >   
> 
> It is okay by me. But the question remains why this patch wasn't
> already merged?
> 
> Andrew: Any objections against this patch?


I'm assuming that merging via media tree is ok for Andrew. So, I guess
I'll just go ahead and merge it via my tree.


Thanks,
Mauro
  

Patch

diff --git a/include/linux/kfifo.h b/include/linux/kfifo.h
index 41eb6fdf87a8..86b5fb08e96c 100644
--- a/include/linux/kfifo.h
+++ b/include/linux/kfifo.h
@@ -113,7 +113,8 @@  struct kfifo_rec_ptr_2 __STRUCT_KFIFO_PTR(unsigned char, 2, void);
  * array is a part of the structure and the fifo type where the array is
  * outside of the fifo structure.
  */
-#define	__is_kfifo_ptr(fifo)	(sizeof(*fifo) == sizeof(struct __kfifo))
+#define	__is_kfifo_ptr(fifo) \
+	(sizeof(*fifo) == sizeof(STRUCT_KFIFO_PTR(typeof(*(fifo)->type))))
 
 /**
  * DECLARE_KFIFO_PTR - macro to declare a fifo pointer object