diff options
| author | Gautham R. Shenoy <ego@linux.vnet.ibm.com> | 2019-03-08 10:33:24 -0500 |
|---|---|---|
| committer | Michael Ellerman <mpe@ellerman.id.au> | 2019-03-26 19:40:09 -0400 |
| commit | ce9afe08e71e3f7d64f337a6e932e50849230fc2 (patch) | |
| tree | 635284ce4f44c79dbe34d76d0d20d7d57a0ddd37 | |
| parent | d9470757398a700d9450a43508000bcfd010c7a4 (diff) | |
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: e83636ac3334 ("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>
| -rw-r--r-- | arch/powerpc/platforms/pseries/pseries_energy.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/arch/powerpc/platforms/pseries/pseries_energy.c b/arch/powerpc/platforms/pseries/pseries_energy.c index 6ed22127391b..921f12182f3e 100644 --- a/arch/powerpc/platforms/pseries/pseries_energy.c +++ b/arch/powerpc/platforms/pseries/pseries_energy.c | |||
| @@ -77,18 +77,27 @@ static u32 cpu_to_drc_index(int cpu) | |||
| 77 | 77 | ||
| 78 | ret = drc.drc_index_start + (thread_index * drc.sequential_inc); | 78 | ret = drc.drc_index_start + (thread_index * drc.sequential_inc); |
| 79 | } else { | 79 | } else { |
| 80 | const __be32 *indexes; | 80 | u32 nr_drc_indexes, thread_drc_index; |
| 81 | |||
| 82 | indexes = of_get_property(dn, "ibm,drc-indexes", NULL); | ||
| 83 | if (indexes == NULL) | ||
| 84 | goto err_of_node_put; | ||
| 85 | 81 | ||
| 86 | /* | 82 | /* |
| 87 | * The first element indexes[0] is the number of drc_indexes | 83 | * The first element of ibm,drc-indexes array is the |
| 88 | * returned in the list. Hence thread_index+1 will get the | 84 | * number of drc_indexes returned in the list. Hence |
| 89 | * drc_index corresponding to core number thread_index. | 85 | * thread_index+1 will get the drc_index corresponding |
| 86 | * to core number thread_index. | ||
| 90 | */ | 87 | */ |
| 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; | ||
| 92 | } | 101 | } |
| 93 | 102 | ||
| 94 | rc = 0; | 103 | rc = 0; |
