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@xxxxxxxxxxxxxx> --- 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