From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v2 3/4] plugins: Check btd_profile_register return value
Date: Tue, 9 Jun 2026 14:53:12 -0400 [thread overview]
Message-ID: <20260609185313.155105-3-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20260609185313.155105-1-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Ensure all plugin init functions check the return value of
btd_profile_register. If registration fails (e.g. bearer not enabled),
the plugin init propagates the error instead of continuing with an
unregistered profile.
---
profiles/audio/a2dp.c | 14 ++++++++++++--
profiles/audio/avrcp.c | 13 +++++++++++--
profiles/audio/hfp-hf.c | 4 +---
profiles/audio/micp.c | 7 ++++++-
profiles/input/manager.c | 4 +---
profiles/network/manager.c | 5 ++++-
src/gatt-database.c | 4 +++-
7 files changed, 38 insertions(+), 13 deletions(-)
diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index c7e0fc75c09e..a5e002784c02 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
@@ -3798,9 +3798,19 @@ static struct btd_adapter_driver media_driver = {
static int a2dp_init(void)
{
+ int err;
+
btd_register_adapter_driver(&media_driver);
- btd_profile_register(&a2dp_source_profile);
- btd_profile_register(&a2dp_sink_profile);
+
+ err = btd_profile_register(&a2dp_source_profile);
+ if (err)
+ return err;
+
+ err = btd_profile_register(&a2dp_sink_profile);
+ if (err) {
+ btd_profile_unregister(&a2dp_source_profile);
+ return err;
+ }
return 0;
}
diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index b6823753fe68..f63acd47091a 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -4987,8 +4987,17 @@ static struct btd_profile avrcp_controller_profile = {
static int avrcp_init(void)
{
- btd_profile_register(&avrcp_controller_profile);
- btd_profile_register(&avrcp_target_profile);
+ int err;
+
+ err = btd_profile_register(&avrcp_controller_profile);
+ if (err)
+ return err;
+
+ err = btd_profile_register(&avrcp_target_profile);
+ if (err) {
+ btd_profile_unregister(&avrcp_controller_profile);
+ return err;
+ }
populate_default_features();
diff --git a/profiles/audio/hfp-hf.c b/profiles/audio/hfp-hf.c
index c91b16426898..8de2d7a62d68 100644
--- a/profiles/audio/hfp-hf.c
+++ b/profiles/audio/hfp-hf.c
@@ -507,9 +507,7 @@ static struct btd_profile hfp_hf_profile = {
static int hfp_init(void)
{
- btd_profile_register(&hfp_hf_profile);
-
- return 0;
+ return btd_profile_register(&hfp_hf_profile);
}
static void hfp_exit(void)
diff --git a/profiles/audio/micp.c b/profiles/audio/micp.c
index 475f32daf75c..3d39ef5e147f 100644
--- a/profiles/audio/micp.c
+++ b/profiles/audio/micp.c
@@ -318,12 +318,17 @@ static unsigned int micp_id;
static int micp_init(void)
{
+ int err;
+
if (!(g_dbus_get_flags() & G_DBUS_FLAG_ENABLE_EXPERIMENTAL)) {
DBG("D-Bus experimental not enabled");
return -ENOTSUP;
}
- btd_profile_register(&micp_profile);
+ err = btd_profile_register(&micp_profile);
+ if (err)
+ return err;
+
micp_id = bt_micp_register(micp_attached, micp_detached, NULL);
return 0;
diff --git a/profiles/input/manager.c b/profiles/input/manager.c
index 0fcd6728c2fc..1fd82d82f500 100644
--- a/profiles/input/manager.c
+++ b/profiles/input/manager.c
@@ -118,12 +118,10 @@ static int input_init(void)
}
- btd_profile_register(&input_profile);
-
if (config)
g_key_file_free(config);
- return 0;
+ return btd_profile_register(&input_profile);
}
static void input_exit(void)
diff --git a/profiles/network/manager.c b/profiles/network/manager.c
index 693547d45fbc..a5f28a99ebfd 100644
--- a/profiles/network/manager.c
+++ b/profiles/network/manager.c
@@ -180,7 +180,10 @@ static int network_init(void)
if (server_init(conf_security) < 0)
return -1;
- btd_profile_register(&panu_profile);
+ err = btd_profile_register(&panu_profile);
+ if (err)
+ return err;
+
btd_profile_register(&gn_profile);
btd_profile_register(&nap_profile);
diff --git a/src/gatt-database.c b/src/gatt-database.c
index 680a52952b16..30e25b6f41ca 100644
--- a/src/gatt-database.c
+++ b/src/gatt-database.c
@@ -3624,7 +3624,9 @@ static void add_profile(void *data, void *user_data)
{
struct btd_adapter *adapter = user_data;
- btd_profile_register(data);
+ if (btd_profile_register(data))
+ return;
+
adapter_add_profile(adapter, data);
}
--
2.54.0
next prev parent reply other threads:[~2026-06-09 18:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-09 18:53 [PATCH BlueZ v2 1/4] btio: Handle EOPNOTSUPP from accept() to prevent busy loop Luiz Augusto von Dentz
2026-06-09 18:53 ` [PATCH BlueZ v2 2/4] profile: Check if bearer is enabled on registration Luiz Augusto von Dentz
2026-06-09 18:53 ` Luiz Augusto von Dentz [this message]
2026-06-09 18:53 ` [PATCH BlueZ v2 4/4] bearer: Check btd_opts.mode on btd_bearer_new Luiz Augusto von Dentz
2026-06-09 21:31 ` [BlueZ,v2,1/4] btio: Handle EOPNOTSUPP from accept() to prevent busy loop bluez.test.bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260609185313.155105-3-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox