Skip to content

Commit 3bf312f

Browse files
krzkrobherring
authored andcommitted
cdx: Use mutex guard to simplify error handling
Mutex guard allows to drop one goto/break in error handling and the less expected code of assigning -EINVAL to unsigned size_t count variable. Suggested-by: Jonathan Cameron <jonathan.cameron@huawei.com> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Link: https://patch.msgid.link/20260109-of-for-each-compatible-scoped-v3-7-c22fa2c0749a@oss.qualcomm.com Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
1 parent 2ff81fe commit 3bf312f

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

drivers/cdx/cdx.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -616,18 +616,16 @@ static ssize_t rescan_store(const struct bus_type *bus,
616616
if (!val)
617617
return -EINVAL;
618618

619-
mutex_lock(&cdx_controller_lock);
619+
guard(mutex)(&cdx_controller_lock);
620620

621621
/* Unregister all the devices on the bus */
622622
cdx_unregister_devices(&cdx_bus_type);
623623

624624
/* Rescan all the devices */
625625
for_each_compatible_node_scoped(np, NULL, compat_node_name) {
626626
pd = of_find_device_by_node(np);
627-
if (!pd) {
628-
count = -EINVAL;
629-
goto unlock;
630-
}
627+
if (!pd)
628+
return -EINVAL;
631629

632630
cdx = platform_get_drvdata(pd);
633631
if (cdx && cdx->controller_registered && cdx->ops->scan)
@@ -636,9 +634,6 @@ static ssize_t rescan_store(const struct bus_type *bus,
636634
put_device(&pd->dev);
637635
}
638636

639-
unlock:
640-
mutex_unlock(&cdx_controller_lock);
641-
642637
return count;
643638
}
644639
static BUS_ATTR_WO(rescan);

0 commit comments

Comments
 (0)