Skip to content

Commit 0654acd

Browse files
Dawei Lirafaeljw
authored andcommitted
powercap: DTPM: Avoid explicit cpumask allocation on stack
In general it's preferable to avoid placing cpumasks on the stack, as for large values of NR_CPUS these can consume significant amounts of stack space and make stack overflows more likely. Use cpumask_weight_and() to avoid the need for a temporary cpumask on the stack. Signed-off-by: Dawei Li <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 0bbac3f commit 0654acd

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

drivers/powercap/dtpm_cpu.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,11 @@ static u64 set_pd_power_limit(struct dtpm *dtpm, u64 power_limit)
4343
struct dtpm_cpu *dtpm_cpu = to_dtpm_cpu(dtpm);
4444
struct em_perf_domain *pd = em_cpu_get(dtpm_cpu->cpu);
4545
struct em_perf_state *table;
46-
struct cpumask cpus;
4746
unsigned long freq;
4847
u64 power;
4948
int i, nr_cpus;
5049

51-
cpumask_and(&cpus, cpu_online_mask, to_cpumask(pd->cpus));
52-
nr_cpus = cpumask_weight(&cpus);
50+
nr_cpus = cpumask_weight_and(cpu_online_mask, to_cpumask(pd->cpus));
5351

5452
rcu_read_lock();
5553
table = em_perf_state_from_pd(pd);
@@ -123,11 +121,9 @@ static int update_pd_power_uw(struct dtpm *dtpm)
123121
struct dtpm_cpu *dtpm_cpu = to_dtpm_cpu(dtpm);
124122
struct em_perf_domain *em = em_cpu_get(dtpm_cpu->cpu);
125123
struct em_perf_state *table;
126-
struct cpumask cpus;
127124
int nr_cpus;
128125

129-
cpumask_and(&cpus, cpu_online_mask, to_cpumask(em->cpus));
130-
nr_cpus = cpumask_weight(&cpus);
126+
nr_cpus = cpumask_weight_and(cpu_online_mask, to_cpumask(em->cpus));
131127

132128
rcu_read_lock();
133129
table = em_perf_state_from_pd(em);

0 commit comments

Comments
 (0)