Linux IIO development
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: Crt Mori <cmo@melexis.com>, Dan Carpenter <dan.carpenter@oracle.com>
Cc: Hartmut Knaack <knaack.h@gmx.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	Linux Iio <linux-iio@vger.kernel.org>
Subject: Re: [bug report] iio: fetch and enable regulators unconditionally
Date: Fri, 14 Oct 2016 11:01:27 +0200	[thread overview]
Message-ID: <27ebc18e-e99e-d4dc-1272-7b16d5231a79@metafoo.de> (raw)
In-Reply-To: <CAKv63uskg4u6p-rH=Vt7JqmAj-VpRSfJUcv1j0SWHdd=yafxFw@mail.gmail.com>

On 10/13/2016 10:25 AM, Crt Mori wrote:
> Hello Dan,
> 
> On 12 October 2016 at 08:07, Dan Carpenter <dan.carpenter@oracle.com> wrote:
>> Hello Crt Mori,
>>
>> The patch 67516074884b: "iio: fetch and enable regulators
>> unconditionally" from Sep 5, 2016, leads to the following static
>> checker warning:
>>
>>         drivers/iio/pressure/ms5611_core.c:419 ms5611_init()
>>         error: 'st->vdd' dereferencing possible ERR_PTR()
>>
>> drivers/iio/pressure/ms5611_core.c
>>    388  static int ms5611_init(struct iio_dev *indio_dev)
>>    389  {
>>    390          int ret;
>>    391          struct ms5611_state *st = iio_priv(indio_dev);
>>    392
>>    393          /* Enable attached regulator if any. */
>>    394          st->vdd = devm_regulator_get(indio_dev->dev.parent, "vdd");
>>    395          if (!IS_ERR(st->vdd)) {
>>    396                  ret = regulator_enable(st->vdd);
>>    397                  if (ret) {
>>    398                          dev_err(indio_dev->dev.parent,
>>    399                                  "failed to enable Vdd supply: %d\n", ret);
>>    400                          return ret;
>>    401                  }
>>    402          } else {
>>    403                  ret = PTR_ERR(st->vdd);
>>    404                  if (ret != -ENODEV)
>>    405                          return ret;
>>
>> You probably want to update this chunk as well?  Otherwise static
>> checkers think we're dereferencing -ENODEV.
> 
> Can you explain a bit more why they would think of it like that and
> what would better proposal be like?
> 
> ret is a return value and it is st->vdd pointer is checked for error
> before we deduct error information out, so I do not see where
> dereferencing takes part?

The thing is, if PTR_ERR(st->vdd) is -ENODEV, we do not return an error and
just continue in the probe function. And then if one of the cleanup
functions is called st->vdd is passed to regulator_disable() which will
crash if it is passed -ENODEV instead of a valid pointer.

I think the ENODEV check should be dropped and the whole thing should be
turned into

if (IS_ERR(st->vdd))
	retrurn PTR_ERR(st->vdd))

ret = regulator_enable()
...

This is the behavior that we expect for normal supply regulators.


  reply	other threads:[~2016-10-14  9:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-12  6:07 [bug report] iio: fetch and enable regulators unconditionally Dan Carpenter
2016-10-13  8:25 ` Crt Mori
2016-10-14  9:01   ` Lars-Peter Clausen [this message]
2016-10-14 11:17     ` Crt Mori
2016-10-14 13:10       ` Linus Walleij

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=27ebc18e-e99e-d4dc-1272-7b16d5231a79@metafoo.de \
    --to=lars@metafoo.de \
    --cc=cmo@melexis.com \
    --cc=dan.carpenter@oracle.com \
    --cc=knaack.h@gmx.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=pmeerw@pmeerw.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