[PATCH] power: regulator: Fix incorrect use of binary and

Andrew Goodbody andrew.goodbody at linaro.org
Mon Sep 1 16:59:38 CEST 2025


On 30/08/2025 19:45, Tom Rini wrote:
> On Thu, Jul 03, 2025 at 12:53:42PM +0100, Andrew Goodbody wrote:
> 
>> In regulator_list_autoset there is a test for ret being non-zero and
>> error being zero but it uses the binary '&' instead of the logical '&&'
>> which could well lead to unexpected results. Correct this to use the
>> logical '&&' instead.
>>
>> This issue found by Smatch.
>>
>> Signed-off-by: Andrew Goodbody <andrew.goodbody at linaro.org>
>> ---
>>   drivers/power/regulator/regulator-uclass.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/power/regulator/regulator-uclass.c b/drivers/power/regulator/regulator-uclass.c
>> index 09567eb9dbb..fbd1f69ac72 100644
>> --- a/drivers/power/regulator/regulator-uclass.c
>> +++ b/drivers/power/regulator/regulator-uclass.c
>> @@ -389,7 +389,7 @@ int regulator_list_autoset(const char *list_platname[],
>>   		ret = regulator_autoset_by_name(list_platname[i], &dev);
>>   		if (ret != -EMEDIUMTYPE && verbose)
>>   			regulator_show(dev, ret);
>> -		if (ret & !error)
>> +		if (ret && !error)
>>   			error = ret;
>>   
>>   		if (list_devp)
>>
> 
> This leads to the testcase failing:
> https://source.denx.de/u-boot/u-boot/-/jobs/1234999#L272
> which should be fixed in the same commit.

Ah, sorry I did not pick that up. The old incorrect code would ignore 
all even error returns. A couple of the regulators in the list returned 
-EALREADY (-114) which was quietly ignored. The corrected code picked 
this up and returned it, which I think is wrong in this specific case.

V2 coming to ignore -EALREADY.

Andrew


More information about the U-Boot mailing list