linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yuanhan Liu <yuanhan.liu@linux.intel.com>
To: Stefani Seibold <stefani@seibold.net>
Cc: linux-kernel@vger.kernel.org, Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH 1/5] kfifo: remove unnecessary type check
Date: Wed, 9 Jan 2013 10:35:03 +0800	[thread overview]
Message-ID: <20130109023503.GC304@yliu-dev.sh.intel.com> (raw)
In-Reply-To: <1357681864.27255.5.camel@wall-e>

On Tue, Jan 08, 2013 at 10:51:04PM +0100, Stefani Seibold wrote:
> Am Dienstag, den 08.01.2013, 22:57 +0800 schrieb Yuanhan Liu:
> > Firstly, this kind of type check doesn't work. It does something similar
> > as following:
> > 	void * __dummy = NULL;
> > 	__buf = __dummy;
> > 
> > __dummy is defined as void *. Thus it will not trigger warnings as
> > expected.
> > 
> > Second, we don't need that kind of check. Since the prototype
> > of __kfifo_out is:
> > 	unsigned int __kfifo_out(struct __kfifo *fifo,  void *buf, unsigned int len)
> > 
> > buf is defined as void *, so we don't need do the type check. Remove it.
> > 
> 
> Thats wrong.
> 
> First the type checking will be used in kfifo_put() and kfifo_in() for
> const types to check if the passed type of the data can converted to the
> fifo element type. 

Hi Stefani,

Yes, I see now. After rechecking the code, I found that this kind of
type checking only works for those static defined kifo by
DECLARE/DEFINE_KFIFO. As the ptrtype is the same as the data type:

    /* the 4th argument "type" is "ptrtype" */
    #define STRUCT_KFIFO(type, size) struct __STRUCT_KFIFO(type, size, 0, type)

    #define DECLARE_KFIFO(fifo, type, size) STRUCT_KFIFO(type, size) fifo

While, for those kfifo dynamically allocated, the type checking will not
work as expected then as ptrtype is always "void":

    struct kfifo __STRUCT_KFIFO_PTR(unsigned char, 0, void);

So, there is no need to do type force convertion like following:
    arch/arm/plat-omap/mailbox.c:   len = kfifo_in(&mq->fifo, (unsigned char *)&msg, sizeof(msg));
As mq->fifo is dynamically allocated.

So, the type checking does work, and I'll drop this patch.

Sorry for the noisy.

	--yliu

> And it will be used in kfifo_get(), kfifo_peek(), kfifo_out() and
> kfio_out_peek() to check if the element type of the fifo can be
> converted to the passed type of the destination.
> 
> So a big NAK!  
> 
> > v2: remove ptr and const_ptr, which were used for type checking.
> > 
> > LINK: https://lkml.org/lkml/2012/10/25/386
> > LINK: https://lkml.org/lkml/2012/10/25/584
> > 
> > Cc: Stefani Seibold <stefani@seibold.net>
> > Cc: Andrew Morton <akpm@linux-foundation.org>
> > Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
> > ---
> >  include/linux/kfifo.h |   46 ++++++++++++----------------------------------
> >  1 files changed, 12 insertions(+), 34 deletions(-)
> > 
> > diff --git a/include/linux/kfifo.h b/include/linux/kfifo.h
> > index 10308c6..7a18245 100644
> > --- a/include/linux/kfifo.h
> > +++ b/include/linux/kfifo.h
> > @@ -63,49 +63,47 @@ struct __kfifo {
> >  	void		*data;
> >  };
> >  
> > -#define __STRUCT_KFIFO_COMMON(datatype, recsize, ptrtype) \
> > +#define __STRUCT_KFIFO_COMMON(datatype, recsize) \
> >  	union { \
> >  		struct __kfifo	kfifo; \
> >  		datatype	*type; \
> >  		char		(*rectype)[recsize]; \
> > -		ptrtype		*ptr; \
> > -		const ptrtype	*ptr_const; \
> >  	}
> >  
> > -#define __STRUCT_KFIFO(type, size, recsize, ptrtype) \
> > +#define __STRUCT_KFIFO(type, size, recsize) \
> >  { \
> > -	__STRUCT_KFIFO_COMMON(type, recsize, ptrtype); \
> > +	__STRUCT_KFIFO_COMMON(type, recsize); \
> >  	type		buf[((size < 2) || (size & (size - 1))) ? -1 : size]; \
> >  }
> >  
> >  #define STRUCT_KFIFO(type, size) \
> > -	struct __STRUCT_KFIFO(type, size, 0, type)
> > +	struct __STRUCT_KFIFO(type, size, 0)
> >  
> > -#define __STRUCT_KFIFO_PTR(type, recsize, ptrtype) \
> > +#define __STRUCT_KFIFO_PTR(type, recsize) \
> >  { \
> > -	__STRUCT_KFIFO_COMMON(type, recsize, ptrtype); \
> > +	__STRUCT_KFIFO_COMMON(type, recsize); \
> >  	type		buf[0]; \
> >  }
> >  
> >  #define STRUCT_KFIFO_PTR(type) \
> > -	struct __STRUCT_KFIFO_PTR(type, 0, type)
> > +	struct __STRUCT_KFIFO_PTR(type, 0)
> >  
> >  /*
> >   * define compatibility "struct kfifo" for dynamic allocated fifos
> >   */
> > -struct kfifo __STRUCT_KFIFO_PTR(unsigned char, 0, void);
> > +struct kfifo __STRUCT_KFIFO_PTR(unsigned char, 0);
> >  
> >  #define STRUCT_KFIFO_REC_1(size) \
> > -	struct __STRUCT_KFIFO(unsigned char, size, 1, void)
> > +	struct __STRUCT_KFIFO(unsigned char, size, 1)
> >  
> >  #define STRUCT_KFIFO_REC_2(size) \
> > -	struct __STRUCT_KFIFO(unsigned char, size, 2, void)
> > +	struct __STRUCT_KFIFO(unsigned char, size, 2)
> >  
> >  /*
> >   * define kfifo_rec types
> >   */
> > -struct kfifo_rec_ptr_1 __STRUCT_KFIFO_PTR(unsigned char, 1, void);
> > -struct kfifo_rec_ptr_2 __STRUCT_KFIFO_PTR(unsigned char, 2, void);
> > +struct kfifo_rec_ptr_1 __STRUCT_KFIFO_PTR(unsigned char, 1);
> > +struct kfifo_rec_ptr_2 __STRUCT_KFIFO_PTR(unsigned char, 2);
> >  
> >  /*
> >   * helper macro to distinguish between real in place fifo where the fifo
> > @@ -390,10 +388,6 @@ __kfifo_int_must_check_helper( \
> >  	unsigned int __ret; \
> >  	const size_t __recsize = sizeof(*__tmp->rectype); \
> >  	struct __kfifo *__kfifo = &__tmp->kfifo; \
> > -	if (0) { \
> > -		typeof(__tmp->ptr_const) __dummy __attribute__ ((unused)); \
> > -		__dummy = (typeof(__val))NULL; \
> > -	} \
> >  	if (__recsize) \
> >  		__ret = __kfifo_in_r(__kfifo, __val, sizeof(*__val), \
> >  			__recsize); \
> > @@ -432,8 +426,6 @@ __kfifo_uint_must_check_helper( \
> >  	unsigned int __ret; \
> >  	const size_t __recsize = sizeof(*__tmp->rectype); \
> >  	struct __kfifo *__kfifo = &__tmp->kfifo; \
> > -	if (0) \
> > -		__val = (typeof(__tmp->ptr))0; \
> >  	if (__recsize) \
> >  		__ret = __kfifo_out_r(__kfifo, __val, sizeof(*__val), \
> >  			__recsize); \
> > @@ -473,8 +465,6 @@ __kfifo_uint_must_check_helper( \
> >  	unsigned int __ret; \
> >  	const size_t __recsize = sizeof(*__tmp->rectype); \
> >  	struct __kfifo *__kfifo = &__tmp->kfifo; \
> > -	if (0) \
> > -		__val = (typeof(__tmp->ptr))NULL; \
> >  	if (__recsize) \
> >  		__ret = __kfifo_out_peek_r(__kfifo, __val, sizeof(*__val), \
> >  			__recsize); \
> > @@ -512,10 +502,6 @@ __kfifo_uint_must_check_helper( \
> >  	unsigned long __n = (n); \
> >  	const size_t __recsize = sizeof(*__tmp->rectype); \
> >  	struct __kfifo *__kfifo = &__tmp->kfifo; \
> > -	if (0) { \
> > -		typeof(__tmp->ptr_const) __dummy __attribute__ ((unused)); \
> > -		__dummy = (typeof(__buf))NULL; \
> > -	} \
> >  	(__recsize) ?\
> >  	__kfifo_in_r(__kfifo, __buf, __n, __recsize) : \
> >  	__kfifo_in(__kfifo, __buf, __n); \
> > @@ -565,10 +551,6 @@ __kfifo_uint_must_check_helper( \
> >  	unsigned long __n = (n); \
> >  	const size_t __recsize = sizeof(*__tmp->rectype); \
> >  	struct __kfifo *__kfifo = &__tmp->kfifo; \
> > -	if (0) { \
> > -		typeof(__tmp->ptr) __dummy = NULL; \
> > -		__buf = __dummy; \
> > -	} \
> >  	(__recsize) ?\
> >  	__kfifo_out_r(__kfifo, __buf, __n, __recsize) : \
> >  	__kfifo_out(__kfifo, __buf, __n); \
> > @@ -777,10 +759,6 @@ __kfifo_uint_must_check_helper( \
> >  	unsigned long __n = (n); \
> >  	const size_t __recsize = sizeof(*__tmp->rectype); \
> >  	struct __kfifo *__kfifo = &__tmp->kfifo; \
> > -	if (0) { \
> > -		typeof(__tmp->ptr) __dummy __attribute__ ((unused)) = NULL; \
> > -		__buf = __dummy; \
> > -	} \
> >  	(__recsize) ? \
> >  	__kfifo_out_peek_r(__kfifo, __buf, __n, __recsize) : \
> >  	__kfifo_out_peek(__kfifo, __buf, __n); \
> 

  reply	other threads:[~2013-01-09  2:34 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-08 14:57 [PATCH 0/5] kfifo cleanup and log based kfifo API Yuanhan Liu
2013-01-08 14:57 ` [PATCH 1/5] kfifo: remove unnecessary type check Yuanhan Liu
2013-01-08 21:51   ` Stefani Seibold
2013-01-09  2:35     ` Yuanhan Liu [this message]
2013-01-09 15:29       ` Stefani Seibold
2013-01-10  7:12         ` Yuanhan Liu
2013-01-08 14:57 ` [PATCH 2/5] libsrp: replace kfifo_init with kfifo_alloc Yuanhan Liu
2013-01-08 14:57 ` [PATCH 3/5] libiscsi: " Yuanhan Liu
2013-01-08 14:57 ` [PATCH 4/5] kfifo: remove kfifo_init Yuanhan Liu
2013-01-08 14:57 ` [PATCH 5/5] kfifo: log based kfifo API Yuanhan Liu
2013-01-08 18:16   ` Dmitry Torokhov
2013-01-08 21:10     ` Andy Walls
2013-01-09  2:42     ` Yuanhan Liu
2013-01-08 15:03 ` Antw: [PATCH 0/5] kfifo cleanup and " Ulrich Windl
2013-01-08 15:29   ` Yuanhan Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130109023503.GC304@yliu-dev.sh.intel.com \
    --to=yuanhan.liu@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stefani@seibold.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).