linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BlueZ] battery: Check interface before getting property
@ 2023-05-28  7:44 Arkadiusz Bokowy
  2023-05-28  9:35 ` [BlueZ] " bluez.test.bot
  2023-06-07 19:50 ` [PATCH BlueZ] " patchwork-bot+bluetooth
  0 siblings, 2 replies; 3+ messages in thread
From: Arkadiusz Bokowy @ 2023-05-28  7:44 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Arkadiusz Bokowy

Client can export other interfaces than the BatteryProvide1 on the
registered object manager. So, before getting battery provider specific
property, validate that we are operating on the right interface.

This change will allow client to implement only one object manger for
media applications, players and battery providers without triggering
error message.
---
 src/battery.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/battery.c b/src/battery.c
index 88a53e80e..5c52581f3 100644
--- a/src/battery.c
+++ b/src/battery.c
@@ -288,6 +288,10 @@ static void provided_battery_added_cb(GDBusProxy *proxy, void *user_data)
 	uint8_t percentage;
 	DBusMessageIter iter;
 
+	if (strcmp(g_dbus_proxy_get_interface(proxy),
+		   BATTERY_PROVIDER_INTERFACE) != 0)
+		return;
+
 	if (g_dbus_proxy_get_property(proxy, "Device", &iter) == FALSE) {
 		warn("Battery object %s does not specify device path", path);
 		return;
@@ -295,10 +299,6 @@ static void provided_battery_added_cb(GDBusProxy *proxy, void *user_data)
 
 	dbus_message_iter_get_basic(&iter, &export_path);
 
-	if (strcmp(g_dbus_proxy_get_interface(proxy),
-		   BATTERY_PROVIDER_INTERFACE) != 0)
-		return;
-
 	device = btd_adapter_find_device_by_path(provider->manager->adapter,
 						 export_path);
 	if (!device || device_is_temporary(device)) {
@@ -341,15 +341,15 @@ static void provided_battery_removed_cb(GDBusProxy *proxy, void *user_data)
 	const char *export_path;
 	DBusMessageIter iter;
 
+	if (strcmp(g_dbus_proxy_get_interface(proxy),
+		   BATTERY_PROVIDER_INTERFACE) != 0)
+		return;
+
 	if (g_dbus_proxy_get_property(proxy, "Device", &iter) == FALSE)
 		return;
 
 	dbus_message_iter_get_basic(&iter, &export_path);
 
-	if (strcmp(g_dbus_proxy_get_interface(proxy),
-		   BATTERY_PROVIDER_INTERFACE) != 0)
-		return;
-
 	DBG("provided battery removed %s", g_dbus_proxy_get_path(proxy));
 
 	battery = find_battery_by_path(export_path);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-06-07 19:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-28  7:44 [PATCH BlueZ] battery: Check interface before getting property Arkadiusz Bokowy
2023-05-28  9:35 ` [BlueZ] " bluez.test.bot
2023-06-07 19:50 ` [PATCH BlueZ] " patchwork-bot+bluetooth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).