linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Javier Carrasco <javier.carrasco.cruz@gmail.com>
To: Hoan Tran <hoan@os.amperecomputing.com>,
	 Serge Semin <fancer.lancer@gmail.com>,
	 Linus Walleij <linus.walleij@linaro.org>,
	 Bartosz Golaszewski <brgl@bgdev.pl>,
	 Mika Westerberg <mika.westerberg@linux.intel.com>,
	 Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-acpi@vger.kernel.org,
	 Javier Carrasco <javier.carrasco.cruz@gmail.com>
Subject: [PATCH 0/3] gpio: switch to device_for_each_chilld_node_scoped()
Date: Sat, 28 Sep 2024 21:47:34 +0200	[thread overview]
Message-ID: <20240928-gpio_device_for_each_child_node_scoped-v1-0-c20eff315f4f@gmail.com> (raw)

This series switches from the device_for_each_child_node() macro to its
scoped variant. This makes the code more robust if new early exits are
added to the loops, because there is no need for explicit calls to
fwnode_handle_put(), which also simplifies existing code.

The non-scoped macros to walk over nodes turn error-prone as soon as
the loop contains early exits (break, goto, return), and patches to
fix them show up regularly, sometimes due to new error paths in an
existing loop [1].

The uses of device_for_each_child_node() with no early exits have been
left untouched because their simpilicty justifies the non-scoped
variant. In particular for gpio, there is a single case in gpio-hisi.c
where the loop does not have early exists. But if desired, it can be
easily converted as well to enforce the usage of the scoped variant when
"borrowing" existing code.

Note that the child node is now declared in the macro, and therefore the
explicit declaration is no longer required.

The general functionality should not be affected by this modification.
Apart from automatically decrementing the node's refcount when it goes
out of scope, the scoped variant works exactly the same as the
non-scoped.

If functional changes are found, please report them back as errors.

Just in case, and even though the scoped macro already has multiple
users, I carried out a quick test with gpio-sim and a few nodes defined
in a devicetree, and everything works as expected.

Link:
https://lore.kernel.org/all/20240901160829.709296395@linuxfoundation.org/
[1]

Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
Javier Carrasco (3):
      gpio: dwapb: switch to device_for_each_child_node_scoped()
      gpio: sim: switch to device_for_each_child_node_scoped()
      gpio: acpi: switch to device_for_each_child_node_scoped()

 drivers/gpio/gpio-dwapb.c   | 4 +---
 drivers/gpio/gpio-sim.c     | 7 ++-----
 drivers/gpio/gpiolib-acpi.c | 4 +---
 3 files changed, 4 insertions(+), 11 deletions(-)
---
base-commit: 40e0c9d414f57d450e3ad03c12765e797fc3fede
change-id: 20240927-gpio_device_for_each_child_node_scoped-a2071fe5c8c6

Best regards,
-- 
Javier Carrasco <javier.carrasco.cruz@gmail.com>


             reply	other threads:[~2024-09-28 19:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-28 19:47 Javier Carrasco [this message]
2024-09-28 19:47 ` [PATCH 1/3] gpio: dwapb: switch to device_for_each_child_node_scoped() Javier Carrasco
2024-09-30 11:22   ` Andy Shevchenko
2024-09-30 13:06   ` Serge Semin
2024-10-01 14:13   ` Linus Walleij
2024-09-28 19:47 ` [PATCH 2/3] gpio: sim: " Javier Carrasco
2024-09-30 11:22   ` Andy Shevchenko
2024-09-28 19:47 ` [PATCH 3/3] gpio: acpi: " Javier Carrasco
2024-09-30 11:23   ` Andy Shevchenko
2024-10-01 18:54 ` (subset) [PATCH 0/3] gpio: switch to device_for_each_chilld_node_scoped() Bartosz Golaszewski

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=20240928-gpio_device_for_each_child_node_scoped-v1-0-c20eff315f4f@gmail.com \
    --to=javier.carrasco.cruz@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=brgl@bgdev.pl \
    --cc=fancer.lancer@gmail.com \
    --cc=hoan@os.amperecomputing.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    /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;
as well as URLs for NNTP newsgroup(s).