Skip to content

Commit ce9afe0

Browse files
Gautham R. Shenoympe
authored andcommitted
powerpc/pseries/energy: Use OF accessor functions to read ibm,drc-indexes
In cpu_to_drc_index() in the case when FW_FEATURE_DRC_INFO is absent, we currently use of_read_property() to obtain the pointer to the array corresponding to the property "ibm,drc-indexes". The elements of this array are of type __be32, but are accessed without any conversion to the OS-endianness, which is buggy on a Little Endian OS. Fix this by using of_property_read_u32_index() accessor function to safely read the elements of the array. Fixes: e83636a ("pseries/drc-info: Search DRC properties for CPU indexes") Cc: stable@vger.kernel.org # v4.16+ Reported-by: Pavithra R. Prakash <pavrampu@in.ibm.com> Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com> Reviewed-by: Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com> [mpe: Make the WARN_ON a WARN_ON_ONCE so it's not retriggerable] Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent d947075 commit ce9afe0

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

arch/powerpc/platforms/pseries/pseries_energy.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,27 @@ static u32 cpu_to_drc_index(int cpu)
7777

7878
ret = drc.drc_index_start + (thread_index * drc.sequential_inc);
7979
} else {
80-
const __be32 *indexes;
81-
82-
indexes = of_get_property(dn, "ibm,drc-indexes", NULL);
83-
if (indexes == NULL)
84-
goto err_of_node_put;
80+
u32 nr_drc_indexes, thread_drc_index;
8581

8682
/*
87-
* The first element indexes[0] is the number of drc_indexes
88-
* returned in the list. Hence thread_index+1 will get the
89-
* drc_index corresponding to core number thread_index.
83+
* The first element of ibm,drc-indexes array is the
84+
* number of drc_indexes returned in the list. Hence
85+
* thread_index+1 will get the drc_index corresponding
86+
* to core number thread_index.
9087
*/
91-
ret = indexes[thread_index + 1];
88+
rc = of_property_read_u32_index(dn, "ibm,drc-indexes",
89+
0, &nr_drc_indexes);
90+
if (rc)
91+
goto err_of_node_put;
92+
93+
WARN_ON_ONCE(thread_index > nr_drc_indexes);
94+
rc = of_property_read_u32_index(dn, "ibm,drc-indexes",
95+
thread_index + 1,
96+
&thread_drc_index);
97+
if (rc)
98+
goto err_of_node_put;
99+
100+
ret = thread_drc_index;
92101
}
93102

94103
rc = 0;

0 commit comments

Comments
 (0)