2016-09-30 15:39:18

by Wu, Jiangbo

[permalink] [raw]
Subject: [PATCH] src/device: Free bonding while failed to pair device

From: Jiangbo Wu <[email protected]>

---
src/device.c | 62 +++++++++++++++++++++++++++++++-----------------------------
1 file changed, 32 insertions(+), 30 deletions(-)

diff --git a/src/device.c b/src/device.c
index 25d2e22..fb6104f 100644
--- a/src/device.c
+++ b/src/device.c
@@ -2314,6 +2314,35 @@ static void create_bond_req_exit(DBusConnection *conn, void *user_data)
}
}

+static void bonding_request_free(struct bonding_req *bonding)
+{
+ if (!bonding)
+ return;
+
+ if (bonding->listener_id)
+ g_dbus_remove_watch(dbus_conn, bonding->listener_id);
+
+ if (bonding->msg)
+ dbus_message_unref(bonding->msg);
+
+ if (bonding->cb_iter)
+ g_free(bonding->cb_iter);
+
+ if (bonding->agent) {
+ agent_cancel(bonding->agent);
+ agent_unref(bonding->agent);
+ bonding->agent = NULL;
+ }
+
+ if (bonding->retry_timer)
+ g_source_remove(bonding->retry_timer);
+
+ if (bonding->device)
+ bonding->device->bonding = NULL;
+
+ g_free(bonding);
+}
+
static DBusMessage *pair_device(DBusConnection *conn, DBusMessage *msg,
void *data)
{
@@ -2384,8 +2413,10 @@ static DBusMessage *pair_device(DBusConnection *conn, DBusMessage *msg,
BDADDR_BREDR, io_cap);
}

- if (err < 0)
+ if (err < 0) {
+ bonding_request_free(device->bonding);
return btd_error_failed(msg, strerror(-err));
+ }

return NULL;
}
@@ -2426,35 +2457,6 @@ static DBusMessage *new_authentication_return(DBusMessage *msg, uint8_t status)
}
}

-static void bonding_request_free(struct bonding_req *bonding)
-{
- if (!bonding)
- return;
-
- if (bonding->listener_id)
- g_dbus_remove_watch(dbus_conn, bonding->listener_id);
-
- if (bonding->msg)
- dbus_message_unref(bonding->msg);
-
- if (bonding->cb_iter)
- g_free(bonding->cb_iter);
-
- if (bonding->agent) {
- agent_cancel(bonding->agent);
- agent_unref(bonding->agent);
- bonding->agent = NULL;
- }
-
- if (bonding->retry_timer)
- g_source_remove(bonding->retry_timer);
-
- if (bonding->device)
- bonding->device->bonding = NULL;
-
- g_free(bonding);
-}
-
static void device_cancel_bonding(struct btd_device *device, uint8_t status)
{
struct bonding_req *bonding = device->bonding;
--
1.9.1



2016-10-03 08:11:15

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH] src/device: Free bonding while failed to pair device

Hi,

On Sun, Oct 2, 2016 at 3:38 PM, <[email protected]> wrote:
> From: Jiangbo Wu <[email protected]>
>
> device unable pair since another pairng is in progress, and need to
> free bonding before it created for next pairing.
> ---
> src/device.c | 62 +++++++++++++++++++++++++++++++-----------------------------
> 1 file changed, 32 insertions(+), 30 deletions(-)
>
> diff --git a/src/device.c b/src/device.c
> index 25d2e22..fb6104f 100644
> --- a/src/device.c
> +++ b/src/device.c
> @@ -2314,6 +2314,35 @@ static void create_bond_req_exit(DBusConnection *conn, void *user_data)
> }
> }
>
> +static void bonding_request_free(struct bonding_req *bonding)
> +{
> + if (!bonding)
> + return;
> +
> + if (bonding->listener_id)
> + g_dbus_remove_watch(dbus_conn, bonding->listener_id);
> +
> + if (bonding->msg)
> + dbus_message_unref(bonding->msg);
> +
> + if (bonding->cb_iter)
> + g_free(bonding->cb_iter);
> +
> + if (bonding->agent) {
> + agent_cancel(bonding->agent);
> + agent_unref(bonding->agent);
> + bonding->agent = NULL;
> + }
> +
> + if (bonding->retry_timer)
> + g_source_remove(bonding->retry_timer);
> +
> + if (bonding->device)
> + bonding->device->bonding = NULL;
> +
> + g_free(bonding);
> +}
> +
> static DBusMessage *pair_device(DBusConnection *conn, DBusMessage *msg,
> void *data)
> {
> @@ -2384,8 +2413,10 @@ static DBusMessage *pair_device(DBusConnection *conn, DBusMessage *msg,
> BDADDR_BREDR, io_cap);
> }
>
> - if (err < 0)
> + if (err < 0) {
> + bonding_request_free(device->bonding);
> return btd_error_failed(msg, strerror(-err));
> + }
>
> return NULL;
> }
> @@ -2426,35 +2457,6 @@ static DBusMessage *new_authentication_return(DBusMessage *msg, uint8_t status)
> }
> }
>
> -static void bonding_request_free(struct bonding_req *bonding)
> -{
> - if (!bonding)
> - return;
> -
> - if (bonding->listener_id)
> - g_dbus_remove_watch(dbus_conn, bonding->listener_id);
> -
> - if (bonding->msg)
> - dbus_message_unref(bonding->msg);
> -
> - if (bonding->cb_iter)
> - g_free(bonding->cb_iter);
> -
> - if (bonding->agent) {
> - agent_cancel(bonding->agent);
> - agent_unref(bonding->agent);
> - bonding->agent = NULL;
> - }
> -
> - if (bonding->retry_timer)
> - g_source_remove(bonding->retry_timer);
> -
> - if (bonding->device)
> - bonding->device->bonding = NULL;
> -
> - g_free(bonding);
> -}
> -
> static void device_cancel_bonding(struct btd_device *device, uint8_t status)
> {
> struct bonding_req *bonding = device->bonding;
> --
> 1.9.1

Applied, thanks.


--
Luiz Augusto von Dentz

2016-10-01 16:55:47

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH] src/device: Free bonding while failed to pair device

Hi,

On Fri, Sep 30, 2016 at 6:39 PM, <[email protected]> wrote:
> From: Jiangbo Wu <[email protected]>

It would be good to have something in the patch description, perhaps
the backtrace if this is a crash fix or perhaps this comes from a
static analyzer?

> ---
> src/device.c | 62 +++++++++++++++++++++++++++++++-----------------------------
> 1 file changed, 32 insertions(+), 30 deletions(-)
>
> diff --git a/src/device.c b/src/device.c
> index 25d2e22..fb6104f 100644
> --- a/src/device.c
> +++ b/src/device.c
> @@ -2314,6 +2314,35 @@ static void create_bond_req_exit(DBusConnection *conn, void *user_data)
> }
> }
>
> +static void bonding_request_free(struct bonding_req *bonding)
> +{
> + if (!bonding)
> + return;
> +
> + if (bonding->listener_id)
> + g_dbus_remove_watch(dbus_conn, bonding->listener_id);
> +
> + if (bonding->msg)
> + dbus_message_unref(bonding->msg);
> +
> + if (bonding->cb_iter)
> + g_free(bonding->cb_iter);
> +
> + if (bonding->agent) {
> + agent_cancel(bonding->agent);
> + agent_unref(bonding->agent);
> + bonding->agent = NULL;
> + }
> +
> + if (bonding->retry_timer)
> + g_source_remove(bonding->retry_timer);
> +
> + if (bonding->device)
> + bonding->device->bonding = NULL;
> +
> + g_free(bonding);
> +}
> +
> static DBusMessage *pair_device(DBusConnection *conn, DBusMessage *msg,
> void *data)
> {
> @@ -2384,8 +2413,10 @@ static DBusMessage *pair_device(DBusConnection *conn, DBusMessage *msg,
> BDADDR_BREDR, io_cap);
> }
>
> - if (err < 0)
> + if (err < 0) {
> + bonding_request_free(device->bonding);
> return btd_error_failed(msg, strerror(-err));
> + }
>
> return NULL;
> }
> @@ -2426,35 +2457,6 @@ static DBusMessage *new_authentication_return(DBusMessage *msg, uint8_t status)
> }
> }
>
> -static void bonding_request_free(struct bonding_req *bonding)
> -{
> - if (!bonding)
> - return;
> -
> - if (bonding->listener_id)
> - g_dbus_remove_watch(dbus_conn, bonding->listener_id);
> -
> - if (bonding->msg)
> - dbus_message_unref(bonding->msg);
> -
> - if (bonding->cb_iter)
> - g_free(bonding->cb_iter);
> -
> - if (bonding->agent) {
> - agent_cancel(bonding->agent);
> - agent_unref(bonding->agent);
> - bonding->agent = NULL;
> - }
> -
> - if (bonding->retry_timer)
> - g_source_remove(bonding->retry_timer);
> -
> - if (bonding->device)
> - bonding->device->bonding = NULL;
> -
> - g_free(bonding);
> -}
> -
> static void device_cancel_bonding(struct btd_device *device, uint8_t status)
> {
> struct bonding_req *bonding = device->bonding;
> --
> 1.9.1
>
> --
> 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



--
Luiz Augusto von Dentz