Linux GPIO subsystem development
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: linux-gpio@vger.kernel.org, Linus Walleij <linus.walleij@linaro.org>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] pinctrl: pistachio: Use scope-based resource management in pistachio_gpio_register()
Date: Wed, 5 Jun 2024 18:02:01 +0200	[thread overview]
Message-ID: <3f6fc17e-2ab4-43f2-b166-2393a369a263@web.de> (raw)

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 5 Jun 2024 17:46:52 +0200

Scope-based resource management became supported also for another
programming interface by contributions of Jonathan Cameron on 2024-02-17.
See also the commit 59ed5e2d505bf5f9b4af64d0021cd0c96aec1f7c ("device
property: Add cleanup.h based fwnode_handle_put() scope based cleanup.").

* Thus use the attribute “__free(fwnode_handle)”.

* Reduce the scope for the local variable “child”.

* Omit explicit fwnode_handle_put() calls accordingly.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/pinctrl/pinctrl-pistachio.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-pistachio.c b/drivers/pinctrl/pinctrl-pistachio.c
index 53408344927a..d0a18296fb27 100644
--- a/drivers/pinctrl/pinctrl-pistachio.c
+++ b/drivers/pinctrl/pinctrl-pistachio.c
@@ -1368,11 +1368,12 @@ static int pistachio_gpio_register(struct pistachio_pinctrl *pctl)

 	for (i = 0; i < pctl->nbanks; i++) {
 		char child_name[sizeof("gpioXX")];
-		struct fwnode_handle *child;
 		struct gpio_irq_chip *girq;

 		snprintf(child_name, sizeof(child_name), "gpio%d", i);
-		child = device_get_named_child_node(pctl->dev, child_name);
+
+		struct fwnode_handle *child __free(fwnode_handle)
+					    = device_get_named_child_node(pctl->dev, child_name);
 		if (!child) {
 			dev_err(pctl->dev, "No node for bank %u\n", i);
 			ret = -ENODEV;
@@ -1380,7 +1381,6 @@ static int pistachio_gpio_register(struct pistachio_pinctrl *pctl)
 		}

 		if (!fwnode_property_present(child, "gpio-controller")) {
-			fwnode_handle_put(child);
 			dev_err(pctl->dev,
 				"No gpio-controller property for bank %u\n", i);
 			ret = -ENODEV;
@@ -1389,12 +1389,10 @@ static int pistachio_gpio_register(struct pistachio_pinctrl *pctl)

 		ret = fwnode_irq_get(child, 0);
 		if (ret < 0) {
-			fwnode_handle_put(child);
 			dev_err(pctl->dev, "Failed to retrieve IRQ for bank %u\n", i);
 			goto err;
 		}
 		if (!ret) {
-			fwnode_handle_put(child);
 			dev_err(pctl->dev, "No IRQ for bank %u\n", i);
 			ret = -EINVAL;
 			goto err;
@@ -1406,7 +1404,7 @@ static int pistachio_gpio_register(struct pistachio_pinctrl *pctl)
 		bank->base = pctl->base + GPIO_BANK_BASE(i);

 		bank->gpio_chip.parent = pctl->dev;
-		bank->gpio_chip.fwnode = child;
+		bank->gpio_chip.fwnode = no_free_ptr(child);

 		girq = &bank->gpio_chip.irq;
 		gpio_irq_chip_set_chip(girq, &pistachio_gpio_irq_chip);
--
2.45.1


             reply	other threads:[~2024-06-05 16:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-05 16:02 Markus Elfring [this message]
2024-06-17  8:32 ` [PATCH] pinctrl: pistachio: Use scope-based resource management in pistachio_gpio_register() Linus Walleij
2024-06-17 20:19   ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3f6fc17e-2ab4-43f2-b166-2393a369a263@web.de \
    --to=markus.elfring@web.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox