Skip to contentSkip to conversation

iio: amplifiers: ad8366: Change devm_gpiod_get() to optional and add the missed check

PATCH In review Chuhong Yuan 3 participants 3 messages Jun 3, 2020 – Jun 6, 2020

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

PATCH v3 1/1 iio: amplifiers: ad8366: Change devm_gpiod_get() to optional and add the missed check

Since if there is no GPIO, nothing happens, replace devm_gpiod_get() with devm_gpiod_get_optional().
Also add IS_ERR() to fix the missing-check bug.

Fixes cee211f4e5a0 ("iio: amplifiers: ad8366: Add support for the ADA4961 DGA")

---
Changes in v3:
- Change devm_gpiod_get() to optional.
- Modify description.

 drivers/iio/amplifiers/ad8366.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/iio/amplifiers/ad8366.c +5 -1
index 62167b87caea..8819e8997f76 100644
@@ -262,8 +262,12 @@ static int ad8366_probe(struct spi_device *spi)
 	case ID_ADA4961:
 	case ID_ADL5240:
 	case ID_HMC1119:
-		st->reset_gpio = devm_gpiod_get(&spi->dev, "reset",
+		st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset",
 			GPIOD_OUT_HIGH);
+		if (IS_ERR(st->reset_gpio)) {
+			ret = PTR_ERR(st->reset_gpio);
+			goto error_disable_reg;
+		}
 		indio_dev->channels = ada4961_channels;
 		indio_dev->num_channels = ARRAY_SIZE(ada4961_channels);
 		break;
Signature · 1 line
2.26.2
Acked-by on v3 1/1
#1 lore raw
Quoted 4 lines · Chuhong Yuan

Since if there is no GPIO, nothing happens, replace devm_gpiod_get() with devm_gpiod_get_optional().
Also add IS_ERR() to fix the missing-check bug.

Quoted 29 lines
Fixes cee211f4e5a0 ("iio: amplifiers: ad8366: Add support for the ADA4961

DGA")

---
Changes in v3:
- Change devm_gpiod_get() to optional.
- Modify description.

 drivers/iio/amplifiers/ad8366.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/iio/amplifiers/ad8366.c +5 -1
index 62167b87caea..8819e8997f76 100644
@@ -262,8 +262,12 @@ static int ad8366_probe(struct spi_device *spi)
 	case ID_ADA4961:
 	case ID_ADL5240:
 	case ID_HMC1119:
-		st->reset_gpio = devm_gpiod_get(&spi->dev, "reset",
+		st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset",
 			GPIOD_OUT_HIGH);
+		if (IS_ERR(st->reset_gpio)) {
+			ret = PTR_ERR(st->reset_gpio);
+			goto error_disable_reg;
+		}
 		indio_dev->channels = ada4961_channels;
 		indio_dev->num_channels = ARRAY_SIZE(ada4961_channels);
 		break;
maintainer
#2 lore raw
Quoted 7 lines · Alexandru
Quoted 4 lines · Chuhong Yuan

Since if there is no GPIO, nothing happens, replace devm_gpiod_get() with devm_gpiod_get_optional().
Also add IS_ERR() to fix the missing-check bug.

Applied with layout tweaked a bit as per Markus' comment which made sense in this particular case.

I also tweaked the description to say "missing-check" warning given as we've established the failure to check for an error wasn't a problem as such. On that basis I thought about dropping the fixes tag, but it's 'sort' of a fix so I'll leave it there. Not sending this the fast path however as is not urgent (shout if you disagree!)

Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it.

Thanks,

Jonathan

Quoted 30 lines
Quoted 30 lines
Fixes cee211f4e5a0 ("iio: amplifiers: ad8366: Add support for the ADA4961

DGA")

---
Changes in v3:
- Change devm_gpiod_get() to optional.
- Modify description.

 drivers/iio/amplifiers/ad8366.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/iio/amplifiers/ad8366.c +5 -1
index 62167b87caea..8819e8997f76 100644
@@ -262,8 +262,12 @@ static int ad8366_probe(struct spi_device *spi)
 	case ID_ADA4961:
 	case ID_ADL5240:
 	case ID_HMC1119:
-		st->reset_gpio = devm_gpiod_get(&spi->dev, "reset",
+		st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset",
 			GPIOD_OUT_HIGH);
+		if (IS_ERR(st->reset_gpio)) {
+			ret = PTR_ERR(st->reset_gpio);
+			goto error_disable_reg;
+		}
 		indio_dev->channels = ada4961_channels;
 		indio_dev->num_channels = ARRAY_SIZE(ada4961_channels);
 		break;