linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/3] gpiolib: Follow usual pattern for gpiod_remove_lookup_table() call
@ 2020-12-28 20:06 Andy Shevchenko
  2020-12-28 20:06 ` [PATCH v1 2/3] i2c: i801: Drop duplicate NULL check in i801_del_mux() Andy Shevchenko
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Andy Shevchenko @ 2020-12-28 20:06 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, linux-gpio, Jean Delvare,
	Wolfram Sang, linux-i2c
  Cc: Andy Shevchenko

The usual pattern for the remove calls, like gpiod_remove_lookup_table(),
is to be NULL-aware, i.o.w. become a no-op whenever parameter is NULL.
Update gpiod_remove_lookup_table() call to follow this pattern.

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

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index b02cc2abd3b6..611d6ea82d75 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -3460,6 +3460,10 @@ EXPORT_SYMBOL_GPL(gpiod_add_lookup_table);
  */
 void gpiod_remove_lookup_table(struct gpiod_lookup_table *table)
 {
+	/* Nothing to remove */
+	if (!table)
+		return;
+
 	mutex_lock(&gpio_lookup_lock);
 
 	list_del(&table->list);
-- 
2.29.2


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

* [PATCH v1 2/3] i2c: i801: Drop duplicate NULL check in i801_del_mux()
  2020-12-28 20:06 [PATCH v1 1/3] gpiolib: Follow usual pattern for gpiod_remove_lookup_table() call Andy Shevchenko
@ 2020-12-28 20:06 ` Andy Shevchenko
  2021-01-06 16:03   ` Jean Delvare
  2020-12-28 20:06 ` [PATCH v1 3/3] i2c: i801: Refactor mux code since platform_device_unregister() is NULL aware Andy Shevchenko
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2020-12-28 20:06 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, linux-gpio, Jean Delvare,
	Wolfram Sang, linux-i2c
  Cc: Andy Shevchenko

Since gpiod_remove_lookup_table() is NULL-aware, no need to have this check
in the caller. Drop duplicate NULL check.

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

diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index ae90713443fa..7c2569a18f8c 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -1487,8 +1487,7 @@ static void i801_del_mux(struct i801_priv *priv)
 {
 	if (priv->mux_pdev)
 		platform_device_unregister(priv->mux_pdev);
-	if (priv->lookup)
-		gpiod_remove_lookup_table(priv->lookup);
+	gpiod_remove_lookup_table(priv->lookup);
 }
 
 static unsigned int i801_get_adapter_class(struct i801_priv *priv)
-- 
2.29.2


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

* [PATCH v1 3/3] i2c: i801: Refactor mux code since platform_device_unregister() is NULL aware
  2020-12-28 20:06 [PATCH v1 1/3] gpiolib: Follow usual pattern for gpiod_remove_lookup_table() call Andy Shevchenko
  2020-12-28 20:06 ` [PATCH v1 2/3] i2c: i801: Drop duplicate NULL check in i801_del_mux() Andy Shevchenko
@ 2020-12-28 20:06 ` Andy Shevchenko
  2021-01-06 16:03   ` Jean Delvare
  2021-01-04 14:24 ` [PATCH v1 1/3] gpiolib: Follow usual pattern for gpiod_remove_lookup_table() call Bartosz Golaszewski
  2021-01-06 16:03 ` Jean Delvare
  3 siblings, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2020-12-28 20:06 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, linux-gpio, Jean Delvare,
	Wolfram Sang, linux-i2c
  Cc: Andy Shevchenko

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);
 }
 
-- 
2.29.2


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

* Re: [PATCH v1 1/3] gpiolib: Follow usual pattern for gpiod_remove_lookup_table() call
  2020-12-28 20:06 [PATCH v1 1/3] gpiolib: Follow usual pattern for gpiod_remove_lookup_table() call Andy Shevchenko
  2020-12-28 20:06 ` [PATCH v1 2/3] i2c: i801: Drop duplicate NULL check in i801_del_mux() Andy Shevchenko
  2020-12-28 20:06 ` [PATCH v1 3/3] i2c: i801: Refactor mux code since platform_device_unregister() is NULL aware Andy Shevchenko
@ 2021-01-04 14:24 ` Bartosz Golaszewski
  2021-01-04 14:33   ` Andy Shevchenko
  2021-01-06 16:03 ` Jean Delvare
  3 siblings, 1 reply; 9+ messages in thread
From: Bartosz Golaszewski @ 2021-01-04 14:24 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Linus Walleij, linux-gpio, Jean Delvare, Wolfram Sang, linux-i2c

On Mon, Dec 28, 2020 at 9:06 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> The usual pattern for the remove calls, like gpiod_remove_lookup_table(),
> is to be NULL-aware, i.o.w. become a no-op whenever parameter is NULL.
> Update gpiod_remove_lookup_table() call to follow this pattern.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/gpio/gpiolib.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index b02cc2abd3b6..611d6ea82d75 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -3460,6 +3460,10 @@ EXPORT_SYMBOL_GPL(gpiod_add_lookup_table);
>   */
>  void gpiod_remove_lookup_table(struct gpiod_lookup_table *table)
>  {
> +       /* Nothing to remove */
> +       if (!table)
> +               return;
> +
>         mutex_lock(&gpio_lookup_lock);
>
>         list_del(&table->list);
> --
> 2.29.2
>

Applied, thanks!

Bart

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

* Re: [PATCH v1 1/3] gpiolib: Follow usual pattern for gpiod_remove_lookup_table() call
  2021-01-04 14:24 ` [PATCH v1 1/3] gpiolib: Follow usual pattern for gpiod_remove_lookup_table() call Bartosz Golaszewski
@ 2021-01-04 14:33   ` Andy Shevchenko
  2021-01-04 14:59     ` Bartosz Golaszewski
  0 siblings, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2021-01-04 14:33 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Linus Walleij, linux-gpio, Jean Delvare, Wolfram Sang, linux-i2c

On Mon, Jan 04, 2021 at 03:24:47PM +0100, Bartosz Golaszewski wrote:
> On Mon, Dec 28, 2020 at 9:06 PM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> >
> > The usual pattern for the remove calls, like gpiod_remove_lookup_table(),
> > is to be NULL-aware, i.o.w. become a no-op whenever parameter is NULL.
> > Update gpiod_remove_lookup_table() call to follow this pattern.
> >
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > ---
> >  drivers/gpio/gpiolib.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> > index b02cc2abd3b6..611d6ea82d75 100644
> > --- a/drivers/gpio/gpiolib.c
> > +++ b/drivers/gpio/gpiolib.c
> > @@ -3460,6 +3460,10 @@ EXPORT_SYMBOL_GPL(gpiod_add_lookup_table);
> >   */
> >  void gpiod_remove_lookup_table(struct gpiod_lookup_table *table)
> >  {
> > +       /* Nothing to remove */
> > +       if (!table)
> > +               return;
> > +
> >         mutex_lock(&gpio_lookup_lock);
> >
> >         list_del(&table->list);
> > --
> > 2.29.2
> >
> 
> Applied, thanks!

Thanks. Though I think it can be also applied to I²C tree since dependency?
Any tags / immutable branch for Wolfram?

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v1 1/3] gpiolib: Follow usual pattern for gpiod_remove_lookup_table() call
  2021-01-04 14:33   ` Andy Shevchenko
@ 2021-01-04 14:59     ` Bartosz Golaszewski
  0 siblings, 0 replies; 9+ messages in thread
From: Bartosz Golaszewski @ 2021-01-04 14:59 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Linus Walleij, linux-gpio, Jean Delvare, Wolfram Sang, linux-i2c

On Mon, Jan 4, 2021 at 3:32 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Mon, Jan 04, 2021 at 03:24:47PM +0100, Bartosz Golaszewski wrote:
> > On Mon, Dec 28, 2020 at 9:06 PM Andy Shevchenko
> > <andriy.shevchenko@linux.intel.com> wrote:
> > >
> > > The usual pattern for the remove calls, like gpiod_remove_lookup_table(),
> > > is to be NULL-aware, i.o.w. become a no-op whenever parameter is NULL.
> > > Update gpiod_remove_lookup_table() call to follow this pattern.
> > >
> > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > > ---
> > >  drivers/gpio/gpiolib.c | 4 ++++
> > >  1 file changed, 4 insertions(+)
> > >
> > > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> > > index b02cc2abd3b6..611d6ea82d75 100644
> > > --- a/drivers/gpio/gpiolib.c
> > > +++ b/drivers/gpio/gpiolib.c
> > > @@ -3460,6 +3460,10 @@ EXPORT_SYMBOL_GPL(gpiod_add_lookup_table);
> > >   */
> > >  void gpiod_remove_lookup_table(struct gpiod_lookup_table *table)
> > >  {
> > > +       /* Nothing to remove */
> > > +       if (!table)
> > > +               return;
> > > +
> > >         mutex_lock(&gpio_lookup_lock);
> > >
> > >         list_del(&table->list);
> > > --
> > > 2.29.2
> > >
> >
> > Applied, thanks!
>
> Thanks. Though I think it can be also applied to I涎 tree since dependency?
> Any tags / immutable branch for Wolfram?
>
> --
> With Best Regards,
> Andy Shevchenko
>
>

Oops I assumed this is independent. In that case:

Acked-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>

Wolfram, please take it through the i2c tree.

Bartosz

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

* Re: [PATCH v1 1/3] gpiolib: Follow usual pattern for gpiod_remove_lookup_table() call
  2020-12-28 20:06 [PATCH v1 1/3] gpiolib: Follow usual pattern for gpiod_remove_lookup_table() call Andy Shevchenko
                   ` (2 preceding siblings ...)
  2021-01-04 14:24 ` [PATCH v1 1/3] gpiolib: Follow usual pattern for gpiod_remove_lookup_table() call Bartosz Golaszewski
@ 2021-01-06 16:03 ` Jean Delvare
  3 siblings, 0 replies; 9+ messages in thread
From: Jean Delvare @ 2021-01-06 16:03 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Linus Walleij, Bartosz Golaszewski, linux-gpio, Wolfram Sang, linux-i2c

On Mon, 28 Dec 2020 22:06:16 +0200, Andy Shevchenko wrote:
> The usual pattern for the remove calls, like gpiod_remove_lookup_table(),
> is to be NULL-aware, i.o.w. become a no-op whenever parameter is NULL.
> Update gpiod_remove_lookup_table() call to follow this pattern.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/gpio/gpiolib.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index b02cc2abd3b6..611d6ea82d75 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -3460,6 +3460,10 @@ EXPORT_SYMBOL_GPL(gpiod_add_lookup_table);
>   */
>  void gpiod_remove_lookup_table(struct gpiod_lookup_table *table)
>  {
> +	/* Nothing to remove */
> +	if (!table)
> +		return;
> +
>  	mutex_lock(&gpio_lookup_lock);
>  
>  	list_del(&table->list);

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

-- 
Jean Delvare
SUSE L3 Support

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

* Re: [PATCH v1 2/3] i2c: i801: Drop duplicate NULL check in i801_del_mux()
  2020-12-28 20:06 ` [PATCH v1 2/3] i2c: i801: Drop duplicate NULL check in i801_del_mux() Andy Shevchenko
@ 2021-01-06 16:03   ` Jean Delvare
  0 siblings, 0 replies; 9+ messages in thread
From: Jean Delvare @ 2021-01-06 16:03 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Linus Walleij, Bartosz Golaszewski, linux-gpio, Wolfram Sang, linux-i2c

On Mon, 28 Dec 2020 22:06:17 +0200, Andy Shevchenko wrote:
> Since gpiod_remove_lookup_table() is NULL-aware, no need to have this check
> in the caller. Drop duplicate NULL check.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/i2c/busses/i2c-i801.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
> index ae90713443fa..7c2569a18f8c 100644
> --- a/drivers/i2c/busses/i2c-i801.c
> +++ b/drivers/i2c/busses/i2c-i801.c
> @@ -1487,8 +1487,7 @@ static void i801_del_mux(struct i801_priv *priv)
>  {
>  	if (priv->mux_pdev)
>  		platform_device_unregister(priv->mux_pdev);
> -	if (priv->lookup)
> -		gpiod_remove_lookup_table(priv->lookup);
> +	gpiod_remove_lookup_table(priv->lookup);
>  }
>  
>  static unsigned int i801_get_adapter_class(struct i801_priv *priv)

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

-- 
Jean Delvare
SUSE L3 Support

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

* Re: [PATCH v1 3/3] i2c: i801: Refactor mux code since platform_device_unregister() is NULL aware
  2020-12-28 20:06 ` [PATCH v1 3/3] i2c: i801: Refactor mux code since platform_device_unregister() is NULL aware Andy Shevchenko
@ 2021-01-06 16:03   ` Jean Delvare
  0 siblings, 0 replies; 9+ messages in thread
From: Jean Delvare @ 2021-01-06 16:03 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Linus Walleij, Bartosz Golaszewski, linux-gpio, Wolfram Sang, linux-i2c

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

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

end of thread, other threads:[~2021-01-06 16:04 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-28 20:06 [PATCH v1 1/3] gpiolib: Follow usual pattern for gpiod_remove_lookup_table() call Andy Shevchenko
2020-12-28 20:06 ` [PATCH v1 2/3] i2c: i801: Drop duplicate NULL check in i801_del_mux() Andy Shevchenko
2021-01-06 16:03   ` Jean Delvare
2020-12-28 20:06 ` [PATCH v1 3/3] i2c: i801: Refactor mux code since platform_device_unregister() is NULL aware Andy Shevchenko
2021-01-06 16:03   ` Jean Delvare
2021-01-04 14:24 ` [PATCH v1 1/3] gpiolib: Follow usual pattern for gpiod_remove_lookup_table() call Bartosz Golaszewski
2021-01-04 14:33   ` Andy Shevchenko
2021-01-04 14:59     ` Bartosz Golaszewski
2021-01-06 16:03 ` Jean Delvare

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