From: Szymon Janc <szymon.janc@tieto.com>
To: Marcel Holtmann <marcel@holtmann.org>
Cc: "linux-bluetooth@vger.kernel.org" <linux-bluetooth@vger.kernel.org>
Subject: Re: [RFC v4 15/18] Refactor bt_get_unaligned macro
Date: Wed, 5 Sep 2012 11:03:29 +0200 [thread overview]
Message-ID: <5709985.AIy78rkvT5@uw000953> (raw)
In-Reply-To: <1346772105.21200.2.camel@aeonflux>
On Tuesday 04 of September 2012 18:21:45 Marcel Holtmann wrote:
> Hi Szymon,
Hi Marcel,
>
> > Use extra parameter type for bt_get_unaligned to avoid pointer casting
> > which might trigger compile time errors due to unaligned memory access.
> >
> > ---
> > attrib/att.h | 6 +++---
> > lib/bluetooth.h | 28 ++++++++++++++--------------
> > lib/sdp.c | 22 +++++++++++-----------
> > src/sdpd-request.c | 4 ++--
> > 4 files changed, 30 insertions(+), 30 deletions(-)
> >
> > diff --git a/attrib/att.h b/attrib/att.h
> > index a563255..6101dac 100644
> > --- a/attrib/att.h
> > +++ b/attrib/att.h
> > @@ -115,19 +115,19 @@ struct att_range {
> > static inline uint8_t att_get_u8(const void *ptr)
> > {
> > const uint8_t *u8_ptr = ptr;
> > - return bt_get_unaligned(u8_ptr);
> > + return bt_get_unaligned(u8_ptr, uint8_t);
> > }
> >
> > static inline uint16_t att_get_u16(const void *ptr)
> > {
> > const uint16_t *u16_ptr = ptr;
> > - return btohs(bt_get_unaligned(u16_ptr));
> > + return btohs(bt_get_unaligned(u16_ptr, uint16_t));
> > }
> >
> > static inline uint32_t att_get_u32(const void *ptr)
> > {
> > const uint32_t *u32_ptr = ptr;
> > - return btohl(bt_get_unaligned(u32_ptr));
> > + return btohl(bt_get_unaligned(u32_ptr, uint32_t));
> > }
> >
> > static inline uint128_t att_get_u128(const void *ptr)
> > diff --git a/lib/bluetooth.h b/lib/bluetooth.h
> > index 161b7bd..898a122 100644
> > --- a/lib/bluetooth.h
> > +++ b/lib/bluetooth.h
> > @@ -137,10 +137,10 @@ enum {
> > #endif
> >
> > /* Bluetooth unaligned access */
> > -#define bt_get_unaligned(ptr) \
> > +#define bt_get_unaligned(ptr, type) \
> > ({ \
> > struct __attribute__((packed)) { \
> > - typeof(*(ptr)) __v; \
> > + type __v; \
> > } *__p = (typeof(__p)) (ptr); \
> > __p->__v; \
> > })
>
> I am not in favor of this change at all. We should not need such a
> change. And in addition, it break the API.
On ARM (and possibly other architectures) with -Wcast-align one is not able to do:
uint8_t *ptr;
uint16_t *ptr2 = (uint16_t *)ptr;
int *ptr3 = (int *)ptr;
etc.
It leads to following error:
error: cast increases required alignment of target type [-Werror=cast-align]
..and this is what current version of that macro requires.
(BTW bt_put_unaligned suffers same issue)
In bluetoothd code we can replace all calls to that macro with (more or less
convenient) memcpy. But if that macro is considered part of API it may produce
compilation errors on projects that use -Wcast-align.
Any suggestions on how this could be solved are welcome.
> Regards
>
> Marcel
>
--
BR
Szymon Janc
next prev parent reply other threads:[~2012-09-05 9:03 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-04 14:41 [RFC v4 00/18] Unaligned memory access fixes Szymon Janc
2012-09-04 14:41 ` [RFC v4 01/18] Add helper functions for putting integers on unaligned memory address Szymon Janc
2012-09-04 14:41 ` [RFC v4 02/18] sdp: Fix compilation errors due to unaligned memory access Szymon Janc
2012-09-04 14:41 ` [RFC v4 03/18] sdp: Use bt_get_be* helpers instead of bt_get_unaligned Szymon Janc
2012-09-04 14:41 ` [RFC v4 04/18] l2test: Fix compilation errors due to unaligned memory access Szymon Janc
2012-09-04 14:41 ` [RFC v4 05/18] rctest: " Szymon Janc
2012-09-04 14:41 ` [RFC v4 06/18] scotest: " Szymon Janc
2012-09-04 14:41 ` [RFC v4 07/18] sap: " Szymon Janc
2012-09-04 14:41 ` [RFC v4 08/18] adaptername: Refactor handle_inotify_cb Szymon Janc
2012-09-04 14:41 ` [RFC v4 09/18] sdpd-request: Fix build errors due to unaligned memory access Szymon Janc
2012-09-04 14:41 ` [RFC v4 10/18] sdpd-service: " Szymon Janc
2012-09-04 14:41 ` [RFC v4 11/18] hciemu: " Szymon Janc
2012-09-04 14:41 ` [RFC v4 12/18] avrcp: Fix compilation " Szymon Janc
2012-09-04 14:41 ` [RFC v4 13/18] eir: Use bt_get_* helper functions to access unaligned memory Szymon Janc
2012-09-04 14:41 ` [RFC v4 14/18] mgmt: " Szymon Janc
2012-09-04 14:41 ` [RFC v4 15/18] Refactor bt_get_unaligned macro Szymon Janc
2012-09-04 15:21 ` Marcel Holtmann
2012-09-05 9:03 ` Szymon Janc [this message]
2012-09-04 14:41 ` [RFC v4 16/18] sap-u8500: Fix compile error due to unaligned memory access Szymon Janc
2012-09-04 14:41 ` [RFC v4 17/18] monitor: Fix compilation errors " Szymon Janc
2012-09-04 14:41 ` [RFC v4 18/18] sdp: Fix build error " Szymon Janc
2012-09-05 9:33 ` [RFC v4 00/18] Unaligned memory access fixes Johan Hedberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5709985.AIy78rkvT5@uw000953 \
--to=szymon.janc@tieto.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=marcel@holtmann.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).