Skip to content

Commit

Permalink
Bluetooth: PACS: Fix logical dead paths
Browse files Browse the repository at this point in the history
In pac_notify and pac_notify_loc coverity found logical dead
paths since if both sink and source notify was disabled,
the functions would still be compiled, but would
never get past the default case.

This is not a real issue as the functions were never called
in that case, but to make coverity happy, and to prevent
any future issues where the functions may be called
incorrectly, the static functions are now fully guarded.

Signed-off-by: Emil Gydesen <[email protected]>
  • Loading branch information
Thalley committed Jan 3, 2024
1 parent 8f0abaf commit 3aa5696
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions subsys/bluetooth/audio/pacs.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ static atomic_t notify_rdy;
static K_SEM_DEFINE(read_buf_sem, 1, 1);
NET_BUF_SIMPLE_DEFINE_STATIC(read_buf, BT_ATT_MAX_ATTRIBUTE_LEN);

#if defined(CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE) || defined(CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE)
static int pac_notify_loc(struct bt_conn *conn, enum bt_audio_dir dir);
#endif /* CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE || CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE*/
static int pacs_gatt_notify(struct bt_conn *conn,
const struct bt_uuid *uuid,
const struct bt_gatt_attr *attr,
Expand Down Expand Up @@ -634,28 +631,25 @@ BT_GATT_SERVICE_DEFINE(pacs_svc,
BT_PAC_SUPPORTED_CONTEXT(supported_context_read)
);

#if defined(CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE) || defined(CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE)
static int pac_notify_loc(struct bt_conn *conn, enum bt_audio_dir dir)
{
uint32_t location_le;
int err;
const struct bt_uuid *uuid;

switch (dir) {
case BT_AUDIO_DIR_SINK:
#if defined(CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE)
case BT_AUDIO_DIR_SINK:
location_le = sys_cpu_to_le32(pacs_snk_location);
uuid = pacs_snk_loc_uuid;
break;
#else
return -ENOTSUP;
#endif /* CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE */
case BT_AUDIO_DIR_SOURCE:
#if defined(CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE)
case BT_AUDIO_DIR_SOURCE:
location_le = sys_cpu_to_le32(pacs_src_location);
uuid = pacs_src_loc_uuid;
break;
#else
return -ENOTSUP;
#endif /* CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE */
default:
return -EINVAL;
Expand All @@ -669,7 +663,9 @@ static int pac_notify_loc(struct bt_conn *conn, enum bt_audio_dir dir)

return 0;
}
#endif /* CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE || CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE */

#if defined(CONFIG_BT_PAC_SNK_NOTIFIABLE) || defined(CONFIG_BT_PAC_SRC_NOTIFIABLE)
static int pac_notify(struct bt_conn *conn, enum bt_audio_dir dir)
{
int err = 0;
Expand Down Expand Up @@ -716,6 +712,7 @@ static int pac_notify(struct bt_conn *conn, enum bt_audio_dir dir)
return 0;
}
}
#endif /* CONFIG_BT_PAC_SNK_NOTIFIABLE || CONFIG_BT_PAC_SRC_NOTIFIABLE */

static int available_contexts_notify(struct bt_conn *conn)
{
Expand Down Expand Up @@ -822,39 +819,45 @@ static void notify_cb(struct bt_conn *conn, void *data)
return;
}

if (IS_ENABLED(CONFIG_BT_PAC_SNK_NOTIFIABLE) &&
atomic_test_bit(client->flags, FLAG_SINK_PAC_CHANGED)) {
#if defined(CONFIG_BT_PAC_SNK_NOTIFIABLE)
if (atomic_test_bit(client->flags, FLAG_SINK_PAC_CHANGED)) {
LOG_DBG("Notifying Sink PAC");
err = pac_notify(conn, BT_AUDIO_DIR_SINK);
if (!err) {
atomic_clear_bit(client->flags, FLAG_SINK_PAC_CHANGED);
}
}
#endif /* CONFIG_BT_PAC_SNK_NOTIFIABLE */

if (IS_ENABLED(CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE) &&
atomic_test_bit(client->flags, FLAG_SINK_AUDIO_LOCATIONS_CHANGED)) {
#if defined(CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE)
if (atomic_test_bit(client->flags, FLAG_SINK_AUDIO_LOCATIONS_CHANGED)) {
LOG_DBG("Notifying Sink Audio Location");
err = pac_notify_loc(conn, BT_AUDIO_DIR_SINK);
if (!err) {
atomic_clear_bit(client->flags, FLAG_SINK_AUDIO_LOCATIONS_CHANGED);
}
}
if (IS_ENABLED(CONFIG_BT_PAC_SRC_NOTIFIABLE) &&
atomic_test_bit(client->flags, FLAG_SOURCE_PAC_CHANGED)) {
#endif /* CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE */

#if defined(CONFIG_BT_PAC_SRC_NOTIFIABLE)
if (atomic_test_bit(client->flags, FLAG_SOURCE_PAC_CHANGED)) {
LOG_DBG("Notifying Source PAC");
err = pac_notify(conn, BT_AUDIO_DIR_SOURCE);
if (!err) {
atomic_clear_bit(client->flags, FLAG_SOURCE_PAC_CHANGED);
}
}
if (IS_ENABLED(CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE) &&
atomic_test_and_clear_bit(client->flags, FLAG_SOURCE_AUDIO_LOCATIONS_CHANGED)) {
#endif /* CONFIG_BT_PAC_SRC_NOTIFIABLE */

#if defined(CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE)
if (atomic_test_and_clear_bit(client->flags, FLAG_SOURCE_AUDIO_LOCATIONS_CHANGED)) {
LOG_DBG("Notifying Source Audio Location");
err = pac_notify_loc(conn, BT_AUDIO_DIR_SOURCE);
if (!err) {
atomic_clear_bit(client->flags, FLAG_SOURCE_AUDIO_LOCATIONS_CHANGED);
}
}
#endif /* CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE */

if (atomic_test_bit(client->flags, FLAG_AVAILABLE_AUDIO_CONTEXT_CHANGED)) {
LOG_DBG("Notifying Available Contexts");
Expand Down

0 comments on commit 3aa5696

Please sign in to comment.