linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] iio: pressure: bmp280: Use IS_ERR() in bmp280_common_probe()
@ 2025-08-07  2:25 Salah Triki
  2025-08-07 15:39 ` David Lechner
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Salah Triki @ 2025-08-07  2:25 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()` 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.

Signed-off-by: Salah Triki <salah.triki@gmail.com>
---
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(-)

diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
index 74505c9ec1a0..be6c981a4cc7 100644
--- a/drivers/iio/pressure/bmp280-core.c
+++ b/drivers/iio/pressure/bmp280-core.c
@@ -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;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] iio: pressure: bmp280: Use IS_ERR() in bmp280_common_probe()
  2025-08-07  2:25 [PATCH v2] iio: pressure: bmp280: Use IS_ERR() in bmp280_common_probe() Salah Triki
@ 2025-08-07 15:39 ` David Lechner
  2025-08-07 21:23 ` Andy Shevchenko
  2025-08-10  8:08 ` Markus Elfring
  2 siblings, 0 replies; 4+ messages in thread
From: David Lechner @ 2025-08-07 15:39 UTC (permalink / raw)
  To: Salah Triki, Jonathan Cameron, Nuno Sá, Andy Shevchenko,
	linux-iio, linux-kernel

On 8/6/25 9:25 PM, Salah Triki wrote:
> `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.
> 
> Signed-off-by: Salah Triki <salah.triki@gmail.com>
> ---
> 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(-)
> 
> diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
> index 74505c9ec1a0..be6c981a4cc7 100644
> --- a/drivers/iio/pressure/bmp280-core.c
> +++ b/drivers/iio/pressure/bmp280-core.c
> @@ -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".

> +
>  	/* 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...

Reviewed-by: David Lechner <dlechner@baylibre.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] iio: pressure: bmp280: Use IS_ERR() in bmp280_common_probe()
  2025-08-07  2:25 [PATCH v2] iio: pressure: bmp280: Use IS_ERR() in bmp280_common_probe() Salah Triki
  2025-08-07 15:39 ` David Lechner
@ 2025-08-07 21:23 ` Andy Shevchenko
  2025-08-10  8:08 ` Markus Elfring
  2 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2025-08-07 21:23 UTC (permalink / raw)
  To: Salah Triki
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	linux-iio, linux-kernel

On Thu, Aug 7, 2025 at 4:25 AM Salah Triki <salah.triki@gmail.com> wrote:
>
> `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.

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] iio: pressure: bmp280: Use IS_ERR() in bmp280_common_probe()
  2025-08-07  2:25 [PATCH v2] iio: pressure: bmp280: Use IS_ERR() in bmp280_common_probe() Salah Triki
  2025-08-07 15:39 ` David Lechner
  2025-08-07 21:23 ` Andy Shevchenko
@ 2025-08-10  8:08 ` Markus Elfring
  2 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2025-08-10  8:08 UTC (permalink / raw)
  To: Salah Triki, linux-iio
  Cc: LKML, Andy Shevchenko, David Lechner, Jonathan Cameron,
	Nuno Sá

> `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


> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-08-10  8:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-07  2:25 [PATCH v2] iio: pressure: bmp280: Use IS_ERR() in bmp280_common_probe() Salah Triki
2025-08-07 15:39 ` David Lechner
2025-08-07 21:23 ` Andy Shevchenko
2025-08-10  8:08 ` Markus Elfring

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).