Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <p.zabel@pengutronix.de>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>

+20 -27
+1 -1
drivers/firmware/arm_scmi/base.c
··· 204 204 if (ret) 205 205 return ret; 206 206 207 - *(__le32 *)t->tx.buf = cpu_to_le32(id); 207 + put_unaligned_le32(id, t->tx.buf); 208 208 209 209 ret = scmi_do_xfer(handle, t); 210 210 if (!ret)
+4 -8
drivers/firmware/arm_scmi/clock.c
··· 107 107 if (ret) 108 108 return ret; 109 109 110 - *(__le32 *)t->tx.buf = cpu_to_le32(clk_id); 110 + put_unaligned_le32(clk_id, t->tx.buf); 111 111 attr = t->rx.buf; 112 112 113 113 ret = scmi_do_xfer(handle, t); ··· 204 204 if (ret) 205 205 return ret; 206 206 207 - *(__le32 *)t->tx.buf = cpu_to_le32(clk_id); 207 + put_unaligned_le32(clk_id, t->tx.buf); 208 208 209 209 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); 216 212 217 213 scmi_xfer_put(handle, t); 218 214 return ret;
+2
drivers/firmware/arm_scmi/common.h
··· 15 15 #include <linux/scmi_protocol.h> 16 16 #include <linux/types.h> 17 17 18 + #include <asm/unaligned.h> 19 + 18 20 #define PROTOCOL_REV_MINOR_MASK GENMASK(15, 0) 19 21 #define PROTOCOL_REV_MAJOR_MASK GENMASK(31, 16) 20 22 #define PROTOCOL_REV_MAJOR(x) (u16)(FIELD_GET(PROTOCOL_REV_MAJOR_MASK, (x)))
+4 -4
drivers/firmware/arm_scmi/perf.c
··· 151 151 if (ret) 152 152 return ret; 153 153 154 - *(__le32 *)t->tx.buf = cpu_to_le32(domain); 154 + put_unaligned_le32(domain, t->tx.buf); 155 155 attr = t->rx.buf; 156 156 157 157 ret = scmi_do_xfer(handle, t); ··· 284 284 if (ret) 285 285 return ret; 286 286 287 - *(__le32 *)t->tx.buf = cpu_to_le32(domain); 287 + put_unaligned_le32(domain, t->tx.buf); 288 288 289 289 ret = scmi_do_xfer(handle, t); 290 290 if (!ret) { ··· 333 333 return ret; 334 334 335 335 t->hdr.poll_completion = poll; 336 - *(__le32 *)t->tx.buf = cpu_to_le32(domain); 336 + put_unaligned_le32(domain, t->tx.buf); 337 337 338 338 ret = scmi_do_xfer(handle, t); 339 339 if (!ret) 340 - *level = le32_to_cpu(*(__le32 *)t->rx.buf); 340 + *level = get_unaligned_le32(t->rx.buf); 341 341 342 342 scmi_xfer_put(handle, t); 343 343 return ret;
+3 -3
drivers/firmware/arm_scmi/power.c
··· 96 96 if (ret) 97 97 return ret; 98 98 99 - *(__le32 *)t->tx.buf = cpu_to_le32(domain); 99 + put_unaligned_le32(domain, t->tx.buf); 100 100 attr = t->rx.buf; 101 101 102 102 ret = scmi_do_xfer(handle, t); ··· 147 147 if (ret) 148 148 return ret; 149 149 150 - *(__le32 *)t->tx.buf = cpu_to_le32(domain); 150 + put_unaligned_le32(domain, t->tx.buf); 151 151 152 152 ret = scmi_do_xfer(handle, t); 153 153 if (!ret) 154 - *state = le32_to_cpu(*(__le32 *)t->rx.buf); 154 + *state = get_unaligned_le32(t->rx.buf); 155 155 156 156 scmi_xfer_put(handle, t); 157 157 return ret;
+6 -11
drivers/firmware/arm_scmi/sensors.c
··· 120 120 121 121 do { 122 122 /* 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); 124 124 125 125 ret = scmi_do_xfer(handle, t); 126 126 if (ret) ··· 217 217 u32 sensor_id, u64 *value) 218 218 { 219 219 int ret; 220 - __le32 *pval; 221 220 struct scmi_xfer *t; 222 221 struct scmi_msg_sensor_reading_get *sensor; 223 222 struct sensors_info *si = handle->sensor_priv; ··· 228 229 if (ret) 229 230 return ret; 230 231 231 - pval = t->rx.buf; 232 232 sensor = t->tx.buf; 233 233 sensor->id = cpu_to_le32(sensor_id); 234 234 235 235 if (s->async) { 236 236 sensor->flags = cpu_to_le32(SENSOR_READ_ASYNC); 237 237 ret = scmi_do_xfer_with_response(handle, t); 238 - if (!ret) { 239 - *value = le32_to_cpu(*(pval + 1)); 240 - *value |= (u64)le32_to_cpu(*(pval + 2)) << 32; 241 - } 238 + if (!ret) 239 + *value = get_unaligned_le64((void *) 240 + ((__le32 *)t->rx.buf + 1)); 242 241 } else { 243 242 sensor->flags = cpu_to_le32(0); 244 243 ret = scmi_do_xfer(handle, t); 245 - if (!ret) { 246 - *value = le32_to_cpu(*pval); 247 - *value |= (u64)le32_to_cpu(*(pval + 1)) << 32; 248 - } 244 + if (!ret) 245 + *value = get_unaligned_le64(t->rx.buf); 249 246 } 250 247 251 248 scmi_xfer_put(handle, t);