cpufreq: Fix policy->freq_table is NULL in __cpufreq_driver_target()
PATCH 1/1 cpufreq: Fix policy->freq_table is NULL in __cpufreq_driver_target()
__resolve_freq() may be return target_freq if policy->freq_table is NULL. In this case, it should return -EINVAL before __target_index().
--- drivers/cpufreq/cpufreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/cpufreq.c +1 -1
@@ -2299,7 +2299,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,return cpufreq_driver->target (policy, target_freq, relation); } -if (!cpufreq_driver->target_index) +if (!cpufreq_driver->target_index || !policy->freq_table)return -EINVAL ;return __target_index (policy, policy->cached_resolved_idx);
Signature · 1 line
2.25.1
Rafael J. Wysocki
maintainerQuoted 3 lines · Yajun Deng
__resolve_freq()may be returntarget_freqifpolicy->freq_tableis NULL. In this case, it should return-EINVALbefore__target_index().
Even so, __target_index() itself doesn't dereference freq_table AFAICS, so arguably the driver should be prepared to deal with a NULL freq_table which comes from it after all.
Or, if you want to argue that drivers providing ->target_index() must also provide freq_table that is not NULL, a check to that effect needs to be done at the driver registration time IMO.
Quoted 19 lines
Signed-off-by Yajun Deng <[email protected]>--- drivers/cpufreq/cpufreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/cpufreq/cpufreq.c +1
-2@@ -2299,7 +2299,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,return cpufreq_driver->target (policy, target_freq, relation); } -if (!cpufreq_driver->target_index) +if (!cpufreq_driver->target_index || !policy->freq_table)return -EINVAL ;return __target_index (policy, policy->cached_resolved_idx); --
Quoted 9 lines · Rafael J. Wysocki
Quoted 2 lines · Yajun Deng
__resolve_freq()may be returntarget_freqifpolicy->freq_tableis NULL. In this case, it should return-EINVALbefore__target_index().Even so,
__target_index()itself doesn't dereferencefreq_tableAFAICS, so arguably the driver should be prepared to deal with a NULLfreq_tablewhich comes from it after all.
But there is a statement 'unsigned int newfreq = policy->freq_table[index].frequency;' in __target_index(), if driver doesn't provide freq_table, __target_index() will fault before the driver itself.
Quoted 23 lines
Or, if you want to argue that drivers providing ->target_index() must also provide
freq_tablethat is not NULL, a check to that effect needs to be done at the driver registration time IMO.Quoted 19 lines
Signed-off-by Yajun Deng <[email protected]>---
drivers/cpufreq/cpufreq.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/cpufreq/cpufreq.c +1
-2@@ -2299,7 +2299,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,return cpufreq_driver->target (policy, target_freq, relation); } -if (!cpufreq_driver->target_index) +if (!cpufreq_driver->target_index || !policy->freq_table)return -EINVAL ;return __target_index (policy, policy->cached_resolved_idx); --
Viresh Kumar
maintainerQuoted 7 lines · Yajun Deng
Quoted 5 lines · Rafael J. Wysocki
Quoted 2 lines · Yajun Deng
__resolve_freq()may be returntarget_freqifpolicy->freq_tableis NULL. In this case, it should return-EINVALbefore__target_index().
Quoted 8 lines
Quoted 4 lines
Even so,
__target_index()itself doesn't dereferencefreq_tableAFAICS, so arguably the driver should be prepared to deal with a NULLfreq_tablewhich comes from it after all.But there is a statement 'unsigned int newfreq = policy->freq_table[index].frequency;' in
__target_index(), if driver doesn't providefreq_table,__target_index()will fault before the driver itself.
Driver must provide a freq table here.
Signature · 1 line
viresh
Rafael J. Wysocki
maintainerQuoted 14 lines · Viresh Kumar
Quoted 12 lines · Yajun Deng
Quoted 9 lines · Rafael J. Wysocki
Quoted 2 lines · Yajun Deng
__resolve_freq()may be returntarget_freqifpolicy->freq_tableis NULL. In this case, it should return-EINVALbefore__target_index().Even so,
__target_index()itself doesn't dereferencefreq_tableAFAICS, so arguably the driver should be prepared to deal with a NULLfreq_tablewhich comes from it after all.
Quoted 5 lines
Quoted 3 lines
But there is a statement 'unsigned int newfreq = policy->freq_table[index].frequency;' in
__target_index(), if driver doesn't providefreq_table,__target_index()will fault before the driver itself.Driver must provide a freq table here.
OK, so let's do the check when the driver gets registered.
Viresh Kumar
maintainerQuoted 13 lines · Yajun Deng
__resolve_freq()may be returntarget_freqifpolicy->freq_tableis NULL. In this case, it should return-EINVALbefore__target_index().Signed-off-by Yajun Deng <[email protected]>--- drivers/cpufreq/cpufreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/cpufreq/cpufreq.c +0
-0
drivers/cpufreq/cpufreq.c int __cpufreq_driver_target(struct cpufreq_policy *policy, · line 2303
Quoted 6 lines
drivers/cpufreq/cpufreq.c +1
-1@@ -2299,7 +2299,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,return cpufreq_driver->target (policy, target_freq, relation); } -if (!cpufreq_driver->target_index) +if (!cpufreq_driver->target_index || !policy->freq_table)return -EINVAL ;
Hi,
I have sent an alternate patch [1] for this, please try it.
Signature · 3 lines
viresh [1] https://lore.kernel.org/all/53d4ed4e5b18a59a48790434f8146fb207e11c49.1680494945.git.viresh.kumar@linaro.org/
Quoted 18 lines · Viresh Kumar
Quoted 16 lines · Yajun Deng
__resolve_freq()may be returntarget_freqifpolicy->freq_tableis NULL. In this case, it should return-EINVALbefore__target_index().Signed-off-by Yajun Deng <[email protected]>---
drivers/cpufreq/cpufreq.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/cpufreq/cpufreq.c +0
-0@@ -2299,7 +2299,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,return cpufreq_driver->target (policy, target_freq, relation); }
Quoted 8 lines
drivers/cpufreq/cpufreq.c int __cpufreq_driver_target(struct cpufreq_policy *policy, · line 2303
Quoted 3 lines
drivers/cpufreq/cpufreq.c +1
-1-if (!cpufreq_driver->target_index) +if (!cpufreq_driver->target_index || !policy->freq_table)return -EINVAL ;Hi,
I have sent an alternate patch [1] for this, please try it.
Thanks, v2 is fine.
Quoted 6 lines
--
viresh[1]
https://lore.kernel.org/all/53d4ed4e5b18a59a48790434f8146fb207e11c49.1680494945.git.viresh.kumar@lin
ro.org