summaryrefslogtreecommitdiff
path: root/drivers/staging/iio/frequency
diff options
context:
space:
mode:
authorEva Rachel Retuya <eraretuya@gmail.com>2016-11-01 01:04:31 +0800
committerJonathan Cameron <jic23@kernel.org>2016-11-05 16:17:14 +0000
commit3925ff0fcba71a27be14b19b01c0b67efbab0be9 (patch)
treec883307ec50eed96f53ad463a603d4445250860d /drivers/staging/iio/frequency
parentc834e1718aae6150936af718db9e483993d2c63f (diff)
staging: iio: rework regulator handling
Currently, the affected drivers ignore all errors from regulator_get(). The way it is now, it also breaks probe deferral (EPROBE_DEFER). The correct behavior is to propagate the error to the upper layers so they can handle it accordingly. Rework the regulator handling so that it matches the standard behavior. If the specific design uses a static always-on regulator and does not explicitly specify it, regulator_get() will return the dummy regulator. The following semantic patch was used to apply the change: @r1@ expression reg, dev, en, volt; @@ reg = \(devm_regulator_get\|regulator_get\)(dev, ...); if ( - ! IS_ERR(reg)) + return PTR_ERR(reg); ( - { en = regulator_enable(reg); - if (en) return en; } + + en = regulator_enable(reg); + if (en) { + dev_err(dev, "Failed to enable specified supply\n"); + return en; } | + - { en = regulator_enable(reg); - if (en) return en; - volt = regulator_get_voltage(reg); } + en = regulator_enable(reg); + if (en) { + dev_err(dev, "Failed to enable specified supply\n"); + return en; + } + volt = regulator_get_voltage(reg); ) @r2@ expression arg; @@ - if (!IS_ERR(arg)) regulator_disable(arg); + regulator_disable(arg); Hand-edit the debugging prints with the supply name to become more specific. Suggested-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Eva Rachel Retuya <eraretuya@gmail.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/staging/iio/frequency')
-rw-r--r--drivers/staging/iio/frequency/ad9832.c17
-rw-r--r--drivers/staging/iio/frequency/ad9834.c17
2 files changed, 18 insertions, 16 deletions
diff --git a/drivers/staging/iio/frequency/ad9832.c b/drivers/staging/iio/frequency/ad9832.c
index 744c8ee9c5a6..7d8dc6cab720 100644
--- a/drivers/staging/iio/frequency/ad9832.c
+++ b/drivers/staging/iio/frequency/ad9832.c
@@ -213,10 +213,13 @@ static int ad9832_probe(struct spi_device *spi)
}
reg = devm_regulator_get(&spi->dev, "avdd");
- if (!IS_ERR(reg)) {
- ret = regulator_enable(reg);
- if (ret)
- return ret;
+ if (IS_ERR(reg))
+ return PTR_ERR(reg);
+
+ ret = regulator_enable(reg);
+ if (ret) {
+ dev_err(&spi->dev, "Failed to enable specified AVDD supply\n");
+ return ret;
}
indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
@@ -311,8 +314,7 @@ static int ad9832_probe(struct spi_device *spi)
return 0;
error_disable_reg:
- if (!IS_ERR(reg))
- regulator_disable(reg);
+ regulator_disable(reg);
return ret;
}
@@ -323,8 +325,7 @@ static int ad9832_remove(struct spi_device *spi)
struct ad9832_state *st = iio_priv(indio_dev);
iio_device_unregister(indio_dev);
- if (!IS_ERR(st->reg))
- regulator_disable(st->reg);
+ regulator_disable(st->reg);
return 0;
}
diff --git a/drivers/staging/iio/frequency/ad9834.c b/drivers/staging/iio/frequency/ad9834.c
index ca3cea68d8d7..19216af1dfc9 100644
--- a/drivers/staging/iio/frequency/ad9834.c
+++ b/drivers/staging/iio/frequency/ad9834.c
@@ -330,10 +330,13 @@ static int ad9834_probe(struct spi_device *spi)
}
reg = devm_regulator_get(&spi->dev, "avdd");
- if (!IS_ERR(reg)) {
- ret = regulator_enable(reg);
- if (ret)
- return ret;
+ if (IS_ERR(reg))
+ return PTR_ERR(reg);
+
+ ret = regulator_enable(reg);
+ if (ret) {
+ dev_err(&spi->dev, "Failed to enable specified AVDD supply\n");
+ return ret;
}
indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
@@ -416,8 +419,7 @@ static int ad9834_probe(struct spi_device *spi)
return 0;
error_disable_reg:
- if (!IS_ERR(reg))
- regulator_disable(reg);
+ regulator_disable(reg);
return ret;
}
@@ -428,8 +430,7 @@ static int ad9834_remove(struct spi_device *spi)
struct ad9834_state *st = iio_priv(indio_dev);
iio_device_unregister(indio_dev);
- if (!IS_ERR(st->reg))
- regulator_disable(st->reg);
+ regulator_disable(st->reg);
return 0;
}