Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH BlueZ v1 1/2] attrib: Remove norequests and noresponses variables
@ 2013-04-01  9:38 Jaganath Kanakkassery
  2013-04-01  9:38 ` [PATCH BlueZ v1 2/2] attrib: Fix use after free of attrib Jaganath Kanakkassery
  2013-04-02  6:47 ` [PATCH BlueZ v1 1/2] attrib: Remove norequests and noresponses variables Johan Hedberg
  0 siblings, 2 replies; 3+ messages in thread
From: Jaganath Kanakkassery @ 2013-04-01  9:38 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jaganath Kanakkassery

Passing NULL is fine to g_queue_is_empty(), so removing these
variables makes the code more readable
---
 attrib/gattrib.c |    9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/attrib/gattrib.c b/attrib/gattrib.c
index 01c19f9..f95f2fb 100644
--- a/attrib/gattrib.c
+++ b/attrib/gattrib.c
@@ -394,7 +394,6 @@ static gboolean received_data(GIOChannel *io, GIOCondition cond, gpointer data)
 	uint8_t buf[512], status;
 	gsize len;
 	GIOStatus iostat;
-	gboolean norequests, noresponses;
 
 	if (attrib->stale)
 		return FALSE;
@@ -447,11 +446,6 @@ static gboolean received_data(GIOChannel *io, GIOCondition cond, gpointer data)
 	status = 0;
 
 done:
-	norequests = attrib->requests == NULL ||
-			g_queue_is_empty(attrib->requests);
-	noresponses = attrib->responses == NULL ||
-			g_queue_is_empty(attrib->responses);
-
 	if (cmd) {
 		if (cmd->func)
 			cmd->func(status, buf, len, cmd->user_data);
@@ -459,7 +453,8 @@ done:
 		command_destroy(cmd);
 	}
 
-	if (!norequests || !noresponses)
+	if (!g_queue_is_empty(attrib->requests) ||
+					!g_queue_is_empty(attrib->responses))
 		wake_up_sender(attrib);
 
 	return TRUE;
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH BlueZ v1 2/2] attrib: Fix use after free of attrib
  2013-04-01  9:38 [PATCH BlueZ v1 1/2] attrib: Remove norequests and noresponses variables Jaganath Kanakkassery
@ 2013-04-01  9:38 ` Jaganath Kanakkassery
  2013-04-02  6:47 ` [PATCH BlueZ v1 1/2] attrib: Remove norequests and noresponses variables Johan Hedberg
  1 sibling, 0 replies; 3+ messages in thread
From: Jaganath Kanakkassery @ 2013-04-01  9:38 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jaganath Kanakkassery

If attrib is freed in cmd->func(), then it will be used if either
request or response queue has some data to send.

This patch moves calling wake_up_sender() which increases the ref
count of attrib so that it wont get freed in cmd->func().
---
 attrib/gattrib.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/attrib/gattrib.c b/attrib/gattrib.c
index f95f2fb..37581a3 100644
--- a/attrib/gattrib.c
+++ b/attrib/gattrib.c
@@ -446,6 +446,10 @@ static gboolean received_data(GIOChannel *io, GIOCondition cond, gpointer data)
 	status = 0;
 
 done:
+	if (!g_queue_is_empty(attrib->requests) ||
+					!g_queue_is_empty(attrib->responses))
+		wake_up_sender(attrib);
+
 	if (cmd) {
 		if (cmd->func)
 			cmd->func(status, buf, len, cmd->user_data);
@@ -453,10 +457,6 @@ done:
 		command_destroy(cmd);
 	}
 
-	if (!g_queue_is_empty(attrib->requests) ||
-					!g_queue_is_empty(attrib->responses))
-		wake_up_sender(attrib);
-
 	return TRUE;
 }
 
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH BlueZ v1 1/2] attrib: Remove norequests and noresponses variables
  2013-04-01  9:38 [PATCH BlueZ v1 1/2] attrib: Remove norequests and noresponses variables Jaganath Kanakkassery
  2013-04-01  9:38 ` [PATCH BlueZ v1 2/2] attrib: Fix use after free of attrib Jaganath Kanakkassery
@ 2013-04-02  6:47 ` Johan Hedberg
  1 sibling, 0 replies; 3+ messages in thread
From: Johan Hedberg @ 2013-04-02  6:47 UTC (permalink / raw)
  To: Jaganath Kanakkassery; +Cc: linux-bluetooth

Hi Jaganath,

On Mon, Apr 01, 2013, Jaganath Kanakkassery wrote:
> Passing NULL is fine to g_queue_is_empty(), so removing these
> variables makes the code more readable
> ---
>  attrib/gattrib.c |    9 ++-------
>  1 file changed, 2 insertions(+), 7 deletions(-)

Both patches in this set have been applied. Thanks.

Johan

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-04-02  6:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-01  9:38 [PATCH BlueZ v1 1/2] attrib: Remove norequests and noresponses variables Jaganath Kanakkassery
2013-04-01  9:38 ` [PATCH BlueZ v1 2/2] attrib: Fix use after free of attrib Jaganath Kanakkassery
2013-04-02  6:47 ` [PATCH BlueZ v1 1/2] attrib: Remove norequests and noresponses variables Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox