提交 43120576 编写于 作者: P Peter Maydell

hw/bt: Don't use cpu_to_*w() and *_to_cpup()

Don't use cpu_to_*w() and *_to_cpup() to do byte-swapped loads
and stores; instead use ld*_p() and st*_p() which correctly handle
misaligned accesses.

Bring the HNDL() macro into line with how we deal with
PARAMHANDLE(), by using cpu_to_le16() rather than an ifdef
HOST_WORDS_BIGENDIAN.
Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
Reviewed-by: NEric Blake <eblake@redhat.com>
Message-id: 1467908460-27048-3-git-send-email-peter.maydell@linaro.org
上级 b442642d
...@@ -426,11 +426,7 @@ static void bt_submit_raw_acl(struct bt_piconet_s *net, int length, uint8_t *dat ...@@ -426,11 +426,7 @@ static void bt_submit_raw_acl(struct bt_piconet_s *net, int length, uint8_t *dat
* be continuously allocated. We do it though, to preserve similar * be continuously allocated. We do it though, to preserve similar
* behaviour between hosts. Some things, like the BD_ADDR cannot be * behaviour between hosts. Some things, like the BD_ADDR cannot be
* preserved though (for example if a real hci is used). */ * preserved though (for example if a real hci is used). */
#ifdef HOST_WORDS_BIGENDIAN #define HNDL(raw) cpu_to_le16(raw)
# define HNDL(raw) bswap16(raw)
#else
# define HNDL(raw) (raw)
#endif
static const uint8_t bt_event_reserved_mask[8] = { static const uint8_t bt_event_reserved_mask[8] = {
0xff, 0x9f, 0xfb, 0xff, 0x07, 0x18, 0x00, 0x00, 0xff, 0x9f, 0xfb, 0xff, 0x07, 0x18, 0x00, 0x00,
...@@ -1504,8 +1500,8 @@ static void bt_submit_hci(struct HCIInfo *info, ...@@ -1504,8 +1500,8 @@ static void bt_submit_hci(struct HCIInfo *info,
return; return;
#define PARAM(cmd, param) (((cmd##_cp *) data)->param) #define PARAM(cmd, param) (((cmd##_cp *) data)->param)
#define PARAM16(cmd, param) le16_to_cpup(&PARAM(cmd, param)) #define PARAM16(cmd, param) lduw_le_p(&PARAM(cmd, param))
#define PARAMHANDLE(cmd) HNDL(PARAM(cmd, handle)) #define PARAMHANDLE(cmd) PARAM16(cmd, handle)
#define LENGTH_CHECK(cmd) if (length < sizeof(cmd##_cp)) goto short_hci #define LENGTH_CHECK(cmd) if (length < sizeof(cmd##_cp)) goto short_hci
/* Note: the supported commands bitmask in bt_hci_read_local_commands_rp /* Note: the supported commands bitmask in bt_hci_read_local_commands_rp
* needs to be updated every time a command is implemented here! */ * needs to be updated every time a command is implemented here! */
......
...@@ -526,9 +526,9 @@ static int l2cap_channel_config(struct l2cap_instance_s *l2cap, ...@@ -526,9 +526,9 @@ static int l2cap_channel_config(struct l2cap_instance_s *l2cap,
} }
/* MTU */ /* MTU */
val = le16_to_cpup((void *) opt->val); val = lduw_le_p(opt->val);
if (val < ch->min_mtu) { if (val < ch->min_mtu) {
cpu_to_le16w((void *) opt->val, ch->min_mtu); stw_le_p(opt->val, ch->min_mtu);
result = L2CAP_CONF_UNACCEPT; result = L2CAP_CONF_UNACCEPT;
break; break;
} }
...@@ -543,7 +543,7 @@ static int l2cap_channel_config(struct l2cap_instance_s *l2cap, ...@@ -543,7 +543,7 @@ static int l2cap_channel_config(struct l2cap_instance_s *l2cap,
} }
/* Flush Timeout */ /* Flush Timeout */
val = le16_to_cpup((void *) opt->val); val = lduw_le_p(opt->val);
if (val < 0x0001) { if (val < 0x0001) {
opt->val[0] = 0xff; opt->val[0] = 0xff;
opt->val[1] = 0xff; opt->val[1] = 0xff;
...@@ -987,7 +987,7 @@ static void l2cap_bframe_in(struct l2cap_chan_s *ch, uint16_t cid, ...@@ -987,7 +987,7 @@ static void l2cap_bframe_in(struct l2cap_chan_s *ch, uint16_t cid,
static void l2cap_iframe_in(struct l2cap_chan_s *ch, uint16_t cid, static void l2cap_iframe_in(struct l2cap_chan_s *ch, uint16_t cid,
const l2cap_hdr *hdr, int len) const l2cap_hdr *hdr, int len)
{ {
uint16_t fcs = le16_to_cpup((void *) (hdr->data + len - 2)); uint16_t fcs = lduw_le_p(hdr->data + len - 2);
if (len < 4) if (len < 4)
goto len_error; goto len_error;
...@@ -1002,7 +1002,7 @@ static void l2cap_iframe_in(struct l2cap_chan_s *ch, uint16_t cid, ...@@ -1002,7 +1002,7 @@ static void l2cap_iframe_in(struct l2cap_chan_s *ch, uint16_t cid,
/* TODO: Signal an error? */ /* TODO: Signal an error? */
return; return;
} }
l2cap_sframe_in(ch, le16_to_cpup((void *) hdr->data)); l2cap_sframe_in(ch, lduw_le_p(hdr->data));
return; return;
} }
...@@ -1022,7 +1022,7 @@ static void l2cap_iframe_in(struct l2cap_chan_s *ch, uint16_t cid, ...@@ -1022,7 +1022,7 @@ static void l2cap_iframe_in(struct l2cap_chan_s *ch, uint16_t cid,
if (len - 6 > ch->mps) if (len - 6 > ch->mps)
goto len_error; goto len_error;
ch->len_total = le16_to_cpup((void *) (hdr->data + 2)); ch->len_total = lduw_le_p(hdr->data + 2);
if (len >= 6 + ch->len_total) if (len >= 6 + ch->len_total)
goto seg_error; goto seg_error;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册