Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp2551197pxb; Sun, 5 Sep 2021 23:07:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+c9VtkZcetZ1UXsnmf+03UZkCr7gl/OyTS41qbYr0CLBUHU9mP4+yPud0tp/B51yp3Xuz X-Received: by 2002:a05:6638:50f:: with SMTP id i15mr9548668jar.79.1630908423376; Sun, 05 Sep 2021 23:07:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630908423; cv=none; d=google.com; s=arc-20160816; b=p3wYTQQ4/HdnSaX9TMdUFtiMIHT0QBe3yJhymLKgeLscX/mZdkhdPupjkbmW7wggIe aTlitLHLHh2Tz2LmDk2h8+gMQh93eE+pfJBXSBNohd98M8djZBSugRZl8BZUnQjEcTuZ Mw4jkrpLckJr70DjyiHLMZT0rxb6tRj+SnJ7CtBJ/AxbrezQImjfaelUa7Ynyva0/Inp vm9GJfqwO884lRgUSb/XFJe+7v2cE3DgSvqFFO1fFVx4KBCF+hHq6P6tNTb5D9jfmzeN Jonzqe0iKt0jkadOStvLCf6GKcDeGB9IdQthAxGvr8wrzvb6Vve9PZC5OQTwtmgf6+gk KQzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=pTDaSxJkExjIr9d5Cl6MptNCwx4AFUjqpvcw+0x4KLs=; b=FIpUOZfhH0W1LBD9Cra+1GeGB8b5ZxYDnxT/UtbOeckEpvtIEwzszEeep8m5VDIGBL h4OBkEJbaLQKB5TUtxncCdiwPhiEg9HC5oqJw7Y9rcvHMUMVbhQcuhJOV/OccTe7o7Sy BT77e/Z7S8mfKhVuzaMMBa7r/imglcow1lPq7gvVbHjIdNjPI7J+Xb72Rj5cvw6LqUSn NbrA18vroBhiqFEDaaP5TAIBJ79vTHsYhqMwqGhaqEFa+J9CHfh3eibrS9o1DgVtnufT S6IAOyy6dmEQkwbSrpq8IA2DJ0CGd0krsHe/XS2/0d8LyT5Hefrt/YPn9fowgDpJ3FwO Np0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=MSWAGvQq; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e16si7220381ilm.91.2021.09.05.23.06.43; Sun, 05 Sep 2021 23:07:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=MSWAGvQq; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239474AbhIFGEe (ORCPT + 99 others); Mon, 6 Sep 2021 02:04:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239433AbhIFGEb (ORCPT ); Mon, 6 Sep 2021 02:04:31 -0400 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD323C061575 for ; Sun, 5 Sep 2021 23:03:26 -0700 (PDT) Received: by mail-qv1-xf4a.google.com with SMTP id l3-20020a056214104300b00366988901acso10474039qvr.2 for ; Sun, 05 Sep 2021 23:03:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=pTDaSxJkExjIr9d5Cl6MptNCwx4AFUjqpvcw+0x4KLs=; b=MSWAGvQqQzO110b/zcJCPQiXnu0gGELOYu0PTcrs8DwTa4Mz2xSdQIXw876fkzukzP USDbx3TGwI2/Z56YnpRRxYHHjK62yAeVf2klNI385MRVPSKwOzBd3a+SeZXgVErg74Gr IslkmPXHZEkivRegfzjP0AshMjZEKgYUNu1VBfuNz4PjWhaeqymNDjscZzes6SwM0x8r 8uOnmW2HPirvsmk+K7hs4iHx7W4/mvnaDfdrddZ9TkOfllFIK0AxU/gIKw5NZatxlvc7 /xI/vffTSU96UFOQIhC9nOtgBN03ygm82ynMMc3HTJuOKS7P7nM0VPzUC795gEZ3DckG MpeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=pTDaSxJkExjIr9d5Cl6MptNCwx4AFUjqpvcw+0x4KLs=; b=T1bnwP3Bf7kAYVCnscmyIrBxEiwt1Mvc6tuSz0ElOZXEQwW03Z9/G+0itIlVGRpkhD +/oaXAbL66U1D2hljKEALb86463xKamb4WO8OXpeaQ1jLw/sHzCoZHUHv7YF5vxN+vEk pnW5SYG2Q5cYQ2cyYUZGW0E9FAlZQ2HaHVNy+VVGoO+0294kgRYSmxis/r2d/po1AP0R +WtKZ7TCozmi4zKEal8RHQM/Y5EVw1f3L/xzbJTWKBy3dhYzxE7aODcPIBJTjXGoDUQf T4ljc+54t1IBPptgoiao84nvKeiIh/L/g3nkB6pT/TsZvyHBjgZeTtt1q2XzZ6Q4+kql LLoQ== X-Gm-Message-State: AOAM532aFntqJslI2fwaX9vtpdIvgAowm/K+zGKNzwdJRafFv5sID8pl YREM07+Y40oKm6EWOnxdalKBVHbPPCdBJT3pysEiMS0dPaWoapHQq6jU65Jcb1xnEQNtQ4bB4iW RfxhXnO6OYd6pSKeVT+0OcQw/fc1iqQdFsDsY7imvn2FGTPoRjaRwg0QeTdX3HXq0M55jB7poNJ cLSAOQyuSTywc= X-Received: from howardchung-p920.tpe.corp.google.com ([2401:fa00:1:10:d42:c8a9:b5b9:8c48]) (user=howardchung job=sendgmr) by 2002:ad4:562c:: with SMTP id cb12mr10144872qvb.6.1630908205758; Sun, 05 Sep 2021 23:03:25 -0700 (PDT) Date: Mon, 6 Sep 2021 14:03:16 +0800 Message-Id: <20210906140250.Bluez.v2.1.Id597e5ae87e680e6a744a8ed08d5000aacfce867@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.33.0.153.gba50c8fa24-goog Subject: [Bluez PATCH v2 1/2] plugins/admin: add adapter_remove handler From: Howard Chung To: linux-bluetooth@vger.kernel.org, luiz.dentz@gmail.com Cc: Yun-Hao Chung , Shyh-In Hwang , Miao-chen Chou Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Yun-Hao Chung Currently admin doesn't handle adapter removed callbacks, which causes interfaces AdminPolicySet1 and AdminPolicyStatus1 not being unregistered, which in turns causes these interfaces can not be re-registered once adapter is back. This adds handler for adapter_remove. Reviewed-by: Shyh-In Hwang Reviewed-by: Miao-chen Chou --- tested with following steps 1. rmmod btusb 2. modprobe btusb 3. read allowlist via bluetoothctl Changes in v2: 1. Fix make errors plugins/admin.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/plugins/admin.c b/plugins/admin.c index 02fec04568ba..82c00cabdb6b 100644 --- a/plugins/admin.c +++ b/plugins/admin.c @@ -85,6 +85,17 @@ static void admin_policy_free(void *data) g_free(admin_policy); } +static void admin_policy_destroy(struct btd_admin_policy *admin_policy) +{ + const char *path = adapter_get_path(admin_policy->adapter); + + g_dbus_unregister_interface(dbus_conn, path, + ADMIN_POLICY_SET_INTERFACE); + g_dbus_unregister_interface(dbus_conn, path, + ADMIN_POLICY_STATUS_INTERFACE); + admin_policy_free(admin_policy); +} + static bool uuid_match(const void *data, const void *match_data) { const bt_uuid_t *uuid = data; @@ -492,7 +503,7 @@ static int admin_policy_adapter_probe(struct btd_adapter *adapter) if (!g_dbus_register_interface(dbus_conn, adapter_path, ADMIN_POLICY_SET_INTERFACE, admin_policy_adapter_methods, NULL, - NULL, policy_data, admin_policy_free)) { + NULL, policy_data, NULL)) { btd_error(policy_data->adapter_id, "Admin Policy Set interface init failed on path %s", adapter_path); @@ -506,7 +517,7 @@ static int admin_policy_adapter_probe(struct btd_adapter *adapter) ADMIN_POLICY_STATUS_INTERFACE, NULL, NULL, admin_policy_adapter_properties, - policy_data, admin_policy_free)) { + policy_data, NULL)) { btd_error(policy_data->adapter_id, "Admin Policy Status interface init failed on path %s", adapter_path); @@ -574,10 +585,24 @@ static void admin_policy_device_removed(struct btd_adapter *adapter, unregister_device_data(data, NULL); } +static void admin_policy_remove(struct btd_adapter *adapter) +{ + DBG(""); + + queue_foreach(devices, unregister_device_data, NULL); + queue_destroy(devices, g_free); + + if (policy_data) { + admin_policy_destroy(policy_data); + policy_data = NULL; + } +} + static struct btd_adapter_driver admin_policy_driver = { .name = "admin_policy", .probe = admin_policy_adapter_probe, .resume = NULL, + .remove = admin_policy_remove, .device_resolved = admin_policy_device_added, .device_removed = admin_policy_device_removed }; @@ -597,11 +622,7 @@ static void admin_exit(void) DBG(""); btd_unregister_adapter_driver(&admin_policy_driver); - queue_foreach(devices, unregister_device_data, NULL); - queue_destroy(devices, g_free); - - if (policy_data) - admin_policy_free(policy_data); + admin_policy_remove(NULL); } BLUETOOTH_PLUGIN_DEFINE(admin, VERSION, -- 2.33.0.153.gba50c8fa24-goog