mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/2] cdev: simplify loop in cdev_by_device_node
Date: Wed,  3 Jan 2024 11:20:34 +0100	[thread overview]
Message-ID: <20240103102035.2630735-1-a.fatoum@pengutronix.de> (raw)

We don't need to compare the cdev's device node pointer both against NULL
and against the searched for device node on each iteration.

Instead, it's sufficient to just compare the device nodes directly.
To maintain previous behavior, when searching for a NULL device node, we
shouldn't return the first cdev, but return NULL. Do that via an early
exit instead of doing it after iterating over all cdevs.

No functional change.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 fs/devfs-core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index 244f76f62c52..c79b092a112e 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -87,9 +87,10 @@ struct cdev *cdev_by_device_node(struct device_node *node)
 {
 	struct cdev *cdev;
 
+	if (!node)
+		return NULL;
+
 	for_each_cdev(cdev) {
-		if (!cdev->device_node)
-			continue;
 		if (cdev->device_node == node)
 			return cdev_readlink(cdev);
 	}
-- 
2.39.2




             reply	other threads:[~2024-01-03 10:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-03 10:20 Ahmad Fatoum [this message]
2024-01-03 10:20 ` [PATCH 2/2] cdev: add cdev_alloc helper for creating cdevs Ahmad Fatoum
2024-01-04 11:17 ` [PATCH 1/2] cdev: simplify loop in cdev_by_device_node Sascha Hauer

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=20240103102035.2630735-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.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