mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] cdev: simplify loop in cdev_by_device_node
@ 2024-01-03 10:20 Ahmad Fatoum
  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
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 10:20 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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




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

end of thread, other threads:[~2024-01-04 11:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-03 10:20 [PATCH 1/2] cdev: simplify loop in cdev_by_device_node Ahmad Fatoum
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

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