Skip to content

Commit 914d6f4

Browse files
vlsunilpalmer-dabbelt
authored andcommitted
RISC-V: only iterate over possible CPUs in ISA string parser
During boot we call riscv_of_processor_hartid() for each hart that we add to the possible cpus list. Repeating the call again here is not required, if we iterate over the list of possible CPUs, rather than the list of all CPUs. The call to of_property_read_string() for "riscv,isa" cannot fail either, as it has previously succeeded in riscv_of_processor_hartid(), but leaving in the error checking makes the operation of the loop more obvious & provides leeway for future refactoring of riscv_of_processor_hartid(). Signed-off-by: Sunil V L <[email protected]> Co-developed-by: Conor Dooley <[email protected]> Signed-off-by: Conor Dooley <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent ce92546 commit 914d6f4

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

arch/riscv/kernel/cpufeature.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/memory.h>
1313
#include <linux/module.h>
1414
#include <linux/of.h>
15+
#include <linux/of_device.h>
1516
#include <asm/alternative.h>
1617
#include <asm/cacheflush.h>
1718
#include <asm/cpufeature.h>
@@ -99,7 +100,7 @@ void __init riscv_fill_hwcap(void)
99100
char print_str[NUM_ALPHA_EXTS + 1];
100101
int i, j, rc;
101102
unsigned long isa2hwcap[26] = {0};
102-
unsigned long hartid;
103+
unsigned int cpu;
103104

104105
isa2hwcap['i' - 'a'] = COMPAT_HWCAP_ISA_I;
105106
isa2hwcap['m' - 'a'] = COMPAT_HWCAP_ISA_M;
@@ -112,16 +113,20 @@ void __init riscv_fill_hwcap(void)
112113

113114
bitmap_zero(riscv_isa, RISCV_ISA_EXT_MAX);
114115

115-
for_each_of_cpu_node(node) {
116+
for_each_possible_cpu(cpu) {
116117
unsigned long this_hwcap = 0;
117118
DECLARE_BITMAP(this_isa, RISCV_ISA_EXT_MAX);
118119
const char *temp;
119120

120-
rc = riscv_of_processor_hartid(node, &hartid);
121-
if (rc < 0)
121+
node = of_cpu_device_node_get(cpu);
122+
if (!node) {
123+
pr_warn("Unable to find cpu node\n");
122124
continue;
125+
}
123126

124-
if (of_property_read_string(node, "riscv,isa", &isa)) {
127+
rc = of_property_read_string(node, "riscv,isa", &isa);
128+
of_node_put(node);
129+
if (rc) {
125130
pr_warn("Unable to find \"riscv,isa\" devicetree entry\n");
126131
continue;
127132
}

0 commit comments

Comments
 (0)