linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Vladimirs Ambrosovs <rodriguez.twister@gmail.com>
Cc: lars@metafoo.de, linux-iio@vger.kernel.org,
	gregkh@linuxfoundation.org,
	driverdev-devel@linuxdriverproject.org, pmeerw@pmeerw.net,
	knaack.h@gmx.de, jic23@kernel.org
Subject: Re: [PATCH 2/2] staging: iio_simple_dummy: zero check param
Date: Thu, 28 May 2015 09:59:34 +0300	[thread overview]
Message-ID: <20150528065934.GU11588@mwanda> (raw)
In-Reply-To: <20150527221240.GA23081@gmail.com>

On Thu, May 28, 2015 at 01:12:40AM +0300, Vladimirs Ambrosovs wrote:
> On Wed, May 27, 2015 at 11:25:07AM +0300, Dan Carpenter wrote:
> > On Wed, May 27, 2015 at 01:19:58AM +0300, Vladimirs Ambrosovs wrote:
> > > Check for zero was added to the module parameter "instances" to
> > > avoid the allocation of array of zero values. Although it is a valid call,
> > > we don't want to allocate ZERO_SIZE_PTR, so need to disallow this case.
> > > The type of variables which are compared to "instances" were also changed
> > > to unsigned int so that no compiler complaints occur.
> > 
> > Which compiler is that?
> > 
> > You should get a different compiler if you compiler complains about
> > stupid stuff like that.  Making everything unsigned int is a common
> > cause of problems.  I fixed or reported several of those bugs yesterday.
> > 
> > "instances" should be unsigned int, though, you're correct about that.
> > 
> Mine is fine - not complaining ;). 
> 
> Got your point, although, in some cases, I think, these warnings not a
> stupid stuff, and could get some junior out of trouble.
> 
> But anyway, will keep in mind to stay away from unsigned ints. 

It's not a matter of staying away from unsigned ints, it's that some
people make everything unsigned by default.  That causes problems for
two reasons.  1) The kernel uses negative error codes.  2) int is the
default datatype when you want a "number" in C.  If you want a special
number then you make it unsigned int, u32, or unsigned long or whatever.
All those types mean something.  An unsigned int and a u32 are the same
to a computer but to a human they mean something different.  People who
use complicated datatypes all the time instead of just plain old int are
making the code complicated.


> > > 
> > > Signed-off-by: Vladimirs Ambrosovs <rodriguez.twister@gmail.com>
> > > ---
> > >  drivers/staging/iio/iio_simple_dummy.c | 9 +++++----
> > >  1 file changed, 5 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/drivers/staging/iio/iio_simple_dummy.c b/drivers/staging/iio/iio_simple_dummy.c
> > > index 88fbb4f..2744a1b 100644
> > > --- a/drivers/staging/iio/iio_simple_dummy.c
> > > +++ b/drivers/staging/iio/iio_simple_dummy.c
> > > @@ -30,7 +30,7 @@
> > >   * dummy devices are registered.
> > >   */
> > >  static unsigned instances = 1;
> > > -module_param(instances, int, 0);
> > > +module_param(instances, uint, 0);
> > >  
> > >  /* Pointer array used to fake bus elements */
> > >  static struct iio_dev **iio_dummy_devs;
> > > @@ -706,9 +706,10 @@ static void iio_dummy_remove(int index)
> > >   */
> > >  static __init int iio_dummy_init(void)
> > >  {
> > > -	int i, ret;
> > > +	unsigned int i;
> > > +	int ret;
> > 
> > No.
> > 
> > >  
> > > -	if (instances > 10) {
> > > +	if (instances == 0 || instances > 10) {
> > >  		instances = 1;
> > >  		return -EINVAL;
> > 
> > Allocating zero size arrays is a totally valid thing the kernel and it
> > doesn't cause a problem unless there are other existing serious bugs in
> > the code.  In this case instances == 0 is fine.
> > 
> Sorry, got a bit confused - is it fine to be in the code, or the 0
> value is valid, and shouldn't be checked for? The idea behind this
> change was not the allocation of zero size array, but the
> use of the module with 0 instances.

The changelog specifically mentioned a ZERO_SIZE_ARRAY.  If you had
said, "It doesn't make sense to load a module with 0 instances" then I
would have allowed the patch.  I don't care if you make this change or
not, but the changelog had wrong motivation.

regards,
dan carpenter

  reply	other threads:[~2015-05-28  6:59 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-26 22:19 [PATCH 1/2] staging: iio_simple_dummy: fix init Vladimirs Ambrosovs
2015-05-26 22:19 ` [PATCH 2/2] staging: iio_simple_dummy: zero check param Vladimirs Ambrosovs
2015-05-27  8:25   ` Dan Carpenter
2015-05-27 22:12     ` Vladimirs Ambrosovs
2015-05-28  6:59       ` Dan Carpenter [this message]
2015-05-29 19:38         ` Vladimirs Ambrosovs
2015-05-27  6:21 ` [PATCH 1/2] staging: iio_simple_dummy: fix init Daniel Baluta
2015-05-27 17:24   ` Vladimirs Ambrosovs
2015-05-27 17:29     ` Dan Carpenter
2015-05-28  5:31       ` Daniel Baluta
2015-05-27  8:23 ` Dan Carpenter

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=20150528065934.GU11588@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=driverdev-devel@linuxdriverproject.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    --cc=rodriguez.twister@gmail.com \
    /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).