Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

driver core: Move true expression out of if condition in 3 device finding APIs

For bus_find_device(), driver_find_device(), and device_find_child(), all
of their function body have pattern below:

{
struct klist_iter i;
struct device *dev;

...
while ((dev = next_device(&i)))
if (match(dev, data) && get_device(dev))
break;
...
}

The expression 'get_device(dev)' in the if condition always returns true
since @dev != NULL.

Move the expression to if body to make logic of these APIs more clearer.

Reviewed-by: Fan Ni <fan.ni@samsung.com>
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-3-3a2f1768d4d4@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Zijun Hu and committed by
Greg Kroah-Hartman
3f58ee54 d1248436

+15 -6
+5 -2
drivers/base/bus.c
··· 402 402 403 403 klist_iter_init_node(&sp->klist_devices, &i, 404 404 (start ? &start->p->knode_bus : NULL)); 405 - while ((dev = next_device(&i))) 406 - if (match(dev, data) && get_device(dev)) 405 + while ((dev = next_device(&i))) { 406 + if (match(dev, data)) { 407 + get_device(dev); 407 408 break; 409 + } 410 + } 408 411 klist_iter_exit(&i); 409 412 subsys_put(sp); 410 413 return dev;
+5 -2
drivers/base/core.c
··· 4089 4089 return NULL; 4090 4090 4091 4091 klist_iter_init(&parent->p->klist_children, &i); 4092 - while ((child = next_device(&i))) 4093 - if (match(child, data) && get_device(child)) 4092 + while ((child = next_device(&i))) { 4093 + if (match(child, data)) { 4094 + get_device(child); 4094 4095 break; 4096 + } 4097 + } 4095 4098 klist_iter_exit(&i); 4096 4099 return child; 4097 4100 }
+5 -2
drivers/base/driver.c
··· 160 160 161 161 klist_iter_init_node(&drv->p->klist_devices, &i, 162 162 (start ? &start->p->knode_driver : NULL)); 163 - while ((dev = next_device(&i))) 164 - if (match(dev, data) && get_device(dev)) 163 + while ((dev = next_device(&i))) { 164 + if (match(dev, data)) { 165 + get_device(dev); 165 166 break; 167 + } 168 + } 166 169 klist_iter_exit(&i); 167 170 return dev; 168 171 }