Skip to content

Commit 1e9a825

Browse files
samitolvanenThierry Strudel
authored andcommitted
drivers: htc_radio: fix unaligned __iomem reads
Bug: 64527440 Bug: 62093296 Change-Id: I0b6a55f28a9fc1094af07b7708d42f420718aa02 Signed-off-by: Sami Tolvanen <[email protected]>
1 parent e844968 commit 1e9a825

File tree

2 files changed

+42
-37
lines changed

2 files changed

+42
-37
lines changed

drivers/htc_radio/htc_radio_smem.c

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,20 @@
2121
#include <linux/fs.h>
2222
#include <linux/of.h>
2323
#include <linux/ctype.h>
24+
#include <asm/io.h>
2425
#include "htc_radio_smem.h"
2526
#include <soc/qcom/smem.h>
2627

2728
#define DEVICE_TREE_RADIO_PATH "/chosen/radio"
2829

29-
static void smem_init(struct htc_smem_type *smem)
30-
{
31-
int i = 0;
32-
33-
smem->version = 0;
34-
smem->struct_size = 0;
35-
smem->htc_smem_pid = 0;
36-
smem->htc_smem_app_run_mode = 0;
37-
smem->htc_smem_flag = 0;
38-
smem->htc_smem_factory_reset = 0;
39-
40-
for (i = 0; i < sizeof(smem->htc_rom_ver); i++)
41-
smem->htc_rom_ver[i] = 0;
42-
43-
for (i = 0; i < sizeof(smem->htc_smem_skuid); i++)
44-
smem->htc_smem_skuid[i] = 0;
45-
46-
for (i = 0; i < sizeof(smem->reserved); i++)
47-
smem->reserved[i] = 0;
48-
}
49-
5030
static int htc_radio_smem_probe(struct platform_device *pdev)
5131
{
5232
int ret = -1;
5333
struct device_node *dnp;
5434
struct htc_smem_type *htc_radio_smem;
35+
u32 value;
36+
u8 buffer[max(sizeof(htc_radio_smem->htc_rom_ver),
37+
sizeof(htc_radio_smem->htc_smem_skuid))];
5538

5639
pr_info("[smem]%s: start.\n", __func__);
5740

@@ -68,28 +51,37 @@ static int htc_radio_smem_probe(struct platform_device *pdev)
6851
return ret;
6952
}
7053

71-
/* set smem init 0 */
72-
smem_init(htc_radio_smem);
54+
/* set smem to 0 */
55+
memset_io(htc_radio_smem, 0, sizeof(*htc_radio_smem));
7356

7457
/* get smem data from radio data note */
7558
dnp = of_find_node_by_path(DEVICE_TREE_RADIO_PATH);
7659
if (dnp) {
77-
htc_radio_smem->version = HTC_RADIO_SMEM_VERSION;
78-
htc_radio_smem->struct_size = sizeof(struct htc_smem_type);
79-
of_property_read_u32(dnp, "htc_smem_radio_dbg_flag",
80-
&htc_radio_smem->htc_smem_flag);
81-
of_property_read_u32(dnp, "htc_smem_app_run_mode",
82-
&htc_radio_smem->htc_smem_app_run_mode);
83-
of_property_read_u32(dnp, "htc_smem_pid",
84-
&htc_radio_smem->htc_smem_pid);
85-
of_property_read_u32(dnp, "htc_smem_factory_reset",
86-
&htc_radio_smem->htc_smem_factory_reset);
87-
of_property_read_u8_array(dnp, "htc_rom_ver",
88-
&htc_radio_smem->htc_rom_ver[0],
60+
htc_smem_set_u32(htc_radio_smem, version,
61+
HTC_RADIO_SMEM_VERSION);
62+
htc_smem_set_u32(htc_radio_smem, struct_size,
63+
sizeof(struct htc_smem_type));
64+
65+
of_property_read_u32(dnp, "htc_smem_radio_dbg_flag", &value);
66+
htc_smem_set_u32(htc_radio_smem, htc_smem_flag, value);
67+
68+
of_property_read_u32(dnp, "htc_smem_app_run_mode", &value);
69+
htc_smem_set_u32(htc_radio_smem, htc_smem_app_run_mode, value);
70+
71+
of_property_read_u32(dnp, "htc_smem_pid", &value);
72+
htc_smem_set_u32(htc_radio_smem, htc_smem_pid, value);
73+
74+
of_property_read_u32(dnp, "htc_smem_factory_reset", &value);
75+
htc_smem_set_u32(htc_radio_smem, htc_smem_factory_reset,
76+
value);
77+
78+
of_property_read_u8_array(dnp, "htc_rom_ver", buffer,
8979
sizeof(htc_radio_smem->htc_rom_ver));
90-
of_property_read_u8_array(dnp, "sku_id",
91-
&htc_radio_smem->htc_smem_skuid[0],
80+
htc_smem_copy(htc_radio_smem, htc_rom_ver, buffer);
81+
82+
of_property_read_u8_array(dnp, "sku_id", buffer,
9283
sizeof(htc_radio_smem->htc_smem_skuid));
84+
htc_smem_copy(htc_radio_smem, htc_smem_skuid, buffer);
9385
} else
9486
pr_err("[smem]%s: cannot find path %s.\n", __func__,
9587
DEVICE_TREE_RADIO_PATH);

drivers/htc_radio/htc_radio_smem.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,17 @@ struct htc_smem_type {
3434
/* totally 2048 bytes */
3535
};
3636

37+
#define htc_smem_addr(smem, field) \
38+
({ \
39+
volatile void __iomem *__p = (smem); \
40+
__p += offsetof(typeof(*(smem)), field); \
41+
__p; \
42+
})
43+
44+
#define htc_smem_set_u32(p, field, value) \
45+
writel((value), htc_smem_addr((p), field))
46+
47+
#define htc_smem_copy(p, field, src) \
48+
memcpy_toio(htc_smem_addr((p), field), (src), sizeof((p)->field))
49+
3750
#endif /* end of _HTC_RADIO_SMEM_H */

0 commit comments

Comments
 (0)