[PATCH v1 4/5] w1: gpio: Remove duplicate NULL checks

Andy Shevchenko posted 5 patches 1 year, 9 months ago
[PATCH v1 4/5] w1: gpio: Remove duplicate NULL checks
Posted by Andy Shevchenko 1 year, 9 months ago
gpiod_set_value() is NULL-aware, no need to check that in the caller.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/w1/masters/w1-gpio.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/w1/masters/w1-gpio.c b/drivers/w1/masters/w1-gpio.c
index 3881f2eaed2f..8fd9fedd8c56 100644
--- a/drivers/w1/masters/w1-gpio.c
+++ b/drivers/w1/masters/w1-gpio.c
@@ -117,8 +117,7 @@ static int w1_gpio_probe(struct platform_device *pdev)
 	if (err)
 		return dev_err_probe(dev, err, "w1_add_master device failed\n");
 
-	if (ddata->pullup_gpiod)
-		gpiod_set_value(ddata->pullup_gpiod, 1);
+	gpiod_set_value(ddata->pullup_gpiod, 1);
 
 	platform_set_drvdata(pdev, master);
 
@@ -130,8 +129,7 @@ static void w1_gpio_remove(struct platform_device *pdev)
 	struct w1_bus_master *master = platform_get_drvdata(pdev);
 	struct w1_gpio_ddata *ddata = master->data;
 
-	if (ddata->pullup_gpiod)
-		gpiod_set_value(ddata->pullup_gpiod, 0);
+	gpiod_set_value(ddata->pullup_gpiod, 0);
 
 	w1_remove_master_device(master);
 }
-- 
2.43.0.rc1.1.gbec44491f096
Re: [PATCH v1 4/5] w1: gpio: Remove duplicate NULL checks
Posted by Uwe Kleine-König 1 year, 9 months ago
On Thu, Mar 07, 2024 at 04:35:50PM +0200, Andy Shevchenko wrote:
> gpiod_set_value() is NULL-aware, no need to check that in the caller.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/w1/masters/w1-gpio.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/w1/masters/w1-gpio.c b/drivers/w1/masters/w1-gpio.c
> index 3881f2eaed2f..8fd9fedd8c56 100644
> --- a/drivers/w1/masters/w1-gpio.c
> +++ b/drivers/w1/masters/w1-gpio.c
> @@ -117,8 +117,7 @@ static int w1_gpio_probe(struct platform_device *pdev)
>  	if (err)
>  		return dev_err_probe(dev, err, "w1_add_master device failed\n");
>  
> -	if (ddata->pullup_gpiod)
> -		gpiod_set_value(ddata->pullup_gpiod, 1);
> +	gpiod_set_value(ddata->pullup_gpiod, 1);
>  
>  	platform_set_drvdata(pdev, master);
>  
> @@ -130,8 +129,7 @@ static void w1_gpio_remove(struct platform_device *pdev)
>  	struct w1_bus_master *master = platform_get_drvdata(pdev);
>  	struct w1_gpio_ddata *ddata = master->data;
>  
> -	if (ddata->pullup_gpiod)
> -		gpiod_set_value(ddata->pullup_gpiod, 0);
> +	gpiod_set_value(ddata->pullup_gpiod, 0);

This also has the advantage to not have to know that NULL is the dummy
value returned by the gpiod_get_optional() family of functions.

Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |