Bluetooth: Audio: Fix HAS double register
Calling bt_has_register multiple times would cause attempts
to register a HAS multiple times. Fixed by adding a check
and return with EALREADY if it is already registered.
@@ -1128,6 +1128,7 @@ int bt_has_preset_name_change(uint8_t index, const char *name)
int bt_has_register(const struct bt_has_register_param *param)
{
+ static bool registered;
int err;
LOG_DBG("param %p", param);
@@ -1137,6 +1138,10 @@ int bt_has_register(const struct bt_has_register_param *param)
return -EINVAL;
}
+ if (registered) {
+ return -EALREADY;
+ }
+
/* Initialize the supported features characteristic value */
has.features = param->type;
@@ -1179,5 +1184,7 @@ int bt_has_register(const struct bt_has_register_param *param)
k_work_init(&active_preset_work, active_preset_work_process);
#endif /* CONFIG_BT_HAS_PRESET_SUPPORT */
+ registered = true;
+
return 0;
}
