Skip to content

Commit bf37784

Browse files
ThalleyMaureenHelm
authored andcommitted
Bluetooth: PACS: Fix logical dead paths
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]>
1 parent 9fc630d commit bf37784

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

subsys/bluetooth/audio/pacs.c

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ static atomic_t notify_rdy;
8686
static K_SEM_DEFINE(read_buf_sem, 1, 1);
8787
NET_BUF_SIMPLE_DEFINE_STATIC(read_buf, BT_ATT_MAX_ATTRIBUTE_LEN);
8888

89-
#if defined(CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE) || defined(CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE)
90-
static int pac_notify_loc(struct bt_conn *conn, enum bt_audio_dir dir);
91-
#endif /* CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE || CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE*/
9289
static int pacs_gatt_notify(struct bt_conn *conn,
9390
const struct bt_uuid *uuid,
9491
const struct bt_gatt_attr *attr,
@@ -634,28 +631,25 @@ BT_GATT_SERVICE_DEFINE(pacs_svc,
634631
BT_PAC_SUPPORTED_CONTEXT(supported_context_read)
635632
);
636633

634+
#if defined(CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE) || defined(CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE)
637635
static int pac_notify_loc(struct bt_conn *conn, enum bt_audio_dir dir)
638636
{
639637
uint32_t location_le;
640638
int err;
641639
const struct bt_uuid *uuid;
642640

643641
switch (dir) {
644-
case BT_AUDIO_DIR_SINK:
645642
#if defined(CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE)
643+
case BT_AUDIO_DIR_SINK:
646644
location_le = sys_cpu_to_le32(pacs_snk_location);
647645
uuid = pacs_snk_loc_uuid;
648646
break;
649-
#else
650-
return -ENOTSUP;
651647
#endif /* CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE */
652-
case BT_AUDIO_DIR_SOURCE:
653648
#if defined(CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE)
649+
case BT_AUDIO_DIR_SOURCE:
654650
location_le = sys_cpu_to_le32(pacs_src_location);
655651
uuid = pacs_src_loc_uuid;
656652
break;
657-
#else
658-
return -ENOTSUP;
659653
#endif /* CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE */
660654
default:
661655
return -EINVAL;
@@ -669,7 +663,9 @@ static int pac_notify_loc(struct bt_conn *conn, enum bt_audio_dir dir)
669663

670664
return 0;
671665
}
666+
#endif /* CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE || CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE */
672667

668+
#if defined(CONFIG_BT_PAC_SNK_NOTIFIABLE) || defined(CONFIG_BT_PAC_SRC_NOTIFIABLE)
673669
static int pac_notify(struct bt_conn *conn, enum bt_audio_dir dir)
674670
{
675671
int err = 0;
@@ -716,6 +712,7 @@ static int pac_notify(struct bt_conn *conn, enum bt_audio_dir dir)
716712
return 0;
717713
}
718714
}
715+
#endif /* CONFIG_BT_PAC_SNK_NOTIFIABLE || CONFIG_BT_PAC_SRC_NOTIFIABLE */
719716

720717
static int available_contexts_notify(struct bt_conn *conn)
721718
{
@@ -822,39 +819,45 @@ static void notify_cb(struct bt_conn *conn, void *data)
822819
return;
823820
}
824821

825-
if (IS_ENABLED(CONFIG_BT_PAC_SNK_NOTIFIABLE) &&
826-
atomic_test_bit(client->flags, FLAG_SINK_PAC_CHANGED)) {
822+
#if defined(CONFIG_BT_PAC_SNK_NOTIFIABLE)
823+
if (atomic_test_bit(client->flags, FLAG_SINK_PAC_CHANGED)) {
827824
LOG_DBG("Notifying Sink PAC");
828825
err = pac_notify(conn, BT_AUDIO_DIR_SINK);
829826
if (!err) {
830827
atomic_clear_bit(client->flags, FLAG_SINK_PAC_CHANGED);
831828
}
832829
}
830+
#endif /* CONFIG_BT_PAC_SNK_NOTIFIABLE */
833831

834-
if (IS_ENABLED(CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE) &&
835-
atomic_test_bit(client->flags, FLAG_SINK_AUDIO_LOCATIONS_CHANGED)) {
832+
#if defined(CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE)
833+
if (atomic_test_bit(client->flags, FLAG_SINK_AUDIO_LOCATIONS_CHANGED)) {
836834
LOG_DBG("Notifying Sink Audio Location");
837835
err = pac_notify_loc(conn, BT_AUDIO_DIR_SINK);
838836
if (!err) {
839837
atomic_clear_bit(client->flags, FLAG_SINK_AUDIO_LOCATIONS_CHANGED);
840838
}
841839
}
842-
if (IS_ENABLED(CONFIG_BT_PAC_SRC_NOTIFIABLE) &&
843-
atomic_test_bit(client->flags, FLAG_SOURCE_PAC_CHANGED)) {
840+
#endif /* CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE */
841+
842+
#if defined(CONFIG_BT_PAC_SRC_NOTIFIABLE)
843+
if (atomic_test_bit(client->flags, FLAG_SOURCE_PAC_CHANGED)) {
844844
LOG_DBG("Notifying Source PAC");
845845
err = pac_notify(conn, BT_AUDIO_DIR_SOURCE);
846846
if (!err) {
847847
atomic_clear_bit(client->flags, FLAG_SOURCE_PAC_CHANGED);
848848
}
849849
}
850-
if (IS_ENABLED(CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE) &&
851-
atomic_test_and_clear_bit(client->flags, FLAG_SOURCE_AUDIO_LOCATIONS_CHANGED)) {
850+
#endif /* CONFIG_BT_PAC_SRC_NOTIFIABLE */
851+
852+
#if defined(CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE)
853+
if (atomic_test_and_clear_bit(client->flags, FLAG_SOURCE_AUDIO_LOCATIONS_CHANGED)) {
852854
LOG_DBG("Notifying Source Audio Location");
853855
err = pac_notify_loc(conn, BT_AUDIO_DIR_SOURCE);
854856
if (!err) {
855857
atomic_clear_bit(client->flags, FLAG_SOURCE_AUDIO_LOCATIONS_CHANGED);
856858
}
857859
}
860+
#endif /* CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE */
858861

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

0 commit comments

Comments
 (0)