* [PATCH 1/2] hcidump: Fix compilation errors due to unaligned memory access
@ 2012-12-18 11:10 Szymon Janc
2012-12-18 11:10 ` [PATCH 2/2] adapter: Use int for storing signed value Szymon Janc
2012-12-18 11:45 ` [PATCH 1/2] hcidump: Fix compilation errors due to unaligned memory access Johan Hedberg
0 siblings, 2 replies; 3+ messages in thread
From: Szymon Janc @ 2012-12-18 11:10 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Use bt_get_le* helper functions to access unaligned memory. This fix
number of compilation errors on ARM similar to:
CC tools/parser/hci.o
tools/parser/hci.c: In function ‘ext_inquiry_data_dump’:
tools/parser/hci.c:797:10 error: cast increases required alignment of
target type [-Werror=cast-align]
tools/parser/hci.c:797:10: error: cast increases required alignment of
target type [-Werror=cast-align]
cc1: all warnings being treated as errors
make[1]: *** [tools/parser/hci.o] Error 1
---
tools/parser/hci.c | 7 ++-----
tools/parser/l2cap.c | 22 +++++++++++-----------
2 files changed, 13 insertions(+), 16 deletions(-)
diff --git a/tools/parser/hci.c b/tools/parser/hci.c
index 4d2b91b..17b776d 100644
--- a/tools/parser/hci.c
+++ b/tools/parser/hci.c
@@ -791,12 +791,9 @@ static inline void ext_inquiry_data_dump(int level, struct frame *frm,
printf("%s service classes:",
type == 0x02 ? "Shortened" : "Complete");
- for (i = 0; i < len / 2; i++) {
- uint16_t val;
+ for (i = 0; i < len / 2; i++)
+ printf(" 0x%4.4x", bt_get_le16(data + i * 2));
- val = btohs(bt_get_unaligned(((uint16_t *) (data + i * 2))));
- printf(" 0x%4.4x", val);
- }
printf("\n");
break;
diff --git a/tools/parser/l2cap.c b/tools/parser/l2cap.c
index 6b3e17a..42f5e1a 100644
--- a/tools/parser/l2cap.c
+++ b/tools/parser/l2cap.c
@@ -250,9 +250,9 @@ static uint32_t get_val(uint8_t *ptr, uint8_t len)
case 1:
return *ptr;
case 2:
- return btohs(bt_get_unaligned((uint16_t *) ptr));
+ return bt_get_le16(ptr);
case 4:
- return btohl(bt_get_unaligned((uint32_t *) ptr));
+ return bt_get_le32(ptr);
}
return 0;
}
@@ -595,9 +595,9 @@ static void conf_rfc(void *ptr, int len, int in, uint16_t handle,
uint16_t rto, mto, mps;
txwin = *((uint8_t *) (ptr + 1));
maxtrans = *((uint8_t *) (ptr + 2));
- rto = btohs(bt_get_unaligned((uint16_t *) (ptr + 3)));
- mto = btohs(bt_get_unaligned((uint16_t *) (ptr + 5)));
- mps = btohs(bt_get_unaligned((uint16_t *) (ptr + 7)));
+ rto = bt_get_le16(ptr + 3);
+ mto = bt_get_le16(ptr + 5);
+ mps = bt_get_le16(ptr + 7);
printf(", TxWin %d, MaxTx %d, RTo %d, MTo %d, MPS %d",
txwin, maxtrans, rto, mto, mps);
}
@@ -916,7 +916,7 @@ static void l2cap_ctrl_ext_parse(int level, struct frame *frm, uint32_t ctrl)
printf(" %s", sar2str(sar));
if (sar == L2CAP_SAR_START) {
uint16_t len;
- len = btohs(bt_get_unaligned((uint16_t *) frm->ptr));
+ len = bt_get_le16(frm->ptr);
frm->ptr += L2CAP_SDULEN_SIZE;
frm->len -= L2CAP_SDULEN_SIZE;
printf(" (len %d)", len);
@@ -949,7 +949,7 @@ static void l2cap_ctrl_parse(int level, struct frame *frm, uint32_t ctrl)
printf(" %s", sar2str(sar));
if (sar == L2CAP_SAR_START) {
uint16_t len;
- len = btohs(bt_get_unaligned((uint16_t *) frm->ptr));
+ len = bt_get_le16(frm->ptr);
frm->ptr += L2CAP_SDULEN_SIZE;
frm->len -= L2CAP_SDULEN_SIZE;
printf(" (len %d)", len);
@@ -1062,7 +1062,7 @@ static inline void a2mp_discover_req(int level, struct frame *frm, uint16_t len)
do {
len -= 2;
- mask = btohs(*(uint16_t *)(&octet[0]));
+ mask = bt_get_le16(octet);
printf(" 0x%4.4x", mask);
extension = octet[1] & 0x80;
@@ -1102,7 +1102,7 @@ static inline void a2mp_discover_rsp(int level, struct frame *frm, uint16_t len)
do {
len -= 2;
- mask = btohs(*(uint16_t *)(&octet[0]));
+ mask = bt_get_le16(octet);
printf(" 0x%4.4x", mask);
extension = octet[1] & 0x80;
@@ -1324,7 +1324,7 @@ static void l2cap_parse(int level, struct frame *frm)
if (p_filter(FILT_L2CAP))
return;
- psm = btohs(bt_get_unaligned((uint16_t *) frm->ptr));
+ psm = bt_get_le16(frm->ptr);
frm->ptr += 2;
frm->len -= 2;
@@ -1433,7 +1433,7 @@ static void l2cap_parse(int level, struct frame *frm)
frm->ptr += 2;
frm->len -= 4;
}
- fcs = btohs(bt_get_unaligned((uint16_t *) (frm->ptr + frm->len)));
+ fcs = bt_get_le16(frm->ptr + frm->len);
}
if (!p_filter(FILT_L2CAP)) {
--
1.8.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] adapter: Use int for storing signed value
2012-12-18 11:10 [PATCH 1/2] hcidump: Fix compilation errors due to unaligned memory access Szymon Janc
@ 2012-12-18 11:10 ` Szymon Janc
2012-12-18 11:45 ` [PATCH 1/2] hcidump: Fix compilation errors due to unaligned memory access Johan Hedberg
1 sibling, 0 replies; 3+ messages in thread
From: Szymon Janc @ 2012-12-18 11:10 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
char can be signed or unsigned depending on architecture. This fix
following compilation error on ARM:
src/adapter.c: In function 'convert_primaries_entry`:
src/adapter:2272:2: error: comparison is always true due to limited
range of data type [-Werror=type-limits]
cc1: all warnings being treated as errors
make[1]: *** [src/adapter.o] Error 1
---
src/adapter.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/adapter.c b/src/adapter.c
index a41eb15..bb54d8b 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2215,7 +2215,7 @@ failed:
static void convert_primaries_entry(char *key, char *value, void *user_data)
{
char *address = user_data;
- char device_type = -1;
+ int device_type = -1;
uuid_t uuid;
char **services, **service, *prim_uuid;
char filename[PATH_MAX + 1];
--
1.8.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] hcidump: Fix compilation errors due to unaligned memory access
2012-12-18 11:10 [PATCH 1/2] hcidump: Fix compilation errors due to unaligned memory access Szymon Janc
2012-12-18 11:10 ` [PATCH 2/2] adapter: Use int for storing signed value Szymon Janc
@ 2012-12-18 11:45 ` Johan Hedberg
1 sibling, 0 replies; 3+ messages in thread
From: Johan Hedberg @ 2012-12-18 11:45 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
Hi Szymon,
On Tue, Dec 18, 2012, Szymon Janc wrote:
> Use bt_get_le* helper functions to access unaligned memory. This fix
> number of compilation errors on ARM similar to:
>
> CC tools/parser/hci.o
> tools/parser/hci.c: In function ‘ext_inquiry_data_dump’:
> tools/parser/hci.c:797:10 error: cast increases required alignment of
> target type [-Werror=cast-align]
> tools/parser/hci.c:797:10: error: cast increases required alignment of
> target type [-Werror=cast-align]
> cc1: all warnings being treated as errors
> make[1]: *** [tools/parser/hci.o] Error 1
> ---
> tools/parser/hci.c | 7 ++-----
> tools/parser/l2cap.c | 22 +++++++++++-----------
> 2 files changed, 13 insertions(+), 16 deletions(-)
Both patches have been applied. Thanks.
Johan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-12-18 11:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-18 11:10 [PATCH 1/2] hcidump: Fix compilation errors due to unaligned memory access Szymon Janc
2012-12-18 11:10 ` [PATCH 2/2] adapter: Use int for storing signed value Szymon Janc
2012-12-18 11:45 ` [PATCH 1/2] hcidump: Fix compilation errors due to unaligned memory access Johan Hedberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).