linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johan Hedberg <johan.hedberg@gmail.com>
To: Ido Yariv <ido@wizery.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH] attrib-server: Fix multiple channels detaching mix-up
Date: Wed, 30 May 2012 10:37:01 +0300	[thread overview]
Message-ID: <20120530073701.GB6539@x220> (raw)
In-Reply-To: <1338322808-15503-1-git-send-email-ido@wizery.com>

Hi Ido,

On Tue, May 29, 2012, Ido Yariv wrote:
> The identifier returned by g_attrib_register is not unique across
> different channels. Since attrib_channel_detach assumes this identifier
> to be unique, it may end up detaching the wrong channel when a device
> disconnects.
> 
> Fix this by using the channel's pointer as a unique identifier for
> detaching the channel. The identifier returned from g_attrib_register
> will still be used to find the relevant event structure.
> ---
>  src/attrib-server.c |   22 +++++++---------------
>  1 files changed, 7 insertions(+), 15 deletions(-)
> 
> diff --git a/src/attrib-server.c b/src/attrib-server.c
> index dd1bba4..39085de 100644
> --- a/src/attrib-server.c
> +++ b/src/attrib-server.c
> @@ -72,7 +72,7 @@ struct gatt_channel {
>  	GAttrib *attrib;
>  	guint mtu;
>  	gboolean le;
> -	guint id;
> +	guint event_id;
>  	gboolean encrypted;
>  	struct gatt_server *server;
>  	guint cleanup_id;
> @@ -1077,8 +1077,8 @@ guint attrib_channel_attach(GAttrib *attrib)
>  
>  
>  	channel->attrib = g_attrib_ref(attrib);
> -	channel->id = g_attrib_register(channel->attrib, GATTRIB_ALL_REQS,
> -					channel_handler, channel, NULL);
> +	channel->event_id = g_attrib_register(channel->attrib, GATTRIB_ALL_REQS,
> +						channel_handler, channel, NULL);
>  
>  	channel->cleanup_id = g_io_add_watch(io, G_IO_HUP, channel_watch_cb,
>  								channel);
> @@ -1087,15 +1087,7 @@ guint attrib_channel_attach(GAttrib *attrib)
>  
>  	server->clients = g_slist_append(server->clients, channel);
>  
> -	return channel->id;
> -}
> -
> -static gint channel_id_cmp(gconstpointer data, gconstpointer user_data)
> -{
> -	const struct gatt_channel *channel = data;
> -	guint id = GPOINTER_TO_UINT(user_data);
> -
> -	return channel->id - id;
> +	return GPOINTER_TO_UINT(channel);

I don't think converting a pointer to uint is safe since some systems
can have 64-bit pointers but 32-bit uints. These macros are therefore
only safe to be used in the other direction, i.e. when starting off with
an uint and passing it to an API that expects a pointer.

Johan

  reply	other threads:[~2012-05-30  7:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-29 20:20 [PATCH] attrib-server: Fix multiple channels detaching mix-up Ido Yariv
2012-05-30  7:37 ` Johan Hedberg [this message]
2012-05-30 18:32   ` Ido Yariv
2012-06-06  9:18     ` Ido Yariv
2012-06-07 15:44       ` Johan Hedberg
2012-06-08 15:39         ` Johan Hedberg
2012-06-08 16:01           ` Ido Yariv

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=20120530073701.GB6539@x220 \
    --to=johan.hedberg@gmail.com \
    --cc=ido@wizery.com \
    --cc=linux-bluetooth@vger.kernel.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).