* [PATCH 2/4] sdp: Fix build errors due to unaligned memory access
2012-11-23 10:09 [PATCH 1/4] sap-u8500: Fix build errors due to unaligned memory access Szymon Janc
@ 2012-11-23 10:09 ` Szymon Janc
2012-11-23 10:09 ` [PATCH 3/4] monitor: " Szymon Janc
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Szymon Janc @ 2012-11-23 10:09 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This fix following compilation errors on ARM.
CC lib/sdp.lo
lib/sdp.c: In function 'sdp_device_record_unregister_binary':
lib/sdp.c:2984:11: error: cast increases required alignment of
target type [-Werror=cast-align]
lib/sdp.c:2984:11: error: cast increases required alignment of
target type [-Werror=cast-align]
lib/sdp.c: In function 'sdp_device_record_update':
lib/sdp.c:3089:11: error: cast increases required alignment of
target type [-Werror=cast-align]
lib/sdp.c:3089:11: error: cast increases required alignment of
target type [-Werror=cast-align]
lib/sdp.c: In function 'sdp_process':
lib/sdp.c:4139:22: error: cast increases required alignment of
target type [-Werror=cast-align]
lib/sdp.c:4146:14: error: cast increases required alignment of
target type [-Werror=cast-align]
lib/sdp.c:4146:14: error: cast increases required alignment of
target type [-Werror=cast-align]
cc1: all warnings being treated as errors
make[1]: *** [lib/sdp.lo] Error 1
---
lib/sdp.c | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/lib/sdp.c b/lib/sdp.c
index ceb1192..4e070b5 100644
--- a/lib/sdp.c
+++ b/lib/sdp.c
@@ -2981,7 +2981,6 @@ int sdp_device_record_unregister_binary(sdp_session_t *session, bdaddr_t *device
rsphdr = (sdp_pdu_hdr_t *) rspbuf;
p = rspbuf + sizeof(sdp_pdu_hdr_t);
- status = bt_get_unaligned((uint16_t *) p);
if (rsphdr->pdu_id == SDP_ERROR_RSP) {
/* For this case the status always is invalid record handle */
@@ -2990,6 +2989,12 @@ int sdp_device_record_unregister_binary(sdp_session_t *session, bdaddr_t *device
} else if (rsphdr->pdu_id != SDP_SVC_REMOVE_RSP) {
errno = EPROTO;
status = -1;
+ } else {
+ uint16_t tmp;
+
+ memcpy(&tmp, p, sizeof(tmp));
+
+ status = tmp;
}
end:
free(reqbuf);
@@ -3086,7 +3091,6 @@ int sdp_device_record_update(sdp_session_t *session, bdaddr_t *device, const sdp
rsphdr = (sdp_pdu_hdr_t *) rspbuf;
p = rspbuf + sizeof(sdp_pdu_hdr_t);
- status = bt_get_unaligned((uint16_t *) p);
if (rsphdr->pdu_id == SDP_ERROR_RSP) {
/* The status can be invalid sintax or invalid record handle */
@@ -3095,6 +3099,12 @@ int sdp_device_record_update(sdp_session_t *session, bdaddr_t *device, const sdp
} else if (rsphdr->pdu_id != SDP_SVC_UPDATE_RSP) {
errno = EPROTO;
status = -1;
+ } else {
+ uint16_t tmp;
+
+ memcpy(&tmp, p, sizeof(tmp));
+
+ status = tmp;
}
end:
free(reqbuf);
@@ -4136,14 +4146,18 @@ int sdp_process(sdp_session_t *session)
rsp_count = sizeof(tsrc) + sizeof(csrc) + csrc * 4;
} else {
/* point to the first csrc */
- uint16_t *pcsrc = (uint16_t *) (t->rsp_concat_buf.data + 2);
+ uint8_t *pcsrc = t->rsp_concat_buf.data + 2;
+ uint16_t tcsrc, tcsrc2;
/* FIXME: update the interface later. csrc doesn't need be passed to clients */
pdata += sizeof(uint16_t); /* point to csrc */
/* the first csrc contains the sum of partial csrc responses */
- *pcsrc += bt_get_unaligned((uint16_t *) pdata);
+ memcpy(&tcsrc, pcsrc, sizeof(tcsrc));
+ memcpy(&tcsrc2, pdata, sizeof(tcsrc2));
+ tcsrc += tcsrc2;
+ memcpy(pcsrc, &tcsrc, sizeof(tcsrc));
pdata += sizeof(uint16_t); /* point to the first handle */
rsp_count = csrc * 4;
--
1.7.9.5
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 3/4] monitor: Fix build errors due to unaligned memory access
2012-11-23 10:09 [PATCH 1/4] sap-u8500: Fix build errors due to unaligned memory access Szymon Janc
2012-11-23 10:09 ` [PATCH 2/4] sdp: " Szymon Janc
@ 2012-11-23 10:09 ` Szymon Janc
2012-11-23 10:09 ` [PATCH 4/4] sdpd-request: " Szymon Janc
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Szymon Janc @ 2012-11-23 10:09 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This fix following compilation errors on ARM.
CC monitor/hcidump.o
monitor/hcidump.c: In function ‘device_callback’:
monitor/hcidump.c:147:11: error: cast increases required alignment of
target type [-Werror=cast-align]
monitor/hcidump.c:150:10: error: cast increases required alignment of
target type [-Werror=cast-align]
monitor/hcidump.c: In function ‘stack_internal_callback’:
monitor/hcidump.c:348:9: error: cast increases required alignment of
target type [-Werror=cast-align]
cc1: all warnings being treated as errors
make[1]: *** [monitor/hcidump.o] Error 1
CC monitor/control.o
monitor/control.c: In function ‘data_callback’:
monitor/control.c:584:10: error: cast increases required alignment of
target type [-Werror=cast-align]
cc1: all warnings being treated as errors
make[1]: *** [monitor/control.o] Error 1
---
monitor/control.c | 7 +++++--
monitor/hcidump.c | 18 +++++++++++-------
2 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/monitor/control.c b/monitor/control.c
index 3447b7a..9b76038 100644
--- a/monitor/control.c
+++ b/monitor/control.c
@@ -565,6 +565,7 @@ static void data_callback(int fd, uint32_t events, void *user_data)
while (1) {
struct cmsghdr *cmsg;
struct timeval *tv = NULL;
+ struct timeval ctv;
uint16_t opcode, index, pktlen;
ssize_t len;
@@ -580,8 +581,10 @@ static void data_callback(int fd, uint32_t events, void *user_data)
if (cmsg->cmsg_level != SOL_SOCKET)
continue;
- if (cmsg->cmsg_type == SCM_TIMESTAMP)
- tv = (struct timeval *) CMSG_DATA(cmsg);
+ if (cmsg->cmsg_type == SCM_TIMESTAMP) {
+ memcpy(&ctv, CMSG_DATA(cmsg), sizeof(ctv));
+ tv = &ctv;
+ }
}
opcode = btohs(hdr.opcode);
diff --git a/monitor/hcidump.c b/monitor/hcidump.c
index e69bcb1..9881bb3 100644
--- a/monitor/hcidump.c
+++ b/monitor/hcidump.c
@@ -130,7 +130,8 @@ static void device_callback(int fd, uint32_t events, void *user_data)
while (1) {
struct cmsghdr *cmsg;
struct timeval *tv = NULL;
- int *dir = NULL;
+ struct timeval ctv;
+ int dir = -1;
ssize_t len;
len = recvmsg(fd, &msg, MSG_DONTWAIT);
@@ -144,15 +145,16 @@ static void device_callback(int fd, uint32_t events, void *user_data)
switch (cmsg->cmsg_type) {
case HCI_DATA_DIR:
- dir = (int *) CMSG_DATA(cmsg);
+ memcpy(&dir, CMSG_DATA(cmsg), sizeof(dir));
break;
case HCI_CMSG_TSTAMP:
- tv = (struct timeval *) CMSG_DATA(cmsg);
+ memcpy(&ctv, CMSG_DATA(cmsg), sizeof(ctv));
+ tv = &ctv;
break;
}
}
- if (!dir || len < 1)
+ if (dir < 0 || len < 1)
continue;
switch (buf[0]) {
@@ -163,11 +165,11 @@ static void device_callback(int fd, uint32_t events, void *user_data)
packet_hci_event(tv, data->index, buf + 1, len - 1);
break;
case HCI_ACLDATA_PKT:
- packet_hci_acldata(tv, data->index, !!(*dir),
+ packet_hci_acldata(tv, data->index, !!dir,
buf + 1, len - 1);
break;
case HCI_SCODATA_PKT:
- packet_hci_scodata(tv, data->index, !!(*dir),
+ packet_hci_scodata(tv, data->index, !!dir,
buf + 1, len - 1);
break;
}
@@ -314,6 +316,7 @@ static void stack_internal_callback(int fd, uint32_t events, void *user_data)
evt_stack_internal *si;
evt_si_device *sd;
struct timeval *tv = NULL;
+ struct timeval ctv;
uint8_t type = 0xff, bus = 0xff;
char str[18], name[8] = "";
bdaddr_t bdaddr;
@@ -345,7 +348,8 @@ static void stack_internal_callback(int fd, uint32_t events, void *user_data)
switch (cmsg->cmsg_type) {
case HCI_CMSG_TSTAMP:
- tv = (struct timeval *) CMSG_DATA(cmsg);
+ memcpy(&ctv, CMSG_DATA(cmsg), sizeof(ctv));
+ tv = &ctv;
break;
}
}
--
1.7.9.5
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 4/4] sdpd-request: Fix build errors due to unaligned memory access
2012-11-23 10:09 [PATCH 1/4] sap-u8500: Fix build errors due to unaligned memory access Szymon Janc
2012-11-23 10:09 ` [PATCH 2/4] sdp: " Szymon Janc
2012-11-23 10:09 ` [PATCH 3/4] monitor: " Szymon Janc
@ 2012-11-23 10:09 ` Szymon Janc
2012-12-10 14:12 ` [PATCH 1/4] sap-u8500: " Szymon Janc
2012-12-11 5:43 ` Johan Hedberg
4 siblings, 0 replies; 6+ messages in thread
From: Szymon Janc @ 2012-11-23 10:09 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This fix following compilation errors on ARM.
CC src/bluetoothd-sdpd-request.o
src/sdpd-request.c: In function ‘extract_des’:
src/sdpd-request.c:186:17: error: cast increases required alignment of
target type [-Werror=cast-align]
src/sdpd-request.c:186:17: error: cast increases required alignment of
target type [-Werror=cast-align]
src/sdpd-request.c:210:17: error: cast increases required alignment of
target type [-Werror=cast-align]
src/sdpd-request.c:210:17: error: cast increases required alignment of
target type [-Werror=cast-align]
cc1: all warnings being treated as errors
make[1]: *** [src/bluetoothd-sdpd-request.o] Error 1
---
src/sdpd-request.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/sdpd-request.c b/src/sdpd-request.c
index 2af743e..a79efc7 100644
--- a/src/sdpd-request.c
+++ b/src/sdpd-request.c
@@ -182,8 +182,12 @@ static int extract_des(uint8_t *buf, int len, sdp_list_t **svcReqSeq, uint8_t *p
aid->uint16 = bt_get_be16(p);
pElem = (char *) aid;
} else {
+ uint16_t tmp;
+
+ memcpy(&tmp, p, sizeof(tmp));
+
pElem = malloc(sizeof(uint16_t));
- bt_put_be16(bt_get_unaligned((uint16_t *)p), pElem);
+ bt_put_be16(tmp, pElem);
}
p += sizeof(uint16_t);
seqlen += sizeof(uint16_t);
@@ -206,8 +210,12 @@ static int extract_des(uint8_t *buf, int len, sdp_list_t **svcReqSeq, uint8_t *p
pElem = (char *) aid;
} else {
+ uint32_t tmp;
+
+ memcpy(&tmp, p, sizeof(tmp));
+
pElem = malloc(sizeof(uint32_t));
- bt_put_be32(bt_get_unaligned((uint32_t *)p), pElem);
+ bt_put_be32(tmp, pElem);
}
p += sizeof(uint32_t);
seqlen += sizeof(uint32_t);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 1/4] sap-u8500: Fix build errors due to unaligned memory access
2012-11-23 10:09 [PATCH 1/4] sap-u8500: Fix build errors due to unaligned memory access Szymon Janc
` (2 preceding siblings ...)
2012-11-23 10:09 ` [PATCH 4/4] sdpd-request: " Szymon Janc
@ 2012-12-10 14:12 ` Szymon Janc
2012-12-11 5:43 ` Johan Hedberg
4 siblings, 0 replies; 6+ messages in thread
From: Szymon Janc @ 2012-12-10 14:12 UTC (permalink / raw)
To: linux-bluetooth@vger.kernel.org
On Friday 23 of November 2012 12:09:11 Janc Szymon wrote:
> This fix following compilation error on ARM.
>
> CC profiles/sap/sap-u8500.o
> profiles/sap/sap-u8500.c: In function recv_card_status:
> profiles/sap/sap-u8500.c:323:16: error: cast increases required
> alignment of target type [-Werror=cast-align]
> profiles/sap/sap-u8500.c: In function recv_response:
> profiles/sap/sap-u8500.c:423:12: error: cast increases required
> alignment of target type [-Werror=cast-align]
> cc1: all warnings being treated as errors
> ---
> profiles/sap/sap-u8500.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/profiles/sap/sap-u8500.c b/profiles/sap/sap-u8500.c
> index f07209d..b1aee57 100644
> --- a/profiles/sap/sap-u8500.c
> +++ b/profiles/sap/sap-u8500.c
> @@ -313,16 +313,16 @@ static void recv_status(uint32_t status)
>
> static void recv_card_status(uint32_t status, uint8_t *param)
> {
> - uint32_t *card_status;
> + uint32_t card_status;
> uint8_t result;
> uint8_t iccrs;
>
> if (status != STE_STATUS_OK)
> return;
>
> - card_status = (uint32_t *)param;
> + memcpy(&card_status, param, sizeof(card_status));
>
> - if (get_sap_reader_status(*card_status, &iccrs) < 0)
> + if (get_sap_reader_status(card_status, &iccrs) < 0)
> result = SAP_RESULT_ERROR_NO_REASON;
> else
> result = get_sap_result(STE_GET_STATUS_MSG, status);
> @@ -420,7 +420,7 @@ static void recv_response(struct ste_message *msg)
> }
>
> param = msg->payload;
> - status = *(uint32_t *)param;
> + memcpy(&status, param, sizeof(status));
> param += sizeof(status);
>
> SAP_VDBG("status 0x%x", status);
>
ping
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH 1/4] sap-u8500: Fix build errors due to unaligned memory access
2012-11-23 10:09 [PATCH 1/4] sap-u8500: Fix build errors due to unaligned memory access Szymon Janc
` (3 preceding siblings ...)
2012-12-10 14:12 ` [PATCH 1/4] sap-u8500: " Szymon Janc
@ 2012-12-11 5:43 ` Johan Hedberg
4 siblings, 0 replies; 6+ messages in thread
From: Johan Hedberg @ 2012-12-11 5:43 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
Hi Szymon,
On Fri, Nov 23, 2012, Szymon Janc wrote:
> This fix following compilation error on ARM.
>
> CC profiles/sap/sap-u8500.o
> profiles/sap/sap-u8500.c: In function recv_card_status:
> profiles/sap/sap-u8500.c:323:16: error: cast increases required
> alignment of target type [-Werror=cast-align]
> profiles/sap/sap-u8500.c: In function recv_response:
> profiles/sap/sap-u8500.c:423:12: error: cast increases required
> alignment of target type [-Werror=cast-align]
> cc1: all warnings being treated as errors
> ---
> profiles/sap/sap-u8500.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
Sorry about the delay with these. All four are now upstream.
Johan
^ permalink raw reply [flat|nested] 6+ messages in thread