kernel: gpio-nct5104d: use devm
authorRosen Penev <rosenp@gmail.com>
Sun, 22 Sep 2024 17:41:24 +0000 (10:41 -0700)
committerHauke Mehrtens <hauke@hauke-m.de>
Sun, 20 Oct 2024 11:52:45 +0000 (13:52 +0200)
Allows removal of the remove function by letting devm handle everything.

Avoids gotos as well.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/16507
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
package/kernel/gpio-nct5104d/Makefile
package/kernel/gpio-nct5104d/src/gpio-nct5104d.c

index bb6010d2d02537abc281fad580357fd60489fb2c..9181a2bc5f19e26cf25bb9a0b8742c807083a29e 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 include $(INCLUDE_DIR)/kernel.mk
 
 PKG_NAME:=gpio-nct5104d
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_MAINTAINER:=Florian Eckert <Eckert.Florian@googlemail.com>
 PKG_LICENSE:=GPL-2.0
index eb1cf8494abe2b317775be145aa9672010d82b8c..e31a94b5cfb20d4669e0f3088add5e9611ebfa2d 100644 (file)
@@ -153,8 +153,7 @@ static struct nct5104d_gpio_bank nct5104d_gpio_bank[] = {
 static int nct5104d_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
 {
        int err;
-       struct nct5104d_gpio_bank *bank =
-               container_of(chip, struct nct5104d_gpio_bank, chip);
+       struct nct5104d_gpio_bank *bank = gpiochip_get_data(chip);
        struct nct5104d_sio *sio = bank->data->sio;
        u8 dir;
 
@@ -175,8 +174,7 @@ static int nct5104d_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
 static int nct5104d_gpio_get(struct gpio_chip *chip, unsigned offset)
 {
        int err;
-       struct nct5104d_gpio_bank *bank =
-               container_of(chip, struct nct5104d_gpio_bank, chip);
+       struct nct5104d_gpio_bank *bank = gpiochip_get_data(chip);
        struct nct5104d_sio *sio = bank->data->sio;
        u8 data;
 
@@ -196,8 +194,7 @@ static int nct5104d_gpio_direction_out(struct gpio_chip *chip,
                                     unsigned offset, int value)
 {
        int err;
-       struct nct5104d_gpio_bank *bank =
-               container_of(chip, struct nct5104d_gpio_bank, chip);
+       struct nct5104d_gpio_bank *bank = gpiochip_get_data(chip);
        struct nct5104d_sio *sio = bank->data->sio;
        u8 dir, data_out;
 
@@ -225,8 +222,7 @@ static int nct5104d_gpio_direction_out(struct gpio_chip *chip,
 static void nct5104d_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
 {
        int err;
-       struct nct5104d_gpio_bank *bank =
-               container_of(chip, struct nct5104d_gpio_bank, chip);
+       struct nct5104d_gpio_bank *bank = gpiochip_get_data(chip);
        struct nct5104d_sio *sio = bank->data->sio;
        u8 data_out;
 
@@ -270,8 +266,6 @@ static int nct5104d_gpio_probe(struct platform_device *pdev)
        }
        data->sio = sio;
 
-       platform_set_drvdata(pdev, data);
-
        /* For each GPIO bank, register a GPIO chip. */
        for (i = 0; i < data->nr_bank; i++) {
                struct nct5104d_gpio_bank *bank = &data->bank[i];
@@ -279,36 +273,10 @@ static int nct5104d_gpio_probe(struct platform_device *pdev)
                bank->chip.parent = &pdev->dev;
                bank->data = data;
 
-               err = gpiochip_add(&bank->chip);
-               if (err) {
-                       dev_err(&pdev->dev,
-                               "Failed to register gpiochip %d: %d\n",
-                               i, err);
-                       goto err_gpiochip;
-               }
-       }
-
-       return 0;
-
-err_gpiochip:
-       for (i = i - 1; i >= 0; i--) {
-               struct nct5104d_gpio_bank *bank = &data->bank[i];
-
-               gpiochip_remove (&bank->chip);
-       }
-
-       return err;
-}
-
-static int nct5104d_gpio_remove(struct platform_device *pdev)
-{
-       int i;
-       struct nct5104d_gpio_data *data = platform_get_drvdata(pdev);
-
-       for (i = 0; i < data->nr_bank; i++) {
-               struct nct5104d_gpio_bank *bank = &data->bank[i];
-
-               gpiochip_remove (&bank->chip);
+               err = devm_gpiochip_add_data(&pdev->dev, &bank->chip, bank);
+               if (err)
+                       return dev_err_probe(&pdev->dev, err,
+                               "Failed to register gpiochip %d", err);
        }
 
        return 0;
@@ -402,7 +370,6 @@ static struct platform_driver nct5104d_gpio_driver = {
                .name   = DRVNAME,
        },
        .probe          = nct5104d_gpio_probe,
-       .remove         = nct5104d_gpio_remove,
 };
 
 static int __init nct5104d_gpio_init(void)