Skip to contentSkip to conversation

gpiolib: Follow usual pattern for gpiod_remove_lookup_table() call

PATCH Applied Andy Shevchenko 3 participants 9 messages Dec 28, 2020 – Jan 6, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 gpiolib: Follow usual pattern for gpiod_remove_lookup_table() call

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.

---
 drivers/gpio/gpiolib.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpio/gpiolib.c +4 -0
index b02cc2abd3b6..611d6ea82d75 100644
@@ -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);
Signature · 1 line
2.29.2
#1 lore raw

PATCH 2/3 i2c: i801: Drop duplicate NULL check in i801_del_mux()

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

---
 drivers/i2c/busses/i2c-i801.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/i2c/busses/i2c-i801.c +1 -2
index ae90713443fa..7c2569a18f8c 100644
@@ -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)
Signature · 1 line
2.29.2
Reviewed-by on v1 2/3
#2 lore raw

Re: [PATCH v1 2/3] i2c: i801: Drop duplicate NULL check in i801_del_mux()

Quoted 13 lines · Andy Shevchenko

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

---
 drivers/i2c/busses/i2c-i801.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/i2c/busses/i2c-i801.c +0 -0
index ae90713443fa..7c2569a18f8c 100644

drivers/i2c/busses/i2c-i801.c static void i801_del_mux(struct i801_priv *priv) · line 1493

Quoted 9 lines
drivers/i2c/busses/i2c-i801.c +1 -2
@@ -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)
Signature · 2 lines
Jean Delvare
SUSE L3 Support
#3 lore raw

PATCH 3/3 i2c: i801: Refactor mux code since platform_device_unregister() is NULL aware

In reply to 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.

---
 drivers/i2c/busses/i2c-i801.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/i2c/busses/i2c-i801.c +3 -7
index 7c2569a18f8c..1400a8716388 100644
@@ -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);
 }
 
Signature · 1 line
2.29.2
Reviewed-by on v1 3/3
#4 lore raw

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

Quoted 36 lines · 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.

---
 drivers/i2c/busses/i2c-i801.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/i2c/busses/i2c-i801.c +2 -5
index 7c2569a18f8c..1400a8716388 100644
@@ -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);

drivers/i2c/busses/i2c-i801.c static int i801_add_mux(struct i801_priv *priv) · line 1488

Quoted 10 lines
drivers/i2c/busses/i2c-i801.c +1 -2
 }
 
 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);
 }
 
Signature · 2 lines
Jean Delvare
SUSE L3 Support
#5 lore raw
In reply to Andy Shevchenko
Quoted 26 lines · 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.

---
 drivers/gpio/gpiolib.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpio/gpiolib.c +4 -1
index b02cc2abd3b6..611d6ea82d75 100644
@@ -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);
--
Quoted 2 lines

2.29.2

Applied, thanks!

Bart

#6 lore raw
Quoted 26 lines · Bartosz Golaszewski
Quoted 24 lines · 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.

---
 drivers/gpio/gpiolib.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpio/gpiolib.c +4 -0
index b02cc2abd3b6..611d6ea82d75 100644
@@ -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);
 
Quoted 6 lines
Quoted 4 lines
drivers/gpio/gpiolib.c +0 -1
        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?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#7 lore raw
Quoted 35 lines · Andy Shevchenko
Quoted 26 lines · Bartosz Golaszewski
Quoted 24 lines · 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.

---
 drivers/gpio/gpiolib.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpio/gpiolib.c +4 -0
index b02cc2abd3b6..611d6ea82d75 100644
@@ -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);
 
Quoted 6 lines
Quoted 4 lines
drivers/gpio/gpiolib.c +0 -1
        list_del(&table->list);
--

2.29.2

Applied, thanks!

Quoted 8 lines

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:

Wolfram, please take it through the i2c tree.

Bartosz

Reviewed-by on v1 1/3
#8 lore raw
In reply to Andy Shevchenko
Quoted 14 lines · 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.

---
 drivers/gpio/gpiolib.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpio/gpiolib.c +0 -0
index b02cc2abd3b6..611d6ea82d75 100644

drivers/gpio/gpiolib.c EXPORT_SYMBOL_GPL(gpiod_add_lookup_table); · line 3469

Quoted 10 lines
drivers/gpio/gpiolib.c +4 -0
@@ -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);
Signature · 2 lines
Jean Delvare
SUSE L3 Support