drivers/cpufreq/freq_table.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
The cpufreq documentation suggests avoiding direct pointer subtraction
when working with entries in driver_freq_table, as it is relatively
costly. Instead, the recommended approach is to use the provided
iteration macros:
- cpufreq_for_each_valid_entry_idx()
Replace pointer subtraction in freq_table.c with the macros
cpufreq_for_each_entry_idx() and cpufreq_for_each_valid_entry_idx(), as
the index does not need initialization, avoiding unnecessary
computation. This improves code clarity and follows the established
cpufreq coding style.
No functional change intended.
Signed-off-by: Zihuan Zhang <zhangzihuan@kylinos.cn>
V2:
- Remove unnecessary initialization for current and remaining follow Rafael's suggestion
---
drivers/cpufreq/freq_table.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/cpufreq/freq_table.c b/drivers/cpufreq/freq_table.c
index d5111ee56e38..408fd8fee2e3 100644
--- a/drivers/cpufreq/freq_table.c
+++ b/drivers/cpufreq/freq_table.c
@@ -33,16 +33,17 @@ int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy)
struct cpufreq_frequency_table *pos, *table = policy->freq_table;
unsigned int min_freq = ~0;
unsigned int max_freq = 0;
+ unsigned int i;
unsigned int freq;
- cpufreq_for_each_valid_entry(pos, table) {
+ cpufreq_for_each_valid_entry_idx(pos, table, i) {
freq = pos->frequency;
if ((!cpufreq_boost_enabled() || !policy->boost_enabled)
&& (pos->flags & CPUFREQ_BOOST_FREQ))
continue;
- pr_debug("table entry %u: %u kHz\n", (int)(pos - table), freq);
+ pr_debug("table entry %u: %u kHz\n", i, freq);
if (freq < min_freq)
min_freq = freq;
if (freq > max_freq)
@@ -126,7 +127,7 @@ int cpufreq_table_index_unsorted(struct cpufreq_policy *policy,
};
struct cpufreq_frequency_table *pos;
struct cpufreq_frequency_table *table = policy->freq_table;
- unsigned int freq, diff, i = 0;
+ unsigned int freq, diff, i;
int index;
pr_debug("request for target %u kHz (relation: %u) for cpu %u\n",
--
2.25.1
On Sep 23, 2025 at 15:55:53 +0800, Zihuan Zhang wrote: > The cpufreq documentation suggests avoiding direct pointer subtraction > when working with entries in driver_freq_table, as it is relatively > costly. Instead, the recommended approach is to use the provided > iteration macros: Thanks for the patch, Just say "macro" not "macros". > > - cpufreq_for_each_valid_entry_idx() > > Replace pointer subtraction in freq_table.c with the macros > cpufreq_for_each_entry_idx() and cpufreq_for_each_valid_entry_idx(), as Where is "cpufreq_for_each_entry_idx" in this entire patch? Please drop this reference, why confuse people? > the index does not need initialization, avoiding unnecessary > computation. This improves code clarity and follows the established > cpufreq coding style. You don't need to add all this to the commit message about the unnecessary computation, code clarity, etc.. Please keep it to the point. > > No functional change intended. > > Signed-off-by: Zihuan Zhang <zhangzihuan@kylinos.cn> > > V2: > - Remove unnecessary initialization for current and remaining follow Rafael's suggestion You didn't fix Rafael's first comment [1] about the $subject, and also please add links to previous revisions for ease of review. [1] > In the subject, this is just one macro, not multiple macros. > --- > drivers/cpufreq/freq_table.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/drivers/cpufreq/freq_table.c b/drivers/cpufreq/freq_table.c > index d5111ee56e38..408fd8fee2e3 100644 > --- a/drivers/cpufreq/freq_table.c > +++ b/drivers/cpufreq/freq_table.c > @@ -33,16 +33,17 @@ int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy) > struct cpufreq_frequency_table *pos, *table = policy->freq_table; > unsigned int min_freq = ~0; > unsigned int max_freq = 0; > + unsigned int i; > unsigned int freq; > > - cpufreq_for_each_valid_entry(pos, table) { > + cpufreq_for_each_valid_entry_idx(pos, table, i) { > freq = pos->frequency; > > if ((!cpufreq_boost_enabled() || !policy->boost_enabled) > && (pos->flags & CPUFREQ_BOOST_FREQ)) > continue; > > - pr_debug("table entry %u: %u kHz\n", (int)(pos - table), freq); > + pr_debug("table entry %u: %u kHz\n", i, freq); > if (freq < min_freq) > min_freq = freq; > if (freq > max_freq) > @@ -126,7 +127,7 @@ int cpufreq_table_index_unsorted(struct cpufreq_policy *policy, > }; > struct cpufreq_frequency_table *pos; > struct cpufreq_frequency_table *table = policy->freq_table; > - unsigned int freq, diff, i = 0; > + unsigned int freq, diff, i; > int index; Usually, it isn't advised to touch code that's not strictly relevant to your patch. However since this seems like a minor fixup it's fine by me... Upto Rafael whether he prefers to have/not have this unrelated change. But atleast mention in your commit message that you're also removing the initialization from cpufreq_table_index_unsorted as part of some minor cleanup (which seems kinda unnecessary to me TBH in the first place) -- Best regards, Dhruva Gole Texas Instruments Incorporated
在 2025/9/23 17:09, Dhruva Gole 写道: > > Usually, it isn't advised to touch code that's not strictly relevant to > your patch. However since this seems like a minor fixup it's fine by > me... Upto Rafael whether he prefers to have/not have this unrelated change. > > But atleast mention in your commit message that you're also removing the > initialization from cpufreq_table_index_unsorted as part of some minor cleanup > (which seems kinda unnecessary to me TBH in the first place) > Thank you all !
On Tue, Sep 23, 2025 at 11:09 AM Dhruva Gole <d-gole@ti.com> wrote: > > On Sep 23, 2025 at 15:55:53 +0800, Zihuan Zhang wrote: > > The cpufreq documentation suggests avoiding direct pointer subtraction > > when working with entries in driver_freq_table, as it is relatively > > costly. Instead, the recommended approach is to use the provided > > iteration macros: > > Thanks for the patch, > Just say "macro" not "macros". > > > > > - cpufreq_for_each_valid_entry_idx() > > > > Replace pointer subtraction in freq_table.c with the macros > > cpufreq_for_each_entry_idx() and cpufreq_for_each_valid_entry_idx(), as > > Where is "cpufreq_for_each_entry_idx" in this entire patch? > Please drop this reference, why confuse people? > > > the index does not need initialization, avoiding unnecessary > > computation. This improves code clarity and follows the established > > cpufreq coding style. > > You don't need to add all this to the commit message about the > unnecessary computation, code clarity, etc.. > Please keep it to the point. > > > > > No functional change intended. > > > > Signed-off-by: Zihuan Zhang <zhangzihuan@kylinos.cn> > > > > V2: > > - Remove unnecessary initialization for current and remaining follow Rafael's suggestion > > You didn't fix Rafael's first comment [1] about the $subject, and also please > add links to previous revisions for ease of review. > > [1] > In the subject, this is just one macro, not multiple macros. @Dhruva, thanks for the review! I've fixed up the shortcomings pointed out above and applied the patch as 6.18 material. > > --- > > drivers/cpufreq/freq_table.c | 7 ++++--- > > 1 file changed, 4 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/cpufreq/freq_table.c b/drivers/cpufreq/freq_table.c > > index d5111ee56e38..408fd8fee2e3 100644 > > --- a/drivers/cpufreq/freq_table.c > > +++ b/drivers/cpufreq/freq_table.c > > @@ -33,16 +33,17 @@ int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy) > > struct cpufreq_frequency_table *pos, *table = policy->freq_table; > > unsigned int min_freq = ~0; > > unsigned int max_freq = 0; > > + unsigned int i; > > unsigned int freq; > > > > - cpufreq_for_each_valid_entry(pos, table) { > > + cpufreq_for_each_valid_entry_idx(pos, table, i) { > > freq = pos->frequency; > > > > if ((!cpufreq_boost_enabled() || !policy->boost_enabled) > > && (pos->flags & CPUFREQ_BOOST_FREQ)) > > continue; > > > > - pr_debug("table entry %u: %u kHz\n", (int)(pos - table), freq); > > + pr_debug("table entry %u: %u kHz\n", i, freq); > > if (freq < min_freq) > > min_freq = freq; > > if (freq > max_freq) > > @@ -126,7 +127,7 @@ int cpufreq_table_index_unsorted(struct cpufreq_policy *policy, > > }; > > struct cpufreq_frequency_table *pos; > > struct cpufreq_frequency_table *table = policy->freq_table; > > - unsigned int freq, diff, i = 0; > > + unsigned int freq, diff, i; > > int index; > > Usually, it isn't advised to touch code that's not strictly relevant to > your patch. However since this seems like a minor fixup it's fine by > me... Upto Rafael whether he prefers to have/not have this unrelated change. > > But atleast mention in your commit message that you're also removing the > initialization from cpufreq_table_index_unsorted as part of some minor cleanup > (which seems kinda unnecessary to me TBH in the first place) Yeah, better to say about things like this in the patch changelog. I've fixed that too.
© 2016 - 2025 Red Hat, Inc.