public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
From: Viktor Rosendahl <Viktor.Rosendahl@nokia.com>
To: ext Felipe Balbi <me@felipebalbi.com>
Cc: linux-omap@vger.kernel.org
Subject: Re: [PATCH 1/1] twl4030-madc: Fix arbitrarily initialized function pointer
Date: Thu, 03 Jul 2008 18:26:17 +0300	[thread overview]
Message-ID: <1215098777.11098.46.camel@viktor.research.nokia.com> (raw)
In-Reply-To: <f30014d3264cbcef10a9f0342fce7ac2@felipebalbi.com>


> 
> > +		req.func_cb	= NULL;
> 
> maybe below is a better patch:
> 
> diff --git a/drivers/i2c/chips/twl4030-madc.c
> b/drivers/i2c/chips/twl4030-madc.c
> index 72b126b..6d8915e 100644
> --- a/drivers/i2c/chips/twl4030-madc.c
> +++ b/drivers/i2c/chips/twl4030-madc.c
> @@ -360,7 +360,7 @@ static int twl4030_madc_ioctl(struct inode *inode,
> struct file *filp,
>  
>         switch (cmd) {
>         case TWL4030_MADC_IOCX_ADC_RAW_READ: {
> -               struct twl4030_madc_request req;
> +               static struct twl4030_madc_request req;
>                 if (par.channel >= TWL4030_MADC_MAX_CHANNELS)
>                         return -EINVAL;

I don't like this idea because:

- It's fragile. This struct, which is not a const, gets initialized only
once but we are still passing a pointer to it, expecting that a fairly
complex function will not modify it. This assertion is probably true
today but makes it easier for somebody to create a bug in the future.

- You introduce another shared datum and it is only protected by the BKL
in fs/ioctl.c:vfs_ioctl().

- I didn't see any argument why this variable should be static. Making
local variables static just to get cheap zero initialization is a weird
thing to do IMO.

best regards,

Viktor



  reply	other threads:[~2008-07-03 15:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-02 13:36 [PATCH 0/1] twl4030-madc: Fix arbitrarily initialized function pointer Viktor Rosendahl
2008-07-02 13:36 ` [PATCH 1/1] " Viktor Rosendahl
2008-07-02 13:54   ` Felipe Balbi
2008-07-03 15:26     ` Viktor Rosendahl [this message]
2008-08-04 14:31       ` Tony Lindgren

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=1215098777.11098.46.camel@viktor.research.nokia.com \
    --to=viktor.rosendahl@nokia.com \
    --cc=linux-omap@vger.kernel.org \
    --cc=me@felipebalbi.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