Skip to content

Commit

Permalink
drivers: htc_radio: fix unaligned __iomem reads
Browse files Browse the repository at this point in the history
Bug: 64527440
Bug: 62093296
Change-Id: I0b6a55f28a9fc1094af07b7708d42f420718aa02
Signed-off-by: Sami Tolvanen <[email protected]>
  • Loading branch information
samitolvanen authored and Thierry Strudel committed Aug 26, 2017
1 parent e844968 commit 1e9a825
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 37 deletions.
66 changes: 29 additions & 37 deletions drivers/htc_radio/htc_radio_smem.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,20 @@
#include <linux/fs.h>
#include <linux/of.h>
#include <linux/ctype.h>
#include <asm/io.h>
#include "htc_radio_smem.h"
#include <soc/qcom/smem.h>

#define DEVICE_TREE_RADIO_PATH "/chosen/radio"

static void smem_init(struct htc_smem_type *smem)
{
int i = 0;

smem->version = 0;
smem->struct_size = 0;
smem->htc_smem_pid = 0;
smem->htc_smem_app_run_mode = 0;
smem->htc_smem_flag = 0;
smem->htc_smem_factory_reset = 0;

for (i = 0; i < sizeof(smem->htc_rom_ver); i++)
smem->htc_rom_ver[i] = 0;

for (i = 0; i < sizeof(smem->htc_smem_skuid); i++)
smem->htc_smem_skuid[i] = 0;

for (i = 0; i < sizeof(smem->reserved); i++)
smem->reserved[i] = 0;
}

static int htc_radio_smem_probe(struct platform_device *pdev)
{
int ret = -1;
struct device_node *dnp;
struct htc_smem_type *htc_radio_smem;
u32 value;
u8 buffer[max(sizeof(htc_radio_smem->htc_rom_ver),
sizeof(htc_radio_smem->htc_smem_skuid))];

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

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

/* set smem init 0 */
smem_init(htc_radio_smem);
/* set smem to 0 */
memset_io(htc_radio_smem, 0, sizeof(*htc_radio_smem));

/* get smem data from radio data note */
dnp = of_find_node_by_path(DEVICE_TREE_RADIO_PATH);
if (dnp) {
htc_radio_smem->version = HTC_RADIO_SMEM_VERSION;
htc_radio_smem->struct_size = sizeof(struct htc_smem_type);
of_property_read_u32(dnp, "htc_smem_radio_dbg_flag",
&htc_radio_smem->htc_smem_flag);
of_property_read_u32(dnp, "htc_smem_app_run_mode",
&htc_radio_smem->htc_smem_app_run_mode);
of_property_read_u32(dnp, "htc_smem_pid",
&htc_radio_smem->htc_smem_pid);
of_property_read_u32(dnp, "htc_smem_factory_reset",
&htc_radio_smem->htc_smem_factory_reset);
of_property_read_u8_array(dnp, "htc_rom_ver",
&htc_radio_smem->htc_rom_ver[0],
htc_smem_set_u32(htc_radio_smem, version,
HTC_RADIO_SMEM_VERSION);
htc_smem_set_u32(htc_radio_smem, struct_size,
sizeof(struct htc_smem_type));

of_property_read_u32(dnp, "htc_smem_radio_dbg_flag", &value);
htc_smem_set_u32(htc_radio_smem, htc_smem_flag, value);

of_property_read_u32(dnp, "htc_smem_app_run_mode", &value);
htc_smem_set_u32(htc_radio_smem, htc_smem_app_run_mode, value);

of_property_read_u32(dnp, "htc_smem_pid", &value);
htc_smem_set_u32(htc_radio_smem, htc_smem_pid, value);

of_property_read_u32(dnp, "htc_smem_factory_reset", &value);
htc_smem_set_u32(htc_radio_smem, htc_smem_factory_reset,
value);

of_property_read_u8_array(dnp, "htc_rom_ver", buffer,
sizeof(htc_radio_smem->htc_rom_ver));
of_property_read_u8_array(dnp, "sku_id",
&htc_radio_smem->htc_smem_skuid[0],
htc_smem_copy(htc_radio_smem, htc_rom_ver, buffer);

of_property_read_u8_array(dnp, "sku_id", buffer,
sizeof(htc_radio_smem->htc_smem_skuid));
htc_smem_copy(htc_radio_smem, htc_smem_skuid, buffer);
} else
pr_err("[smem]%s: cannot find path %s.\n", __func__,
DEVICE_TREE_RADIO_PATH);
Expand Down
13 changes: 13 additions & 0 deletions drivers/htc_radio/htc_radio_smem.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,17 @@ struct htc_smem_type {
/* totally 2048 bytes */
};

#define htc_smem_addr(smem, field) \
({ \
volatile void __iomem *__p = (smem); \
__p += offsetof(typeof(*(smem)), field); \
__p; \
})

#define htc_smem_set_u32(p, field, value) \
writel((value), htc_smem_addr((p), field))

#define htc_smem_copy(p, field, src) \
memcpy_toio(htc_smem_addr((p), field), (src), sizeof((p)->field))

#endif /* end of _HTC_RADIO_SMEM_H */

0 comments on commit 1e9a825

Please sign in to comment.