Skip to contentSkip to conversation

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

PATCH Superseded Salah Triki 4 participants 4 messages Aug 7, 2025 – Aug 10, 2025 IIO

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

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

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

dev_info() has been dropped as it was considered noisy.

Also switch to gpiod_set_value_cansleep(), which is safe to use in sleepable contexts like probe.

---
Changes in v2:
- Use IS_ERR() instead of IS_ERR_OR_NULL()
- Drop dev_info()
- Use gpiod_set_value_cansleep()
- Improve commit title and message

 drivers/iio/pressure/bmp280-core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/iio/pressure/bmp280-core.c +4 -4
index 74505c9ec1a0..be6c981a4cc7 100644
@@ -3213,11 +3213,11 @@ 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(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);
-	}
+	gpiod_set_value_cansleep(gpiod, 0);
 
 	data->regmap = regmap;
 
Signature · 1 line
2.43.0
reviewer Reviewed-by on v2 1/1
#1 lore raw
Quoted 25 lines · Salah Triki

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

dev_info() has been dropped as it was considered noisy.

Also switch to gpiod_set_value_cansleep(), which is safe to use in sleepable contexts like probe.

---
Changes in v2:
- Use IS_ERR() instead of IS_ERR_OR_NULL()
- Drop dev_info()
- Use gpiod_set_value_cansleep()
- Improve commit title and message

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

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

Quoted 5 lines
drivers/iio/pressure/bmp280-core.c +2 -0
@@ -3213,11 +3213,11 @@ 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(gpiod))
+		return dev_err_probe(dev, PTR_ERR(gpiod), "failed to get GPIO\n");

Could be slightly better if the error message said "reset GPIO".

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

Quoted 10 lines
drivers/iio/pressure/bmp280-core.c +2 -4
+
 	/* Deassert the signal */
-	if (gpiod) {
-		dev_info(dev, "release reset\n");
-		gpiod_set_value(gpiod, 0);
-	}
+	gpiod_set_value_cansleep(gpiod, 0);
 
 	data->regmap = regmap;
 

In any case...

#2 lore raw
In reply to Salah Triki
Quoted 9 lines · Salah Triki

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

dev_info() has been dropped as it was considered noisy.

Also switch to gpiod_set_value_cansleep(), which is safe to use in sleepable contexts like probe.

'Also' automatically means: Please split to a separate patch.

You may drop dev_info() in the patch which converts to _cansleep, though. Ordering of the patch should be based on the least noise and churn between them.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw
In reply to Salah Triki
Quoted 3 lines

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

How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.16#n145

Quoted 2 lines

Also switch to gpiod_set_value_cansleep(), which is safe to use in sleepable contexts like probe.

Would it be helpful to provide desirable changes by separate update steps?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.16#n81

Regards,
Markus