Skip to content

Commit aa90ac4

Browse files
committed
firmware: arm_scmi: Use {get,put}_unaligned_le{32,64} accessors
Instead of type-casting the {tx,rx}.buf all over the place while accessing them to read/write __le{32,64} from/to the firmware, let's use the existing {get,put}_unaligned_le{32,64} accessors to hide all the type cast ugliness. Suggested-by: Philipp Zabel <[email protected]> Reviewed-by: Philipp Zabel <[email protected]> Signed-off-by: Sudeep Holla <[email protected]>
1 parent 2bc06ff commit aa90ac4

File tree

6 files changed

+20
-27
lines changed

6 files changed

+20
-27
lines changed

drivers/firmware/arm_scmi/base.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ static int scmi_base_discover_agent_get(const struct scmi_handle *handle,
204204
if (ret)
205205
return ret;
206206

207-
*(__le32 *)t->tx.buf = cpu_to_le32(id);
207+
put_unaligned_le32(id, t->tx.buf);
208208

209209
ret = scmi_do_xfer(handle, t);
210210
if (!ret)

drivers/firmware/arm_scmi/clock.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static int scmi_clock_attributes_get(const struct scmi_handle *handle,
107107
if (ret)
108108
return ret;
109109

110-
*(__le32 *)t->tx.buf = cpu_to_le32(clk_id);
110+
put_unaligned_le32(clk_id, t->tx.buf);
111111
attr = t->rx.buf;
112112

113113
ret = scmi_do_xfer(handle, t);
@@ -204,15 +204,11 @@ scmi_clock_rate_get(const struct scmi_handle *handle, u32 clk_id, u64 *value)
204204
if (ret)
205205
return ret;
206206

207-
*(__le32 *)t->tx.buf = cpu_to_le32(clk_id);
207+
put_unaligned_le32(clk_id, t->tx.buf);
208208

209209
ret = scmi_do_xfer(handle, t);
210-
if (!ret) {
211-
__le32 *pval = t->rx.buf;
212-
213-
*value = le32_to_cpu(*pval);
214-
*value |= (u64)le32_to_cpu(*(pval + 1)) << 32;
215-
}
210+
if (!ret)
211+
*value = get_unaligned_le64(t->rx.buf);
216212

217213
scmi_xfer_put(handle, t);
218214
return ret;

drivers/firmware/arm_scmi/common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <linux/scmi_protocol.h>
1616
#include <linux/types.h>
1717

18+
#include <asm/unaligned.h>
19+
1820
#define PROTOCOL_REV_MINOR_MASK GENMASK(15, 0)
1921
#define PROTOCOL_REV_MAJOR_MASK GENMASK(31, 16)
2022
#define PROTOCOL_REV_MAJOR(x) (u16)(FIELD_GET(PROTOCOL_REV_MAJOR_MASK, (x)))

drivers/firmware/arm_scmi/perf.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ scmi_perf_domain_attributes_get(const struct scmi_handle *handle, u32 domain,
151151
if (ret)
152152
return ret;
153153

154-
*(__le32 *)t->tx.buf = cpu_to_le32(domain);
154+
put_unaligned_le32(domain, t->tx.buf);
155155
attr = t->rx.buf;
156156

157157
ret = scmi_do_xfer(handle, t);
@@ -284,7 +284,7 @@ static int scmi_perf_limits_get(const struct scmi_handle *handle, u32 domain,
284284
if (ret)
285285
return ret;
286286

287-
*(__le32 *)t->tx.buf = cpu_to_le32(domain);
287+
put_unaligned_le32(domain, t->tx.buf);
288288

289289
ret = scmi_do_xfer(handle, t);
290290
if (!ret) {
@@ -333,11 +333,11 @@ static int scmi_perf_level_get(const struct scmi_handle *handle, u32 domain,
333333
return ret;
334334

335335
t->hdr.poll_completion = poll;
336-
*(__le32 *)t->tx.buf = cpu_to_le32(domain);
336+
put_unaligned_le32(domain, t->tx.buf);
337337

338338
ret = scmi_do_xfer(handle, t);
339339
if (!ret)
340-
*level = le32_to_cpu(*(__le32 *)t->rx.buf);
340+
*level = get_unaligned_le32(t->rx.buf);
341341

342342
scmi_xfer_put(handle, t);
343343
return ret;

drivers/firmware/arm_scmi/power.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ scmi_power_domain_attributes_get(const struct scmi_handle *handle, u32 domain,
9696
if (ret)
9797
return ret;
9898

99-
*(__le32 *)t->tx.buf = cpu_to_le32(domain);
99+
put_unaligned_le32(domain, t->tx.buf);
100100
attr = t->rx.buf;
101101

102102
ret = scmi_do_xfer(handle, t);
@@ -147,11 +147,11 @@ scmi_power_state_get(const struct scmi_handle *handle, u32 domain, u32 *state)
147147
if (ret)
148148
return ret;
149149

150-
*(__le32 *)t->tx.buf = cpu_to_le32(domain);
150+
put_unaligned_le32(domain, t->tx.buf);
151151

152152
ret = scmi_do_xfer(handle, t);
153153
if (!ret)
154-
*state = le32_to_cpu(*(__le32 *)t->rx.buf);
154+
*state = get_unaligned_le32(t->rx.buf);
155155

156156
scmi_xfer_put(handle, t);
157157
return ret;

drivers/firmware/arm_scmi/sensors.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ static int scmi_sensor_description_get(const struct scmi_handle *handle,
120120

121121
do {
122122
/* Set the number of sensors to be skipped/already read */
123-
*(__le32 *)t->tx.buf = cpu_to_le32(desc_index);
123+
put_unaligned_le32(desc_index, t->tx.buf);
124124

125125
ret = scmi_do_xfer(handle, t);
126126
if (ret)
@@ -217,7 +217,6 @@ static int scmi_sensor_reading_get(const struct scmi_handle *handle,
217217
u32 sensor_id, u64 *value)
218218
{
219219
int ret;
220-
__le32 *pval;
221220
struct scmi_xfer *t;
222221
struct scmi_msg_sensor_reading_get *sensor;
223222
struct sensors_info *si = handle->sensor_priv;
@@ -229,24 +228,20 @@ static int scmi_sensor_reading_get(const struct scmi_handle *handle,
229228
if (ret)
230229
return ret;
231230

232-
pval = t->rx.buf;
233231
sensor = t->tx.buf;
234232
sensor->id = cpu_to_le32(sensor_id);
235233

236234
if (s->async) {
237235
sensor->flags = cpu_to_le32(SENSOR_READ_ASYNC);
238236
ret = scmi_do_xfer_with_response(handle, t);
239-
if (!ret) {
240-
*value = le32_to_cpu(*(pval + 1));
241-
*value |= (u64)le32_to_cpu(*(pval + 2)) << 32;
242-
}
237+
if (!ret)
238+
*value = get_unaligned_le64((void *)
239+
((__le32 *)t->rx.buf + 1));
243240
} else {
244241
sensor->flags = cpu_to_le32(0);
245242
ret = scmi_do_xfer(handle, t);
246-
if (!ret) {
247-
*value = le32_to_cpu(*pval);
248-
*value |= (u64)le32_to_cpu(*(pval + 1)) << 32;
249-
}
243+
if (!ret)
244+
*value = get_unaligned_le64(t->rx.buf);
250245
}
251246

252247
scmi_xfer_put(handle, t);

0 commit comments

Comments
 (0)