lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <2ed209ec-2eef-4a41-9591-275e7d8f7676@arm.com>
Date:   Tue, 24 Oct 2023 09:14:17 +0100
From:   Lukasz Luba <lukasz.luba@....com>
To:     Daniel Lezcano <daniel.lezcano@...aro.org>
Cc:     dietmar.eggemann@....com, rui.zhang@...el.com,
        linux-kernel@...r.kernel.org, amit.kucheria@...durent.com,
        amit.kachhap@...il.com, viresh.kumar@...aro.org,
        len.brown@...el.com, pavel@....cz, mhiramat@...nel.org,
        qyousef@...alina.io, wvw@...gle.com, linux-pm@...r.kernel.org,
        rafael@...nel.org
Subject: Re: [PATCH v4 06/18] PM: EM: Check if the get_cost() callback is
 present in em_compute_costs()



On 10/23/23 19:23, Daniel Lezcano wrote:
> On 25/09/2023 10:11, Lukasz Luba wrote:
>> The em_compute_cost() is going to be re-used in runtime modified EM
>> code path. Thus, make sure that this common code is safe and won't
>> try to use the NULL pointer. The former em_compute_cost() didn't have to
>> care about runtime modification code path. The upcoming changes introduce
>> such option, but with different callback. Those two paths which use
>> get_cost() (during first EM registration) or update_power() (during
>> runtime modification) need to be safely handled in em_compute_costs().
>>
>> Signed-off-by: Lukasz Luba <lukasz.luba@....com>
>> ---
>>   kernel/power/energy_model.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c
>> index 7ea882401833..35e07933b34a 100644
>> --- a/kernel/power/energy_model.c
>> +++ b/kernel/power/energy_model.c
>> @@ -116,7 +116,7 @@ static int em_compute_costs(struct device *dev, 
>> struct em_perf_state *table,
>>       for (i = nr_states - 1; i >= 0; i--) {
>>           unsigned long power_res, cost;
>> -        if (flags & EM_PERF_DOMAIN_ARTIFICIAL) {
>> +        if (flags & EM_PERF_DOMAIN_ARTIFICIAL && cb->get_cost) {
>>               ret = cb->get_cost(dev, table[i].frequency, &cost);
>>               if (ret || !cost || cost > EM_MAX_POWER) {
>>                   dev_err(dev, "EM: invalid cost %lu %d\n",
> 
> I do believe & operator has lower precedence than && operator, thus the 
> test is actually:
> 
>      (flags & (EM_PERF_DOMAIN_ARTIFICIAL && cb->get_cost))
> 
> but it should be
> 
>      ((flags & EM_PERF_DOMAIN_ARTIFICIAL) && cb->get_cost)
> 
> Right ?
> 

The bitwise '&' is stronger than logical '&&', so the code will
work as in your 2nd example. Although, I will change it and add
parentheses for better reading.

Thanks!

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ