Skip to contentSkip to conversation

iio: pressure: bmp280: Use IS_ERR_OR_NULL() in bmp280_common_probe()

PATCH Superseded Salah Triki 3 participants 3 messages Aug 7, 2025 IIO

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: pressure: bmp280: Use IS_ERR_OR_NULL() in bmp280_common_probe()

devm_gpiod_get_optional() may return non-NULL error pointer on failure. Check its return value using IS_ERR_OR_NULL() and propagate the error if necessary.

---
 drivers/iio/pressure/bmp280-core.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/iio/pressure/bmp280-core.c +6 -4
index 74505c9ec1a0..2ac0188d2857 100644
@@ -3213,11 +3213,13 @@ int bmp280_common_probe(struct device *dev,
 
 	/* Bring chip out of reset if there is an assigned GPIO line */
 	gpiod = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
+
+	if (IS_ERR_OR_NULL(gpiod))
+		return dev_err_probe(dev, PTR_ERR(gpiod), "failed to get GPIO\n");
+
 	/* Deassert the signal */
-	if (gpiod) {
-		dev_info(dev, "release reset\n");
-		gpiod_set_value(gpiod, 0);
-	}
+	dev_info(dev, "release reset\n");
+	gpiod_set_value(gpiod, 0);
 
 	data->regmap = regmap;
 
Signature · 1 line
2.43.0
reviewer
#1 lore raw
Quoted 14 lines · Salah Triki

devm_gpiod_get_optional() may return non-NULL error pointer on failure. Check its return value using IS_ERR_OR_NULL() and propagate the error if necessary.

---
 drivers/iio/pressure/bmp280-core.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/iio/pressure/bmp280-core.c +0 -0
index 74505c9ec1a0..2ac0188d2857 100644

drivers/iio/pressure/bmp280-core.c int bmp280_common_probe(struct device *dev, · line 3216

Quoted 4 lines
drivers/iio/pressure/bmp280-core.c +1 -0
@@ -3213,11 +3213,13 @@ int bmp280_common_probe(struct device *dev,
 
 	/* Bring chip out of reset if there is an assigned GPIO line */
 	gpiod = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
+

No blank line here.

drivers/iio/pressure/bmp280-core.c int bmp280_common_probe(struct device *dev, · line 3217

Quoted 1 line
drivers/iio/pressure/bmp280-core.c +1 -0
+	if (IS_ERR_OR_NULL(gpiod))

This needs to be IS_ERR(). NULL is not an error and we cant return early here because there is more to do in the probe function.

drivers/iio/pressure/bmp280-core.c int bmp280_common_probe(struct device *dev, · line 3222

Quoted 9 lines
drivers/iio/pressure/bmp280-core.c +4 -4
+		return dev_err_probe(dev, PTR_ERR(gpiod), "failed to get GPIO\n");
+
 	/* Deassert the signal */
-	if (gpiod) {
-		dev_info(dev, "release reset\n");
-		gpiod_set_value(gpiod, 0);
-	}
+	dev_info(dev, "release reset\n");
+	gpiod_set_value(gpiod, 0);

If we drop the if here, we should also drop the dev_info(). gpiod_set_value() handles NULL gpiod value so that is fine, but the message is just noise.

Also, gpiod_set_value_cansleep() would be more appropriate. This is not an atomic context.

Quoted 3 lines
drivers/iio/pressure/bmp280-core.c +0 -0
 	data->regmap = regmap;
 
#2 lore raw
Quoted 1 line · David Lechner

On 8/6/25 7:52 PM, Salah Triki wrote:

...

All what David said I agree with.

Quoted 2 lines

Also, gpiod_set_value_cansleep() would be more
appropriate. This is not an atomic context.

Just note that the original code doesn't have it, so it may be done in a separate patch.

Signature · 2 lines
With Best Regards,
Andy Shevchenko