Skip to content

Commit 49e5a0d

Browse files
alexsvenkartben
authored andcommitted
bluetooth: tester: audio: Add NULL checks
- Add NULL checks for broadcast_source_stop - Add NULL checks for broadcast_source_release - Return -ESRCH if trying to stop ext_adv before creation Signed-off-by: Alexander Svensen <[email protected]>
1 parent 6682a10 commit 49e5a0d

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

tests/bluetooth/tester/src/audio/btp_cap.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,11 @@ static uint8_t btp_cap_broadcast_source_release(const void *cmd, uint16_t cmd_le
697697

698698
LOG_DBG("");
699699

700+
/* If no source has been created yet, there is nothing to release */
701+
if (source == NULL || source->cap_broadcast == NULL) {
702+
return BTP_STATUS_SUCCESS;
703+
}
704+
700705
err = bt_cap_initiator_broadcast_audio_delete(source->cap_broadcast);
701706
if (err != 0) {
702707
LOG_DBG("Unable to delete broadcast source: %d", err);
@@ -744,7 +749,11 @@ static uint8_t btp_cap_broadcast_adv_stop(const void *cmd, uint16_t cmd_len,
744749
LOG_DBG("");
745750

746751
err = tester_gap_padv_stop();
747-
if (err != 0) {
752+
if (err == -ESRCH) {
753+
/* Ext adv hasn't been created yet */
754+
return BTP_STATUS_SUCCESS;
755+
} else if (err != 0) {
756+
LOG_DBG("Failed to stop periodic adv, err: %d", err);
748757
return BTP_STATUS_FAILED;
749758
}
750759

@@ -786,6 +795,11 @@ static uint8_t btp_cap_broadcast_source_stop(const void *cmd, uint16_t cmd_len,
786795
struct btp_bap_broadcast_local_source *source =
787796
btp_bap_broadcast_local_source_get(cp->source_id);
788797

798+
/* If no source has been started yet, there is nothing to stop */
799+
if (source == NULL || source->cap_broadcast == NULL) {
800+
return BTP_STATUS_SUCCESS;
801+
}
802+
789803
err = bt_cap_initiator_broadcast_audio_stop(source->cap_broadcast);
790804
if (err != 0) {
791805
LOG_ERR("Failed to stop audio source: %d", err);

tests/bluetooth/tester/src/btp_gap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1548,7 +1548,8 @@ int tester_gap_padv_stop(void)
15481548
int err;
15491549

15501550
if (ext_adv == NULL) {
1551-
return -EINVAL;
1551+
/* Ext adv not yet created */
1552+
return -ESRCH;
15521553
}
15531554

15541555
/* Enable Periodic Advertising */

0 commit comments

Comments
 (0)