Skip to content

Commit

Permalink
bluetooth: tester: audio: Add NULL checks
Browse files Browse the repository at this point in the history
- 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]>
  • Loading branch information
alexsven committed Dec 4, 2024
1 parent 8a190e8 commit 3712541
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
16 changes: 15 additions & 1 deletion tests/bluetooth/tester/src/audio/btp_cap.c
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,11 @@ static uint8_t btp_cap_broadcast_source_release(const void *cmd, uint16_t cmd_le

LOG_DBG("");

/* If no source has been created yet, there is nothing to release */
if (source == NULL || source->cap_broadcast == NULL) {
return BTP_STATUS_SUCCESS;
}

err = bt_cap_initiator_broadcast_audio_delete(source->cap_broadcast);
if (err != 0) {
LOG_DBG("Unable to delete broadcast source: %d", err);
Expand Down Expand Up @@ -744,7 +749,11 @@ static uint8_t btp_cap_broadcast_adv_stop(const void *cmd, uint16_t cmd_len,
LOG_DBG("");

err = tester_gap_padv_stop();
if (err != 0) {
if (err == -ESRCH) {
/* Ext adv hasn't been created yet */
return BTP_STATUS_SUCCESS;
} else if (err != 0) {
LOG_DBG("Failed to stop periodic adv, err: %d", err);
return BTP_STATUS_FAILED;
}

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

/* If no source has been started yet, there is nothing to stop */
if (source == NULL || source->cap_broadcast == NULL) {
return BTP_STATUS_SUCCESS;
}

err = bt_cap_initiator_broadcast_audio_stop(source->cap_broadcast);
if (err != 0) {
LOG_ERR("Failed to stop audio source: %d", err);
Expand Down
3 changes: 2 additions & 1 deletion tests/bluetooth/tester/src/btp_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1548,7 +1548,8 @@ int tester_gap_padv_stop(void)
int err;

if (ext_adv == NULL) {
return -EINVAL;
/* Ext adv not yet created */
return -ESRCH;
}

/* Enable Periodic Advertising */
Expand Down

0 comments on commit 3712541

Please sign in to comment.