* [PATCH] [BUGFIX] iio: ms65611_core: Fixes dereferencing regulator pointer
@ 2016-10-14 13:43 Crt Mori
2016-10-15 13:56 ` Jonathan Cameron
0 siblings, 1 reply; 2+ messages in thread
From: Crt Mori @ 2016-10-14 13:43 UTC (permalink / raw)
To: linux-iio, Jonathan Cameron
Cc: Lars-Peter Clausen, Dan Carpenter, Hartmut Knaack,
Peter Meerwald-Stadler, Linus Walleij, Crt Mori
Change in handling of the regulator description means that static
checkers correctly assume we could be using dereferenced pointer to the
regulator. In reality we will never get the -ENODEV error, as current
behavior flow does not predict it, because:
If the device tree or board file does not define suitable regulators for
the component, it will be substituted by a dummy regulator, or, if
regulators are disabled altogether, by stubs.
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Suggested-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Crt Mori <cmo@melexis.com>
---
drivers/iio/pressure/ms5611_core.c | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/drivers/iio/pressure/ms5611_core.c b/drivers/iio/pressure/ms5611_core.c
index a74ed1f..6bd53e7 100644
--- a/drivers/iio/pressure/ms5611_core.c
+++ b/drivers/iio/pressure/ms5611_core.c
@@ -392,17 +392,14 @@ static int ms5611_init(struct iio_dev *indio_dev)
/* Enable attached regulator if any. */
st->vdd = devm_regulator_get(indio_dev->dev.parent, "vdd");
- if (!IS_ERR(st->vdd)) {
- ret = regulator_enable(st->vdd);
- if (ret) {
- dev_err(indio_dev->dev.parent,
- "failed to enable Vdd supply: %d\n", ret);
- return ret;
- }
- } else {
- ret = PTR_ERR(st->vdd);
- if (ret != -ENODEV)
- return ret;
+ if (IS_ERR(st->vdd))
+ return PTR_ERR(st->vdd);
+
+ ret = regulator_enable(st->vdd);
+ if (ret) {
+ dev_err(indio_dev->dev.parent,
+ "failed to enable Vdd supply: %d\n", ret);
+ return ret;
}
ret = ms5611_reset(indio_dev);
--
2.10.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] [BUGFIX] iio: ms65611_core: Fixes dereferencing regulator pointer
2016-10-14 13:43 [PATCH] [BUGFIX] iio: ms65611_core: Fixes dereferencing regulator pointer Crt Mori
@ 2016-10-15 13:56 ` Jonathan Cameron
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2016-10-15 13:56 UTC (permalink / raw)
To: Crt Mori, linux-iio
Cc: Lars-Peter Clausen, Dan Carpenter, Hartmut Knaack,
Peter Meerwald-Stadler, Linus Walleij
On 14/10/16 14:43, Crt Mori wrote:
> Change in handling of the regulator description means that static
> checkers correctly assume we could be using dereferenced pointer to the
> regulator. In reality we will never get the -ENODEV error, as current
> behavior flow does not predict it, because:
> If the device tree or board file does not define suitable regulators for
> the component, it will be substituted by a dummy regulator, or, if
> regulators are disabled altogether, by stubs.
>
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Suggested-by: Lars-Peter Clausen <lars@metafoo.de>
> Signed-off-by: Crt Mori <cmo@melexis.com>
Applied to the togreg branch of iio.git and pushed out as testing for the
autobuilders to play with it.
Thanks,
Jonathan
> ---
> drivers/iio/pressure/ms5611_core.c | 19 ++++++++-----------
> 1 file changed, 8 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/iio/pressure/ms5611_core.c b/drivers/iio/pressure/ms5611_core.c
> index a74ed1f..6bd53e7 100644
> --- a/drivers/iio/pressure/ms5611_core.c
> +++ b/drivers/iio/pressure/ms5611_core.c
> @@ -392,17 +392,14 @@ static int ms5611_init(struct iio_dev *indio_dev)
>
> /* Enable attached regulator if any. */
> st->vdd = devm_regulator_get(indio_dev->dev.parent, "vdd");
> - if (!IS_ERR(st->vdd)) {
> - ret = regulator_enable(st->vdd);
> - if (ret) {
> - dev_err(indio_dev->dev.parent,
> - "failed to enable Vdd supply: %d\n", ret);
> - return ret;
> - }
> - } else {
> - ret = PTR_ERR(st->vdd);
> - if (ret != -ENODEV)
> - return ret;
> + if (IS_ERR(st->vdd))
> + return PTR_ERR(st->vdd);
> +
> + ret = regulator_enable(st->vdd);
> + if (ret) {
> + dev_err(indio_dev->dev.parent,
> + "failed to enable Vdd supply: %d\n", ret);
> + return ret;
> }
>
> ret = ms5611_reset(indio_dev);
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-10-15 13:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-14 13:43 [PATCH] [BUGFIX] iio: ms65611_core: Fixes dereferencing regulator pointer Crt Mori
2016-10-15 13:56 ` Jonathan Cameron
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).