From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v1 3/4] battery: Document the unknown sentinels and fix a stale name
Date: Thu, 10 Sep 2026 14:42:15 -0400 [thread overview]
Message-ID: <20260910184216.1601639-3-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20260910184216.1601639-1-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
btd_battery_update() treats UINT8_MAX and btd_battery_update_charging()
treats -1 as "unknown", invalidating the D-Bus property rather than
setting it. Neither was documented at the prototypes.
Also rename unregister_if_path_has_prefix() to
unregister_if_provider_matches(); it no longer compares path prefixes,
it compares the owning provider.
Assisted-by: opencode:claude-opus-5
---
src/battery.c | 4 ++--
src/battery.h | 8 ++++++++
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/battery.c b/src/battery.c
index 181bf3846d52..dbfe56881259 100644
--- a/src/battery.c
+++ b/src/battery.c
@@ -664,7 +664,7 @@ static bool match_provider_path(const void *data, const void *user_data)
return strcmp(provider->path, path) == 0;
}
-static void unregister_if_path_has_prefix(void *data, void *user_data)
+static void unregister_if_provider_matches(void *data, void *user_data)
{
struct btd_battery *battery = data;
struct battery_provider *provider = user_data;
@@ -678,7 +678,7 @@ static void battery_provider_free(gpointer data)
struct battery_provider *provider = data;
/* Unregister batteries registered by this provider. */
- queue_foreach(batteries, unregister_if_path_has_prefix, provider);
+ queue_foreach(batteries, unregister_if_provider_matches, provider);
if (provider->owner)
g_free(provider->owner);
diff --git a/src/battery.h b/src/battery.h
index 2b459809cba6..5990c8e0b87f 100644
--- a/src/battery.h
+++ b/src/battery.h
@@ -18,7 +18,15 @@ struct btd_battery *btd_battery_register_component(const char *device_path,
const char *identifier,
const char *source);
bool btd_battery_unregister(struct btd_battery *battery);
+
+/* Pass UINT8_MAX as percentage to mark the level as unknown, which
+ * invalidates the Percentage property instead of setting it.
+ */
bool btd_battery_update(struct btd_battery *battery, uint8_t percentage);
+
+/* charging is 0 or 1 when known, or -1 to mark the state as unknown, which
+ * invalidates the Charging property instead of setting it.
+ */
bool btd_battery_update_charging(struct btd_battery *battery, int charging);
struct btd_battery_provider_manager *
--
2.55.0
next prev parent reply other threads:[~2026-09-10 18:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-10 18:42 [PATCH BlueZ v1 1/4] gatt-server: Check prepare write length before reallocating Luiz Augusto von Dentz
2026-09-10 18:42 ` [PATCH BlueZ v1 2/4] adapter: Unify the A2DP admin allowlist UUID mapping Luiz Augusto von Dentz
2026-09-10 18:42 ` Luiz Augusto von Dentz [this message]
2026-09-10 18:42 ` [PATCH BlueZ v1 4/4] client/bluetoothctl: Declare the controller helper in its own header Luiz Augusto von Dentz
2026-09-10 20:06 ` [BlueZ,v1,1/4] gatt-server: Check prepare write length before reallocating 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=20260910184216.1601639-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