Hi, On Wed, Nov 16, 2016 at 5:01 PM, Luiz Augusto von Dentz <luiz.dentz@xxxxxxxxx> wrote: > From: Luiz Augusto von Dentz <luiz.von.dentz@xxxxxxxxx> > > The instance id needs to be cleared in case of an error during > registration otherwise it cannot be reused anymore. > --- > src/advertising.c | 25 +++++++++++++------------ > 1 file changed, 13 insertions(+), 12 deletions(-) > > diff --git a/src/advertising.c b/src/advertising.c > index e5cd31c..ef84e45 100644 > --- a/src/advertising.c > +++ b/src/advertising.c > @@ -95,6 +95,9 @@ static void advertisement_free(void *data) > g_dbus_client_unref(ad->client); > } > > + if (ad->instance) > + util_clear_uid(&ad->manager->instance_bitmap, ad->instance); > + > bt_ad_unref(ad->data); > > g_dbus_proxy_unref(ad->proxy); > @@ -155,8 +158,6 @@ static void advertisement_remove(void *data) > > queue_remove(ad->manager->ads, ad); > > - util_clear_uid(&ad->manager->instance_bitmap, ad->instance); > - > g_idle_add(advertisement_free_idle_cb, ad); > } > > @@ -585,7 +586,8 @@ static void advertisement_proxy_added(GDBusProxy *proxy, void *data) > ad->reg = NULL; > } > > -static struct advertisement *advertisement_create(DBusConnection *conn, > +static struct advertisement * > +advertisement_create(struct btd_advertising *manager, DBusConnection *conn, > DBusMessage *msg, const char *path) > { > struct advertisement *ad; > @@ -621,6 +623,13 @@ static struct advertisement *advertisement_create(DBusConnection *conn, > if (!ad->data) > goto fail; > > + ad->instance = util_get_uid(&manager->instance_bitmap, > + manager->max_ads); > + if (!ad->instance) > + goto fail; > + > + ad->manager = manager; > + > return ad; > > fail: > @@ -636,7 +645,6 @@ static DBusMessage *register_advertisement(DBusConnection *conn, > DBusMessageIter args; > struct advertisement *ad; > struct dbus_obj_match match; > - uint8_t instance; > > DBG("RegisterAdvertisement"); > > @@ -653,25 +661,18 @@ static DBusMessage *register_advertisement(DBusConnection *conn, > if (queue_find(manager->ads, match_advertisement, &match)) > return btd_error_already_exists(msg); > > - instance = util_get_uid(&manager->instance_bitmap, manager->max_ads); > - if (!instance) > - return btd_error_failed(msg, "Maximum advertisements reached"); > - > dbus_message_iter_next(&args); > > if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_ARRAY) > return btd_error_invalid_args(msg); > > - ad = advertisement_create(conn, msg, match.path); > + ad = advertisement_create(manager, conn, msg, match.path); > if (!ad) > return btd_error_failed(msg, > "Failed to register advertisement"); > > DBG("Registered advertisement at path %s", match.path); > > - ad->instance = instance; > - ad->manager = manager; > - > queue_push_tail(manager->ads, ad); > > return NULL; > -- > 2.7.4 Applied. -- Luiz Augusto von Dentz -- To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html