driver core: Correct parameter check for API device_for_each_child_reverse_from()
authorZijun Hu <quic_zijuhu@quicinc.com>
Sun, 5 Jan 2025 08:34:06 +0000 (16:34 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 10 Jan 2025 14:26:12 +0000 (15:26 +0100)
device_for_each_child_reverse_from() checks (!parent->p) for its
parameter @parent, and that is not consistent with other APIs of
its cluster as shown below:

device_for_each_child_reverse_from() // check (!parent->p)
device_for_each_child_reverse()      // check (!parent || !parent->p)
device_for_each_child()              // same above
device_find_child()                  // same above

Correct the API's parameter @parent check by (!parent || !parent->p).

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
Link: https://lore.kernel.org/r/20250105-class_fix-v6-5-3a2f1768d4d4@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/core.c

index a83a1350fb5b2baa5e4ee0f5e5805a5bee536ec7..d3800f0dc5bbd2a7de80bd58b50e31038265da03 100644 (file)
@@ -4050,7 +4050,7 @@ int device_for_each_child_reverse_from(struct device *parent,
        struct device *child;
        int error = 0;
 
-       if (!parent->p)
+       if (!parent || !parent->p)
                return 0;
 
        klist_iter_init_node(&parent->p->klist_children, &i,