* [PATCH] iio: pressure: bmp280: Use IS_ERR_OR_NULL() in bmp280_common_probe()
@ 2025-08-07 0:52 Salah Triki
2025-08-07 1:24 ` David Lechner
0 siblings, 1 reply; 3+ messages in thread
From: Salah Triki @ 2025-08-07 0:52 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
linux-iio, linux-kernel
Cc: 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.
Signed-off-by: Salah Triki <salah.triki@gmail.com>
---
drivers/iio/pressure/bmp280-core.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
index 74505c9ec1a0..2ac0188d2857 100644
--- a/drivers/iio/pressure/bmp280-core.c
+++ b/drivers/iio/pressure/bmp280-core.c
@@ -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;
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: pressure: bmp280: Use IS_ERR_OR_NULL() in bmp280_common_probe()
2025-08-07 0:52 [PATCH] iio: pressure: bmp280: Use IS_ERR_OR_NULL() in bmp280_common_probe() Salah Triki
@ 2025-08-07 1:24 ` David Lechner
2025-08-07 20:36 ` Andy Shevchenko
0 siblings, 1 reply; 3+ messages in thread
From: David Lechner @ 2025-08-07 1:24 UTC (permalink / raw)
To: Salah Triki, Jonathan Cameron, Nuno Sá, Andy Shevchenko,
linux-iio, linux-kernel
On 8/6/25 7:52 PM, Salah Triki wrote:
> `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.
>
> Signed-off-by: Salah Triki <salah.triki@gmail.com>
> ---
> drivers/iio/pressure/bmp280-core.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
> index 74505c9ec1a0..2ac0188d2857 100644
> --- a/drivers/iio/pressure/bmp280-core.c
> +++ b/drivers/iio/pressure/bmp280-core.c
> @@ -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.
> + 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.
> + 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.
>
> data->regmap = regmap;
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: pressure: bmp280: Use IS_ERR_OR_NULL() in bmp280_common_probe()
2025-08-07 1:24 ` David Lechner
@ 2025-08-07 20:36 ` Andy Shevchenko
0 siblings, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2025-08-07 20:36 UTC (permalink / raw)
To: David Lechner
Cc: Salah Triki, Jonathan Cameron, Nuno Sá, Andy Shevchenko,
linux-iio, linux-kernel
On Thu, Aug 7, 2025 at 3:24 AM David Lechner <dlechner@baylibre.com> wrote:
> On 8/6/25 7:52 PM, Salah Triki wrote:
...
All what David said I agree with.
> 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.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-08-07 20:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-07 0:52 [PATCH] iio: pressure: bmp280: Use IS_ERR_OR_NULL() in bmp280_common_probe() Salah Triki
2025-08-07 1:24 ` David Lechner
2025-08-07 20:36 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).