Skip to contentSkip to conversation

iio: pressure: bmp280: GPIO error handling and cleanup

PATCH Superseded Salah Triki 3 participants 5 messages Aug 18, 2025 – Aug 20, 2025 IIO

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover iio: pressure: bmp280: GPIO error handling and cleanup

Hi all,

This patch series improves the GPIO handling in the bmp280 driver.

Changes in v3:
- Split into two separate patches, as suggested by Andy Shevchenko.
- Improve the error message to "failed to get reset GPIO", as suggested by David Lechner.
- Add Fixes and Cc tags where appropriate, as suggested by Markus Elfring.

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

Salah Triki (2):
iio: pressure: bmp280: Use IS_ERR() in bmp280_common_probe()
iio: pressure: bmp280: Use gpiod_set_value_cansleep()

 drivers/iio/pressure/bmp280-core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v3 1/2 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.

Fixes df6e71256c84 ("iio: pressure: bmp280: Explicitly mark GPIO optional")
Cc David Lechner <[email protected]>
Cc Jonathan Cameron <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Nuno Sá <[email protected]>
Cc Markus Elfring <[email protected]>
---
 drivers/iio/pressure/bmp280-core.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/iio/pressure/bmp280-core.c +5 -4
index 74505c9ec1a0..6cdc8ed53520 100644
@@ -3213,11 +3213,12 @@ 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 reset 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
#2 lore raw

PATCH v3 2/2 iio: pressure: bmp280: Use gpiod_set_value_cansleep()

In reply to Salah Triki

Switch to gpiod_set_value_cansleep(), which is safe to use in sleepable contexts like the driver probe function.

The dev_info() call has been removed as it was considered noisy and is not necessary for normal driver operation.

---
 drivers/iio/pressure/bmp280-core.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/iio/pressure/bmp280-core.c +1 -2
index 6cdc8ed53520..656f6189c84c 100644
@@ -3217,8 +3217,7 @@ int bmp280_common_probe(struct device *dev,
 		return dev_err_probe(dev, PTR_ERR(gpiod), "failed to get reset GPIO\n");
 
 	/* Deassert the signal */
-	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
#3 lore raw

Re: [PATCH v3 2/2] iio: pressure: bmp280: Use gpiod_set_value_cansleep()

Quoted 5 lines

Switch to gpiod_set_value_cansleep(), which is safe to use in sleepable contexts like the driver probe function.

The dev_info() call has been removed as it was considered noisy and is not necessary for normal driver operation.

Should such a change combination be reconsidered once more?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.17-rc1#n81

Regards,
Markus

#4 lore raw
In reply to Salah Triki
Quoted 3 lines · Salah Triki

Hi all,

This patch series improves the GPIO handling in the bmp280 driver.

Is this similar to what I just reviewed? I'm sorry I got lost. But if it's different, it needs to be amended in the same way.

Signature · 2 lines
With Best Regards,
Andy Shevchenko