[PATCH] block: Remove unreachable code
Andrew Goodbody
andrew.goodbody at linaro.org
Mon Jul 14 19:12:05 CEST 2025
On 14/07/2025 17:29, Tom Rini wrote:
> On Mon, Jul 14, 2025 at 04:38:53PM +0100, Andrew Goodbody wrote:
>> The two functions blk_find_first and blk_find_next use a for loop with
>> the content being a 'return 0' which means that the 'increment' code is
>> unreachable so remove it and also remove the variable ret which is
>> assigned to but its value is never used.
>>
>> This issue found by Smatch.
>>
>> Signed-off-by: Andrew Goodbody <andrew.goodbody at linaro.org>
>> ---
>> drivers/block/blk-uclass.c | 14 ++++----------
>> 1 file changed, 4 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
>> index f3ac8db9464..b38c21ffbe2 100644
>> --- a/drivers/block/blk-uclass.c
>> +++ b/drivers/block/blk-uclass.c
>> @@ -613,11 +613,8 @@ static int blk_flags_check(struct udevice *dev, enum blk_flag_t req_flags)
>>
>> int blk_find_first(enum blk_flag_t flags, struct udevice **devp)
>> {
>> - int ret;
>> -
>> - for (ret = uclass_find_first_device(UCLASS_BLK, devp);
>> - *devp && !blk_flags_check(*devp, flags);
>> - ret = uclass_find_next_device(devp))
>> + for (uclass_find_first_device(UCLASS_BLK, devp);
>> + *devp && !blk_flags_check(*devp, flags);)
>> return 0;
>>
>> return -ENODEV;
>> @@ -625,11 +622,8 @@ int blk_find_first(enum blk_flag_t flags, struct udevice **devp)
>>
>> int blk_find_next(enum blk_flag_t flags, struct udevice **devp)
>> {
>> - int ret;
>> -
>> - for (ret = uclass_find_next_device(devp);
>> - *devp && !blk_flags_check(*devp, flags);
>> - ret = uclass_find_next_device(devp))
>> + for (uclass_find_next_device(devp);
>> + *devp && !blk_flags_check(*devp, flags);)
>> return 0;
>>
>> return -ENODEV;
>
> Should we clean up uclass_find_next_device(...) to not return int? The
> function comments don't quite make sense (include/dm/uclass-internal.h)
> and it always returns 0.
OK, that should not be too bad.
Andrew
More information about the U-Boot
mailing list