diff mbox series

[v1,3/3] i2c: i801: Refactor mux code since platform_device_unregister() is NULL aware

Message ID 20201228200618.58716-3-andriy.shevchenko@linux.intel.com
State New
Headers show
Series [v1,1/3] gpiolib: Follow usual pattern for gpiod_remove_lookup_table() call | expand

Commit Message

Andy Shevchenko Dec. 28, 2020, 8:06 p.m. UTC
platform_device_unregister() is NULL-aware and thus doesn't required a
duplication check in i801_del_mux(). Besides that it's also error pointer
aware, and we may drop unneeded assignment in i801_add_mux() followed by
conversion to PTR_ERR_OR_ZERO() for the returned value.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-i801.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

Comments

Jean Delvare Jan. 6, 2021, 4:03 p.m. UTC | #1
On Mon, 28 Dec 2020 22:06:18 +0200, Andy Shevchenko wrote:
> platform_device_unregister() is NULL-aware and thus doesn't required a

> duplication check in i801_del_mux(). Besides that it's also error pointer

> aware, and we may drop unneeded assignment in i801_add_mux() followed by

> conversion to PTR_ERR_OR_ZERO() for the returned value.

> 

> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> ---

>  drivers/i2c/busses/i2c-i801.c | 10 +++-------

>  1 file changed, 3 insertions(+), 7 deletions(-)

> 

> diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c

> index 7c2569a18f8c..1400a8716388 100644

> --- a/drivers/i2c/busses/i2c-i801.c

> +++ b/drivers/i2c/busses/i2c-i801.c

> @@ -1433,7 +1433,7 @@ static int i801_add_mux(struct i801_priv *priv)

>  	const struct i801_mux_config *mux_config;

>  	struct i2c_mux_gpio_platform_data gpio_data;

>  	struct gpiod_lookup_table *lookup;

> -	int err, i;

> +	int i;

>  

>  	if (!priv->mux_drvdata)

>  		return 0;

> @@ -1473,20 +1473,16 @@ static int i801_add_mux(struct i801_priv *priv)

>  				PLATFORM_DEVID_NONE, &gpio_data,

>  				sizeof(struct i2c_mux_gpio_platform_data));

>  	if (IS_ERR(priv->mux_pdev)) {

> -		err = PTR_ERR(priv->mux_pdev);

>  		gpiod_remove_lookup_table(lookup);

> -		priv->mux_pdev = NULL;

>  		dev_err(dev, "Failed to register i2c-mux-gpio device\n");

> -		return err;

>  	}

>  

> -	return 0;

> +	return PTR_ERR_OR_ZERO(priv->mux_pdev);

>  }

>  

>  static void i801_del_mux(struct i801_priv *priv)

>  {

> -	if (priv->mux_pdev)

> -		platform_device_unregister(priv->mux_pdev);

> +	platform_device_unregister(priv->mux_pdev);

>  	gpiod_remove_lookup_table(priv->lookup);

>  }

>  


Reviewed-by: Jean Delvare <jdelvare@suse.de>


-- 
Jean Delvare
SUSE L3 Support
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 7c2569a18f8c..1400a8716388 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -1433,7 +1433,7 @@  static int i801_add_mux(struct i801_priv *priv)
 	const struct i801_mux_config *mux_config;
 	struct i2c_mux_gpio_platform_data gpio_data;
 	struct gpiod_lookup_table *lookup;
-	int err, i;
+	int i;
 
 	if (!priv->mux_drvdata)
 		return 0;
@@ -1473,20 +1473,16 @@  static int i801_add_mux(struct i801_priv *priv)
 				PLATFORM_DEVID_NONE, &gpio_data,
 				sizeof(struct i2c_mux_gpio_platform_data));
 	if (IS_ERR(priv->mux_pdev)) {
-		err = PTR_ERR(priv->mux_pdev);
 		gpiod_remove_lookup_table(lookup);
-		priv->mux_pdev = NULL;
 		dev_err(dev, "Failed to register i2c-mux-gpio device\n");
-		return err;
 	}
 
-	return 0;
+	return PTR_ERR_OR_ZERO(priv->mux_pdev);
 }
 
 static void i801_del_mux(struct i801_priv *priv)
 {
-	if (priv->mux_pdev)
-		platform_device_unregister(priv->mux_pdev);
+	platform_device_unregister(priv->mux_pdev);
 	gpiod_remove_lookup_table(priv->lookup);
 }