Linux GPIO subsystem development
 help / color / mirror / Atom feed
* [PATCH v3] gpio: sch311x: Use devm_gpiochip_add_data() to simplify remove path
@ 2023-05-15 17:42 Andrew Davis
  2023-05-15 21:08 ` Andy Shevchenko
  2023-05-17  9:52 ` Bartosz Golaszewski
  0 siblings, 2 replies; 4+ messages in thread
From: Andrew Davis @ 2023-05-15 17:42 UTC (permalink / raw)
  To: Peter Tyser, Andy Shevchenko, Linus Walleij, Bartosz Golaszewski
  Cc: linux-gpio, linux-kernel, Andrew Davis

Use devm version of gpiochip add function to handle removal for us.

Signed-off-by: Andrew Davis <afd@ti.com>
---

Changes from v2:
 - Remove platform_driver.remove (thanks kernel test robot)

 drivers/gpio/gpio-sch311x.c | 26 ++------------------------
 1 file changed, 2 insertions(+), 24 deletions(-)

diff --git a/drivers/gpio/gpio-sch311x.c b/drivers/gpio/gpio-sch311x.c
index da01e1cad7cb..ba4fccf3cc94 100644
--- a/drivers/gpio/gpio-sch311x.c
+++ b/drivers/gpio/gpio-sch311x.c
@@ -281,8 +281,6 @@ static int sch311x_gpio_probe(struct platform_device *pdev)
 	if (!priv)
 		return -ENOMEM;
 
-	platform_set_drvdata(pdev, priv);
-
 	for (i = 0; i < ARRAY_SIZE(priv->blocks); i++) {
 		block = &priv->blocks[i];
 
@@ -305,42 +303,22 @@ static int sch311x_gpio_probe(struct platform_device *pdev)
 		block->data_reg = sch311x_gpio_blocks[i].data_reg;
 		block->runtime_reg = pdata->runtime_reg;
 
-		err = gpiochip_add_data(&block->chip, block);
+		err = devm_gpiochip_add_data(&pdev->dev, &block->chip, block);
 		if (err < 0) {
 			dev_err(&pdev->dev,
 				"Could not register gpiochip, %d\n", err);
-			goto exit_err;
+			return err;
 		}
 		dev_info(&pdev->dev,
 			 "SMSC SCH311x GPIO block %d registered.\n", i);
 	}
 
 	return 0;
-
-exit_err:
-	/* release already registered chips */
-	for (--i; i >= 0; i--)
-		gpiochip_remove(&priv->blocks[i].chip);
-	return err;
-}
-
-static int sch311x_gpio_remove(struct platform_device *pdev)
-{
-	struct sch311x_gpio_priv *priv = platform_get_drvdata(pdev);
-	int i;
-
-	for (i = 0; i < ARRAY_SIZE(priv->blocks); i++) {
-		gpiochip_remove(&priv->blocks[i].chip);
-		dev_info(&pdev->dev,
-			 "SMSC SCH311x GPIO block %d unregistered.\n", i);
-	}
-	return 0;
 }
 
 static struct platform_driver sch311x_gpio_driver = {
 	.driver.name	= DRV_NAME,
 	.probe		= sch311x_gpio_probe,
-	.remove		= sch311x_gpio_remove,
 };
 
 
-- 
2.39.2


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

* Re: [PATCH v3] gpio: sch311x: Use devm_gpiochip_add_data() to simplify remove path
  2023-05-15 17:42 [PATCH v3] gpio: sch311x: Use devm_gpiochip_add_data() to simplify remove path Andrew Davis
@ 2023-05-15 21:08 ` Andy Shevchenko
  2023-05-16 15:19   ` Andrew Davis
  2023-05-17  9:52 ` Bartosz Golaszewski
  1 sibling, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2023-05-15 21:08 UTC (permalink / raw)
  To: Andrew Davis
  Cc: Peter Tyser, Andy Shevchenko, Linus Walleij, Bartosz Golaszewski,
	linux-gpio, linux-kernel

On Mon, May 15, 2023 at 8:42 PM Andrew Davis <afd@ti.com> wrote:
>
> Use devm version of gpiochip add function to handle removal for us.

...version of gpiochip_add() function...

...

> +               err = devm_gpiochip_add_data(&pdev->dev, &block->chip, block);
>                 if (err < 0) {
>                         dev_err(&pdev->dev,
>                                 "Could not register gpiochip, %d\n", err);
> -                       goto exit_err;
> +                       return err;

With this applied you can consider a followup to have this be converted to use

    return dev_err_probe(...);

here and in other ->probe() related pieces.

>                 }

-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH v3] gpio: sch311x: Use devm_gpiochip_add_data() to simplify remove path
  2023-05-15 21:08 ` Andy Shevchenko
@ 2023-05-16 15:19   ` Andrew Davis
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Davis @ 2023-05-16 15:19 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Peter Tyser, Andy Shevchenko, Linus Walleij, Bartosz Golaszewski,
	linux-gpio, linux-kernel

On 5/15/23 4:08 PM, Andy Shevchenko wrote:
> On Mon, May 15, 2023 at 8:42 PM Andrew Davis <afd@ti.com> wrote:
>>
>> Use devm version of gpiochip add function to handle removal for us.
> 
> ...version of gpiochip_add() function...
> 
> ...
> 
>> +               err = devm_gpiochip_add_data(&pdev->dev, &block->chip, block);
>>                  if (err < 0) {
>>                          dev_err(&pdev->dev,
>>                                  "Could not register gpiochip, %d\n", err);
>> -                       goto exit_err;
>> +                       return err;
> 
> With this applied you can consider a followup to have this be converted to use
> 
>      return dev_err_probe(...);
> 
> here and in other ->probe() related pieces.
> 

Sure, I can add that cleanup to my list.

Or maybe Coccinelle can help do this everywhere, will have to look into that.

Andrew

>>                  }
> 

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

* Re: [PATCH v3] gpio: sch311x: Use devm_gpiochip_add_data() to simplify remove path
  2023-05-15 17:42 [PATCH v3] gpio: sch311x: Use devm_gpiochip_add_data() to simplify remove path Andrew Davis
  2023-05-15 21:08 ` Andy Shevchenko
@ 2023-05-17  9:52 ` Bartosz Golaszewski
  1 sibling, 0 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2023-05-17  9:52 UTC (permalink / raw)
  To: Andrew Davis
  Cc: Peter Tyser, Andy Shevchenko, Linus Walleij, linux-gpio,
	linux-kernel

On Mon, May 15, 2023 at 7:42 PM Andrew Davis <afd@ti.com> wrote:
>
> Use devm version of gpiochip add function to handle removal for us.
>
> Signed-off-by: Andrew Davis <afd@ti.com>
> ---

Applied, thanks!

Bart

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

end of thread, other threads:[~2023-05-17  9:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-15 17:42 [PATCH v3] gpio: sch311x: Use devm_gpiochip_add_data() to simplify remove path Andrew Davis
2023-05-15 21:08 ` Andy Shevchenko
2023-05-16 15:19   ` Andrew Davis
2023-05-17  9:52 ` Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox