public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Marcel Holtmann <marcel@holtmann.org>
To: Szymon Janc <szymon.janc@tieto.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [RFC v4 15/18] Refactor bt_get_unaligned macro
Date: Tue, 04 Sep 2012 08:21:45 -0700	[thread overview]
Message-ID: <1346772105.21200.2.camel@aeonflux> (raw)
In-Reply-To: <1346769697-9930-16-git-send-email-szymon.janc@tieto.com>

Hi Szymon,

> 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.

Regards

Marcel



  reply	other threads:[~2012-09-04 15:21 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 [this message]
2012-09-05  9:03     ` Szymon Janc
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=1346772105.21200.2.camel@aeonflux \
    --to=marcel@holtmann.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=szymon.janc@tieto.com \
    /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