* [PATCH] PM: EM: Fix uninitialized power in em_create_perf_table
@ 2024-11-04 9:03 Jinjie Ruan
2024-11-04 9:14 ` Lukasz Luba
2024-11-04 9:15 ` Quentin Perret
0 siblings, 2 replies; 5+ messages in thread
From: Jinjie Ruan @ 2024-11-04 9:03 UTC (permalink / raw)
To: rafael, pavel, len.brown, daniel.lezcano, qperret, lukasz.luba,
linux-pm, linux-kernel
Cc: ruanjinjie
In em_create_perf_table(), power is uninitialized and passed the pointer
to active_power() hook, but the hook function may not assign it and
return 0, such as mtk_cpufreq_get_cpu_power(), so the later zero check for
power is not invalid, initialize power to zero to fix it.
Cc: stable@vger.kernel.org
Fixes: 7d9895c7fbfc ("PM / EM: introduce em_dev_register_perf_domain function")
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.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 927cc55ba0b3..866a3e9c05b2 100644
--- a/kernel/power/energy_model.c
+++ b/kernel/power/energy_model.c
@@ -344,7 +344,7 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd,
struct em_data_callback *cb,
unsigned long flags)
{
- unsigned long power, freq, prev_freq = 0;
+ unsigned long power = 0, freq, prev_freq = 0;
int nr_states = pd->nr_perf_states;
int i, ret;
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] PM: EM: Fix uninitialized power in em_create_perf_table
2024-11-04 9:03 [PATCH] PM: EM: Fix uninitialized power in em_create_perf_table Jinjie Ruan
@ 2024-11-04 9:14 ` Lukasz Luba
2024-11-04 9:16 ` Quentin Perret
2024-11-04 9:19 ` Jinjie Ruan
2024-11-04 9:15 ` Quentin Perret
1 sibling, 2 replies; 5+ messages in thread
From: Lukasz Luba @ 2024-11-04 9:14 UTC (permalink / raw)
To: Jinjie Ruan
Cc: rafael, pavel, len.brown, linux-pm, daniel.lezcano, linux-kernel,
qperret
Hi Jinjie,
On 11/4/24 09:03, Jinjie Ruan wrote:
> In em_create_perf_table(), power is uninitialized and passed the pointer
> to active_power() hook, but the hook function may not assign it and
> return 0, such as mtk_cpufreq_get_cpu_power(), so the later zero check for
Please fix the driver. I have checked that function. It must return
-EINVAL when the 'policy' is not found. We cannot progress with power=0.
> power is not invalid, initialize power to zero to fix it.
>
> Cc: stable@vger.kernel.org
> Fixes: 7d9895c7fbfc ("PM / EM: introduce em_dev_register_perf_domain function")
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.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 927cc55ba0b3..866a3e9c05b2 100644
> --- a/kernel/power/energy_model.c
> +++ b/kernel/power/energy_model.c
> @@ -344,7 +344,7 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd,
> struct em_data_callback *cb,
> unsigned long flags)
> {
> - unsigned long power, freq, prev_freq = 0;
> + unsigned long power = 0, freq, prev_freq = 0;
> int nr_states = pd->nr_perf_states;
> int i, ret;
>
This patch proposal is just a workaround.
When you send a patch to that MTK driver, I can review it for you so
please add me on CC.
Regards,
Lukasz
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] PM: EM: Fix uninitialized power in em_create_perf_table
2024-11-04 9:03 [PATCH] PM: EM: Fix uninitialized power in em_create_perf_table Jinjie Ruan
2024-11-04 9:14 ` Lukasz Luba
@ 2024-11-04 9:15 ` Quentin Perret
1 sibling, 0 replies; 5+ messages in thread
From: Quentin Perret @ 2024-11-04 9:15 UTC (permalink / raw)
To: Jinjie Ruan
Cc: rafael, pavel, len.brown, daniel.lezcano, lukasz.luba, linux-pm,
linux-kernel
Hi,
On Monday 04 Nov 2024 at 17:03:51 (+0800), Jinjie Ruan wrote:
> In em_create_perf_table(), power is uninitialized and passed the pointer
> to active_power() hook, but the hook function may not assign it and
> return 0, such as mtk_cpufreq_get_cpu_power(), so the later zero check for
> power is not invalid, initialize power to zero to fix it.
Sounds to me like a driver bug? We check the return value of
active_power() first, so if the callback failed it should tell us.
mtk_cpufreq_get_cpu_power() should only fail if we couldn't find a
cpufreq policy IIUC, so why can't this return -EINVAL instead?
Thanks,
Quentin
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] PM: EM: Fix uninitialized power in em_create_perf_table
2024-11-04 9:14 ` Lukasz Luba
@ 2024-11-04 9:16 ` Quentin Perret
2024-11-04 9:19 ` Jinjie Ruan
1 sibling, 0 replies; 5+ messages in thread
From: Quentin Perret @ 2024-11-04 9:16 UTC (permalink / raw)
To: Lukasz Luba
Cc: Jinjie Ruan, rafael, pavel, len.brown, linux-pm, daniel.lezcano,
linux-kernel
On Monday 04 Nov 2024 at 09:14:36 (+0000), Lukasz Luba wrote:
> Hi Jinjie,
>
> On 11/4/24 09:03, Jinjie Ruan wrote:
> > In em_create_perf_table(), power is uninitialized and passed the pointer
> > to active_power() hook, but the hook function may not assign it and
> > return 0, such as mtk_cpufreq_get_cpu_power(), so the later zero check for
>
> Please fix the driver. I have checked that function. It must return
> -EINVAL when the 'policy' is not found. We cannot progress with power=0.
>
>
> > power is not invalid, initialize power to zero to fix it.
> >
> > Cc: stable@vger.kernel.org
> > Fixes: 7d9895c7fbfc ("PM / EM: introduce em_dev_register_perf_domain function")
> > Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.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 927cc55ba0b3..866a3e9c05b2 100644
> > --- a/kernel/power/energy_model.c
> > +++ b/kernel/power/energy_model.c
> > @@ -344,7 +344,7 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd,
> > struct em_data_callback *cb,
> > unsigned long flags)
> > {
> > - unsigned long power, freq, prev_freq = 0;
> > + unsigned long power = 0, freq, prev_freq = 0;
> > int nr_states = pd->nr_perf_states;
> > int i, ret;
>
>
> This patch proposal is just a workaround.
>
> When you send a patch to that MTK driver, I can review it for you so
> please add me on CC.
We raced, but +1 to the above :-)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] PM: EM: Fix uninitialized power in em_create_perf_table
2024-11-04 9:14 ` Lukasz Luba
2024-11-04 9:16 ` Quentin Perret
@ 2024-11-04 9:19 ` Jinjie Ruan
1 sibling, 0 replies; 5+ messages in thread
From: Jinjie Ruan @ 2024-11-04 9:19 UTC (permalink / raw)
To: Lukasz Luba
Cc: rafael, pavel, len.brown, linux-pm, daniel.lezcano, linux-kernel,
qperret
On 2024/11/4 17:14, Lukasz Luba wrote:
> Hi Jinjie,
>
> On 11/4/24 09:03, Jinjie Ruan wrote:
>> In em_create_perf_table(), power is uninitialized and passed the pointer
>> to active_power() hook, but the hook function may not assign it and
>> return 0, such as mtk_cpufreq_get_cpu_power(), so the later zero check
>> for
>
> Please fix the driver. I have checked that function. It must return
> -EINVAL when the 'policy' is not found. We cannot progress with power=0.
Thank you very much! It will be also good to fix the driver.
>
>
>> power is not invalid, initialize power to zero to fix it.
>>
>> Cc: stable@vger.kernel.org
>> Fixes: 7d9895c7fbfc ("PM / EM: introduce em_dev_register_perf_domain
>> function")
>> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.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 927cc55ba0b3..866a3e9c05b2 100644
>> --- a/kernel/power/energy_model.c
>> +++ b/kernel/power/energy_model.c
>> @@ -344,7 +344,7 @@ static int em_create_perf_table(struct device
>> *dev, struct em_perf_domain *pd,
>> struct em_data_callback *cb,
>> unsigned long flags)
>> {
>> - unsigned long power, freq, prev_freq = 0;
>> + unsigned long power = 0, freq, prev_freq = 0;
>> int nr_states = pd->nr_perf_states;
>> int i, ret;
>>
>
>
> This patch proposal is just a workaround.
>
> When you send a patch to that MTK driver, I can review it for you so
> please add me on CC.
>
> Regards,
> Lukasz
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-11-04 9:19 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-04 9:03 [PATCH] PM: EM: Fix uninitialized power in em_create_perf_table Jinjie Ruan
2024-11-04 9:14 ` Lukasz Luba
2024-11-04 9:16 ` Quentin Perret
2024-11-04 9:19 ` Jinjie Ruan
2024-11-04 9:15 ` Quentin Perret
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).