Skip to contentSkip to conversation

shared/att: Simplify bt_att_new

PATCH In review Luiz Augusto von Dentz 2 participants 3 messages Oct 31, 2014 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/1 shared/att: Simplify bt_att_new

From: Luiz Augusto von Dentz <[email protected]>

This split bt_att_unref into bt_att_free so it can be used within bt_att_new when freeing the data.

---
 src/shared/att.c | 68 +++++++++++++++++++++++---------------------------------
 1 file changed, 28 insertions(+), 40 deletions(-)
src/shared/att.c +28 -40
index 6adde22..97f2541 100644
@@ -743,6 +743,32 @@ static bool can_read_data(struct io *io, void *user_data)
 	return true;
 }
 
+static void bt_att_free(struct bt_att *att)
+{
+	if (att->pending_req)
+		destroy_att_send_op(att->pending_req);
+
+	if (att->pending_ind)
+		destroy_att_send_op(att->pending_ind);
+
+	io_destroy(att->io);
+
+	queue_destroy(att->req_queue, destroy_att_send_op);
+	queue_destroy(att->ind_queue, destroy_att_send_op);
+	queue_destroy(att->write_queue, destroy_att_send_op);
+	queue_destroy(att->notify_list, destroy_att_notify);
+	queue_destroy(att->disconn_list, destroy_att_disconn);
+
+	if (att->timeout_destroy)
+		att->timeout_destroy(att->timeout_data);
+
+	if (att->debug_destroy)
+		att->debug_destroy(att->debug_data);
+
+	free(att->buf);
+	free(att);
+}
+
 struct bt_att *bt_att_new(int fd)
 {
 	struct bt_att *att;
@@ -794,14 +820,7 @@ struct bt_att *bt_att_new(int fd)
 	return bt_att_ref(att);
 
 fail:
-	queue_destroy(att->req_queue, NULL);
-	queue_destroy(att->ind_queue, NULL);
-	queue_destroy(att->write_queue, NULL);
-	queue_destroy(att->notify_list, NULL);
-	queue_destroy(att->disconn_list, NULL);
-	io_destroy(att->io);
-	free(att->buf);
-	free(att);
+	bt_att_free(att);
 
 	return NULL;
 }
@@ -824,38 +843,7 @@ void bt_att_unref(struct bt_att *att)
 	if (__sync_sub_and_fetch(&att->ref_count, 1))
 		return;
 
-	bt_att_unregister_all(att);
-	bt_att_cancel_all(att);
-
-	if (att->pending_req)
-		destroy_att_send_op(att->pending_req);
-
-	if (att->pending_ind)
-		destroy_att_send_op(att->pending_ind);
-
-	io_destroy(att->io);
-	att->io = NULL;
-
-	queue_destroy(att->req_queue, NULL);
-	queue_destroy(att->ind_queue, NULL);
-	queue_destroy(att->write_queue, NULL);
-	queue_destroy(att->notify_list, NULL);
-	queue_destroy(att->disconn_list, NULL);
-	att->req_queue = NULL;
-	att->ind_queue = NULL;
-	att->write_queue = NULL;
-	att->notify_list = NULL;
-
-	if (att->timeout_destroy)
-		att->timeout_destroy(att->timeout_data);
-
-	if (att->debug_destroy)
-		att->debug_destroy(att->debug_data);
-
-	free(att->buf);
-	att->buf = NULL;
-
-	free(att);
+	bt_att_free(att);
 }
 
 bool bt_att_set_close_on_unref(struct bt_att *att, bool do_close)
Signature · 1 line
1.9.3
#1 lore raw

Hi Luiz,

Quoted 14 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This split bt_att_unref into bt_att_free so it can be used within bt_att_new when freeing the data.

---
 src/shared/att.c | 68 +++++++++++++++++++++++---------------------------------
 1 file changed, 28 insertions(+), 40 deletions(-)
src/shared/att.c +0 -0
index 6adde22..97f2541 100644

src/shared/att.c static bool can_read_data(struct io *io, void *user_data) · line 748

Quoted 6 lines
src/shared/att.c +3 -0
@@ -743,6 +743,32 @@ static bool can_read_data(struct io *io, void *user_data)
        return true;
 }
 
+static void bt_att_free(struct bt_att *att)
+{
+

I think that bt_ prefix we use only for api functions. For static function free_att or att_free is enought.

Quoted 84 lines
src/shared/att.c +23 -0
     if (att->pending_req)
+               destroy_att_send_op(att->pending_req);
+
+       if (att->pending_ind)
+               destroy_att_send_op(att->pending_ind);
+
+       io_destroy(att->io);
+
+       queue_destroy(att->req_queue, destroy_att_send_op);
+       queue_destroy(att->ind_queue, destroy_att_send_op);
+       queue_destroy(att->write_queue, destroy_att_send_op);
+       queue_destroy(att->notify_list, destroy_att_notify);
+       queue_destroy(att->disconn_list, destroy_att_disconn);
+
+       if (att->timeout_destroy)
+               att->timeout_destroy(att->timeout_data);
+
+       if (att->debug_destroy)
+               att->debug_destroy(att->debug_data);
+
+       free(att->buf);
+       free(att);
+}
+
 struct bt_att *bt_att_new(int fd)
 {
        struct bt_att *att;
src/shared/att.c +2 -41
@@ -794,14 +820,7 @@ struct bt_att *bt_att_new(int fd)
        return bt_att_ref(att);
 
 fail:
-       queue_destroy(att->req_queue, NULL);
-       queue_destroy(att->ind_queue, NULL);
-       queue_destroy(att->write_queue, NULL);
-       queue_destroy(att->notify_list, NULL);
-       queue_destroy(att->disconn_list, NULL);
-       io_destroy(att->io);
-       free(att->buf);
-       free(att);
+       bt_att_free(att);
 
        return NULL;
 }
@@ -824,38 +843,7 @@ void bt_att_unref(struct bt_att *att)
        if (__sync_sub_and_fetch(&att->ref_count, 1))
                return;
 
-       bt_att_unregister_all(att);
-       bt_att_cancel_all(att);
-
-       if (att->pending_req)
-               destroy_att_send_op(att->pending_req);
-
-       if (att->pending_ind)
-               destroy_att_send_op(att->pending_ind);
-
-       io_destroy(att->io);
-       att->io = NULL;
-
-       queue_destroy(att->req_queue, NULL);
-       queue_destroy(att->ind_queue, NULL);
-       queue_destroy(att->write_queue, NULL);
-       queue_destroy(att->notify_list, NULL);
-       queue_destroy(att->disconn_list, NULL);
-       att->req_queue = NULL;
-       att->ind_queue = NULL;
-       att->write_queue = NULL;
-       att->notify_list = NULL;
-
-       if (att->timeout_destroy)
-               att->timeout_destroy(att->timeout_data);
-
-       if (att->debug_destroy)
-               att->debug_destroy(att->debug_data);
-
-       free(att->buf);
-       att->buf = NULL;
-
-       free(att);
+       bt_att_free(att);
 }
 
 bool bt_att_set_close_on_unref(struct bt_att *att, bool do_close)
--
Quoted 1 line

1.9.3

BR
Lukasz

Quoted 6 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author maintainer
#2 lore raw

Hi Lukasz,

Quoted 21 lines · Lukasz Rymanowski

Hi Luiz,

Quoted 17 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This split bt_att_unref into bt_att_free so it can be used within bt_att_new when freeing the data.

---
 src/shared/att.c | 68 +++++++++++++++++++++++---------------------------------
 1 file changed, 28 insertions(+), 40 deletions(-)
src/shared/att.c +0 -0
index 6adde22..97f2541 100644
@@ -743,6 +743,32 @@ static bool can_read_data(struct io *io, void *user_data)
        return true;
 }
 
Quoted 6 lines

src/shared/att.c static bool can_read_data(struct io *io, void *user_data) · line 750

Quoted 3 lines
src/shared/att.c +3 -0
+static void bt_att_free(struct bt_att *att)
+{
+

I think that bt_ prefix we use only for api functions. For static function free_att or att_free is enought.

Yes but usually when it is a counterpart function I usually keep the prefix for convenience in case it is made public later.

Quoted 95 lines
Quoted 84 lines
src/shared/att.c +23 -0
     if (att->pending_req)
+               destroy_att_send_op(att->pending_req);
+
+       if (att->pending_ind)
+               destroy_att_send_op(att->pending_ind);
+
+       io_destroy(att->io);
+
+       queue_destroy(att->req_queue, destroy_att_send_op);
+       queue_destroy(att->ind_queue, destroy_att_send_op);
+       queue_destroy(att->write_queue, destroy_att_send_op);
+       queue_destroy(att->notify_list, destroy_att_notify);
+       queue_destroy(att->disconn_list, destroy_att_disconn);
+
+       if (att->timeout_destroy)
+               att->timeout_destroy(att->timeout_data);
+
+       if (att->debug_destroy)
+               att->debug_destroy(att->debug_data);
+
+       free(att->buf);
+       free(att);
+}
+
 struct bt_att *bt_att_new(int fd)
 {
        struct bt_att *att;
src/shared/att.c +2 -41
@@ -794,14 +820,7 @@ struct bt_att *bt_att_new(int fd)
        return bt_att_ref(att);
 
 fail:
-       queue_destroy(att->req_queue, NULL);
-       queue_destroy(att->ind_queue, NULL);
-       queue_destroy(att->write_queue, NULL);
-       queue_destroy(att->notify_list, NULL);
-       queue_destroy(att->disconn_list, NULL);
-       io_destroy(att->io);
-       free(att->buf);
-       free(att);
+       bt_att_free(att);
 
        return NULL;
 }
@@ -824,38 +843,7 @@ void bt_att_unref(struct bt_att *att)
        if (__sync_sub_and_fetch(&att->ref_count, 1))
                return;
 
-       bt_att_unregister_all(att);
-       bt_att_cancel_all(att);
-
-       if (att->pending_req)
-               destroy_att_send_op(att->pending_req);
-
-       if (att->pending_ind)
-               destroy_att_send_op(att->pending_ind);
-
-       io_destroy(att->io);
-       att->io = NULL;
-
-       queue_destroy(att->req_queue, NULL);
-       queue_destroy(att->ind_queue, NULL);
-       queue_destroy(att->write_queue, NULL);
-       queue_destroy(att->notify_list, NULL);
-       queue_destroy(att->disconn_list, NULL);
-       att->req_queue = NULL;
-       att->ind_queue = NULL;
-       att->write_queue = NULL;
-       att->notify_list = NULL;
-
-       if (att->timeout_destroy)
-               att->timeout_destroy(att->timeout_data);
-
-       if (att->debug_destroy)
-               att->debug_destroy(att->debug_data);
-
-       free(att->buf);
-       att->buf = NULL;
-
-       free(att);
+       bt_att_free(att);
 }
 
 bool bt_att_set_close_on_unref(struct bt_att *att, bool do_close)
--
Quoted 1 line

1.9.3

BR
Lukasz

Quoted 6 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 1 line
Luiz Augusto von Dentz