diff mbox series

[v3,7/9] driver core: Correct parameter check for API device_for_each_child_reverse_from()

Message ID 20241212-class_fix-v3-7-04e20c4f0971@quicinc.com
State Superseded
Headers show
Series driver core: class: Fix bug and code improvements for class APIs | expand

Commit Message

Zijun Hu Dec. 12, 2024, 1:38 p.m. UTC
From: Zijun Hu <quic_zijuhu@quicinc.com>

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).

Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
 drivers/base/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jonathan Cameron Dec. 16, 2024, 3:23 p.m. UTC | #1
On Thu, 12 Dec 2024 21:38:43 +0800
Zijun Hu <zijun_hu@icloud.com> wrote:

> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> 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).
> 
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
Given that 'from' implies continuation of an iteration I can see why
it might not ever be relevant to check parent.  It's harmless, but to
my mind unnecessary.

Jonathan

> ---
>  drivers/base/core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 69bb6bf4bd12395226ee3c99e2f63d15c7e342a5..34fb13f914b3db47e6a047fdabf3c9b18ecc08cc 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -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,
>
Zijun Hu Dec. 17, 2024, 2:18 p.m. UTC | #2
On 2024/12/16 23:23, Jonathan Cameron wrote:
>> Correct the API's parameter @parent check by (!parent || !parent->p).
>>
>> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
> Given that 'from' implies continuation of an iteration I can see why
> it might not ever be relevant to check parent.  It's harmless, but to
> my mind unnecessary.

the extra check !parent has no overhead and make this check consistent
with others in the cluster. (^^)
diff mbox series

Patch

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 69bb6bf4bd12395226ee3c99e2f63d15c7e342a5..34fb13f914b3db47e6a047fdabf3c9b18ecc08cc 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -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,