mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yaxiong Tian <iambestgod@qq.com>
To: Lukasz Luba <lukasz.luba@arm.com>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Yaxiong Tian <tianyaxiong@kylinos.cn>,
	rafael@kernel.org
Subject: Re: [PATCH v2] PM: EM: Fix potential division-by-zero error in em_compute_costs()
Date: Tue, 15 Apr 2025 09:12:51 +0800	[thread overview]
Message-ID: <tencent_AE7CE43CDAD6747AFF0E952C8D0908A98D0A@qq.com> (raw)
In-Reply-To: <143378b0-5740-4f2b-9a79-f04cf9ef1f77@arm.com>



在 2025/4/14 16:08, Lukasz Luba 写道:
> Hi Yaxiong,
> 
> On 4/11/25 02:28, Yaxiong Tian wrote:
>> From: Yaxiong Tian <tianyaxiong@kylinos.cn>
>>
>> When the device is of a non-CPU type, table[i].performance won't be
>> initialized in the previous em_init_performance(), resulting in division
>> by zero when calculating costs in em_compute_costs().
>>
>> Since the 'cost' algorithm is only used for EAS energy efficiency
>> calculations and is currently not utilized by other device drivers, we
>> should add the _is_cpu_device(dev) check to prevent this division-by-zero
>> issue.
>>
>> Fixes: <1b600da51073> ("PM: EM: Optimize em_cpu_energy() and remove 
>> division")
>> Signed-off-by: Yaxiong Tian <tianyaxiong@kylinos.cn>
>> ---
>>   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 d9b7e2b38c7a..d1fa7e8787b5 100644
>> --- a/kernel/power/energy_model.c
>> +++ b/kernel/power/energy_model.c
>> @@ -244,7 +244,7 @@ static int em_compute_costs(struct device *dev, 
>> struct em_perf_state *table,
>>                       cost, ret);
>>                   return -EINVAL;
>>               }
>> -        } else {
>> +        } else if (_is_cpu_device(dev)) {
>>               /* increase resolution of 'cost' precision */
>>               power_res = table[i].power * 10;
>>               cost = power_res / table[i].performance;
> 
> 
> As the test robot pointed out, please set the 'cost' to 0
> where it's declared.
> 
> The rest should be fine.
> 
> Regards,
> Lukasz

Sorry, the V3 version with cost=0 still has issues.

I noticed that if the cost is set to 0, the condition "if (table[i].cost
  >= prev_cost)" in the following code will always evaluate to true. This
  will incorrectly set the flags to EM_PERF_STATE_INEFFICIENT.

Should we change ">=" to ">"?







  parent reply	other threads:[~2025-04-15  1:12 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-11  1:28 Yaxiong Tian
2025-04-12  1:55 ` kernel test robot
2025-04-14  8:08 ` Lukasz Luba
2025-04-14  9:08   ` Yaxiong Tian
2025-04-17  7:20     ` Geert Uytterhoeven
2025-04-17  7:41       ` Yaxiong Tian
2025-04-15  1:12   ` Yaxiong Tian [this message]
2025-04-15  1:58     ` Yaxiong Tian
2025-04-15 17:19       ` Rafael J. Wysocki
2025-04-14  9:04 ` [PATCH v3] " Yaxiong Tian
2025-04-15  8:50   ` Lukasz Luba
2025-04-15 17:17   ` Rafael J. Wysocki
2025-04-16  2:56     ` Yaxiong Tian
2025-04-16 11:58       ` Rafael J. Wysocki
2025-04-16 15:26         ` Lukasz Luba
2025-04-17  0:56         ` Yaxiong Tian
2025-04-17  1:07 ` [PATCH v4] " Yaxiong Tian
2025-04-17  5:57   ` Lukasz Luba
2025-04-17  7:43     ` Yaxiong Tian
2025-04-17 13:27       ` Lukasz Luba
2025-04-18  1:26         ` Yaxiong Tian
2025-04-28  1:45           ` Yaxiong Tian

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_AE7CE43CDAD6747AFF0E952C8D0908A98D0A@qq.com \
    --to=iambestgod@qq.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lukasz.luba@arm.com \
    --cc=rafael@kernel.org \
    --cc=tianyaxiong@kylinos.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®