Skip to contentSkip to conversation

iio: dac: ad5380: Fix probe failure when no external reference is supplied

PATCH In review Paweł Grudziński 3 participants 3 messages Jul 19, 2016 – Jul 24, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 iio: dac: ad5380: Fix probe failure when no external reference is supplied

From: Pawel Grudzinski <[email protected]>

Driver fails to load when there is no external Vref regulator defined, leaving no way to use internal reference. ad5380_probe function tries to obtain regulator with demv_regulator_get and checks for error, in which case it would use internal reference. Even without "Vref" regulator defined devm_regulator_get returns dummy regulator which makes function omit use of internal reference and causes failure on regulator_get_voltage.

Replace demv_regulator_get with demv_regulator_get_optional, which returns error instead of dummy regulator if it does not find one which is specified by the caller to make ad5380_probe configure internal reference when no "Vref" regulator is supplied.

Initialize internal regulator only if returned error is ENODEV, otherwise propagate the error to the caller of probe.

---
Changes in v2:
- Add error type checking to enable internal reference only on ENODEV and return any other error to the caller.

 drivers/iio/dac/ad5380.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/iio/dac/ad5380.c +8 -3
index 97d2c51..144cfdc 100644
@@ -401,7 +401,7 @@ static int ad5380_probe(struct device *dev, struct regmap *regmap,
 	if (st->chip_info->int_vref == 2500)
 		ctrl |= AD5380_CTRL_INT_VREF_2V5;
 
-	st->vref_reg = devm_regulator_get(dev, "vref");
+	st->vref_reg = devm_regulator_get_optional(dev, "vref");
 	if (!IS_ERR(st->vref_reg)) {
 		ret = regulator_enable(st->vref_reg);
 		if (ret) {
@@ -416,8 +416,13 @@ static int ad5380_probe(struct device *dev, struct regmap *regmap,
 
 		st->vref = ret / 1000;
 	} else {
-		st->vref = st->chip_info->int_vref;
-		ctrl |= AD5380_CTRL_INT_VREF_EN;
+		if (PTR_ERR(st->vref_reg) == -ENODEV) {
+			st->vref = st->chip_info->int_vref;
+			ctrl |= AD5380_CTRL_INT_VREF_EN;
+		} else {
+			ret = st->vref_reg;
+			goto error_free_reg;
+		}
 	}
 
 	ret = regmap_write(st->regmap, AD5380_REG_SF_CTRL, ctrl);
Signature · 1 line
2.8.0
#1 lore raw
reproduce:

Hi,

[auto build test WARNING on iio/togreg]
[also build test WARNING on v4.7-rc7 next-20160722]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Pawe-Grudzi-ski/iio-dac-ad5380-Fix-probe-failure-when-no-external-reference-is-supplied/20160723-221946
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
config: x86_64-allmodconfig (attached as .config)
compiler: gcc-6 (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All warnings (new ones prefixed by >>):

drivers/iio/dac/ad5380.c: In function 'ad5380_probe':

>> drivers/iio/dac/ad5380.c:423:8: warning: assignment makes integer from pointer without a cast [-Wint-conversion]
       ret = st->vref_reg;
           ^

vim +423 drivers/iio/dac/ad5380.c

407 if (ret) {
408 dev_err(dev, "Failed to enable vref regulators: %d\n",
409 ret);
410 goto error_free_reg;
411 }
412
413 ret = regulator_get_voltage(st->vref_reg);
414 if (ret < 0)
415 goto error_disable_reg;
416
417 st->vref = ret / 1000;
418 } else {
419 if (PTR_ERR(st->vref_reg) == -ENODEV) {
420 st->vref = st->chip_info->int_vref;
421 ctrl |= AD5380_CTRL_INT_VREF_EN;
422 } else {

 > 423				ret = st->vref_reg;

424 goto error_free_reg;
425 }
426 }
427
428 ret = regmap_write(st->regmap, AD5380_REG_SF_CTRL, ctrl);
429 if (ret) {
430 dev_err(dev, "Failed to write to device: %d\n", ret);
431 goto error_disable_reg;

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

maintainer
#2 lore raw
In reply to Paweł Grudziński
Quoted 40 lines · Paweł Grudziński

From: Pawel Grudzinski <[email protected]>

Driver fails to load when there is no external Vref regulator defined, leaving no way to use internal reference. ad5380_probe function tries to obtain regulator with demv_regulator_get and checks for error, in which case it would use internal reference. Even without "Vref" regulator defined devm_regulator_get returns dummy regulator which makes function omit use of internal reference and causes failure on regulator_get_voltage.

Replace demv_regulator_get with demv_regulator_get_optional, which returns error instead of dummy regulator if it does not find one which is specified by the caller to make ad5380_probe configure internal reference when no "Vref" regulator is supplied.

Initialize internal regulator only if returned error is ENODEV, otherwise propagate the error to the caller of probe.

---
Changes in v2:
- Add error type checking to enable internal reference only on ENODEV and return any other error to the caller.

 drivers/iio/dac/ad5380.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/iio/dac/ad5380.c +1 -1
index 97d2c51..144cfdc 100644
@@ -401,7 +401,7 @@ static int ad5380_probe(struct device *dev, struct regmap *regmap,
 	if (st->chip_info->int_vref == 2500)
 		ctrl |= AD5380_CTRL_INT_VREF_2V5;
 
-	st->vref_reg = devm_regulator_get(dev, "vref");
+	st->vref_reg = devm_regulator_get_optional(dev, "vref");
 	if (!IS_ERR(st->vref_reg)) {
 		ret = regulator_enable(st->vref_reg);
 		if (ret) {

drivers/iio/dac/ad5380.c static int ad5380_probe(struct device *dev, struct regmap *regmap, · line 423

Quoted 10 lines
drivers/iio/dac/ad5380.c +5 -2
@@ -416,8 +416,13 @@ static int ad5380_probe(struct device *dev, struct regmap *regmap,
 
 		st->vref = ret / 1000;
 	} else {
-		st->vref = st->chip_info->int_vref;
-		ctrl |= AD5380_CTRL_INT_VREF_EN;
+		if (PTR_ERR(st->vref_reg) == -ENODEV) {
+			st->vref = st->chip_info->int_vref;
+			ctrl |= AD5380_CTRL_INT_VREF_EN;
+		} else {
+			ret = st->vref_reg;

Autobuilder picked it up an issue. This should be ret = PTR_ERR(st->vref_reg) I think?

Jonathan

Quoted 6 lines
drivers/iio/dac/ad5380.c +2 -0
+			goto error_free_reg;
+		}
 	}
 
 	ret = regmap_write(st->regmap, AD5380_REG_SF_CTRL, ctrl);