Skip to content

Commit e5742b2

Browse files
MarkWangChinesekartben
authored andcommitted
bluetooth: avdtp: avoid that the ret and err exist together
Keep the err in code as it is convention in Bluetooth code, remove ret, change error_code as avdtp_err_code for avdtp protocol error. Signed-off-by: Mark Wang <yichang.wang@nxp.com>
1 parent 2f1a134 commit e5742b2

File tree

1 file changed

+73
-79
lines changed
  • subsys/bluetooth/host/classic

1 file changed

+73
-79
lines changed

subsys/bluetooth/host/classic/avdtp.c

Lines changed: 73 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -425,12 +425,11 @@ static void avdtp_process_configuration_cmd(struct bt_avdtp *session, struct net
425425
uint8_t tid, bool reconfig)
426426
{
427427
int err = 0;
428-
int ret;
429428
struct bt_avdtp_sep *sep;
430429
struct net_buf *rsp_buf;
431-
uint8_t error_code = 0;
430+
uint8_t avdtp_err_code = 0;
432431

433-
sep = avdtp_get_cmd_sep(buf, &error_code);
432+
sep = avdtp_get_cmd_sep(buf, &avdtp_err_code);
434433
avdtp_sep_lock(sep);
435434

436435
if (sep == NULL) {
@@ -450,7 +449,7 @@ static void avdtp_process_configuration_cmd(struct bt_avdtp *session, struct net
450449

451450
if (!(sep->state & expected_state)) {
452451
err = -ENOTSUP;
453-
error_code = BT_AVDTP_BAD_STATE;
452+
avdtp_err_code = BT_AVDTP_BAD_STATE;
454453
} else if (buf->len >= 1U) {
455454
uint8_t int_seid;
456455

@@ -459,15 +458,15 @@ static void avdtp_process_configuration_cmd(struct bt_avdtp *session, struct net
459458

460459
if (!reconfig) {
461460
err = session->ops->set_configuration_ind(session, sep, int_seid,
462-
buf, &error_code);
461+
buf, &avdtp_err_code);
463462
} else {
464463
err = session->ops->re_configuration_ind(session, sep, int_seid,
465-
buf, &error_code);
464+
buf, &avdtp_err_code);
466465
}
467466
} else {
468467
LOG_WRN("Invalid INT SEID");
469468
err = -ENOTSUP;
470-
error_code = BT_AVDTP_BAD_LENGTH;
469+
avdtp_err_code = BT_AVDTP_BAD_LENGTH;
471470
}
472471
}
473472

@@ -480,26 +479,26 @@ static void avdtp_process_configuration_cmd(struct bt_avdtp *session, struct net
480479
}
481480

482481
if (err) {
483-
if (error_code == 0) {
484-
error_code = BT_AVDTP_BAD_ACP_SEID;
482+
if (avdtp_err_code == 0) {
483+
avdtp_err_code = BT_AVDTP_BAD_ACP_SEID;
485484
}
486485

487-
LOG_DBG("set configuration err code:%d", error_code);
486+
LOG_DBG("set configuration err code:%d", avdtp_err_code);
488487
/* Service Category: Media Codec */
489488
net_buf_add_u8(rsp_buf, BT_AVDTP_SERVICE_MEDIA_CODEC);
490489
/* Length Of Service Capability */
491490
net_buf_add_u8(rsp_buf, 0);
492491
/* ERROR CODE */
493-
net_buf_add_u8(rsp_buf, error_code);
492+
net_buf_add_u8(rsp_buf, avdtp_err_code);
494493
}
495494

496-
ret = bt_l2cap_chan_send(&session->br_chan.chan, rsp_buf);
497-
if (ret) {
495+
err = bt_l2cap_chan_send(&session->br_chan.chan, rsp_buf);
496+
if (err) {
498497
net_buf_unref(rsp_buf);
499-
LOG_ERR("Error:L2CAP send fail - result = %d", ret);
498+
LOG_ERR("Error:L2CAP send fail - result = %d", err);
500499
}
501500

502-
if (!reconfig && !err && !ret) {
501+
if (!reconfig && !err && !avdtp_err_code) {
503502
bt_avdtp_set_state(sep, AVDTP_CONFIGURED);
504503
}
505504

@@ -566,22 +565,21 @@ static void avdtp_re_configure_rsp(struct bt_avdtp *session, struct net_buf *buf
566565
static void avdtp_open_cmd(struct bt_avdtp *session, struct net_buf *buf, uint8_t tid)
567566
{
568567
int err = 0;
569-
int ret;
570568
struct bt_avdtp_sep *sep;
571569
struct net_buf *rsp_buf;
572-
uint8_t error_code = 0;
570+
uint8_t avdtp_err_code = 0;
573571

574-
sep = avdtp_get_cmd_sep(buf, &error_code);
572+
sep = avdtp_get_cmd_sep(buf, &avdtp_err_code);
575573
avdtp_sep_lock(sep);
576574

577575
if ((sep == NULL) || (session->ops->open_ind == NULL)) {
578576
err = -ENOTSUP;
579577
} else {
580578
if (sep->state != AVDTP_CONFIGURED) {
581579
err = -ENOTSUP;
582-
error_code = BT_AVDTP_BAD_STATE;
580+
avdtp_err_code = BT_AVDTP_BAD_STATE;
583581
} else {
584-
err = session->ops->open_ind(session, sep, &error_code);
582+
err = session->ops->open_ind(session, sep, &avdtp_err_code);
585583
}
586584
}
587585

@@ -593,23 +591,23 @@ static void avdtp_open_cmd(struct bt_avdtp *session, struct net_buf *buf, uint8_
593591
}
594592

595593
if (err) {
596-
if (error_code == 0) {
597-
error_code = BT_AVDTP_BAD_ACP_SEID;
594+
if (avdtp_err_code == 0) {
595+
avdtp_err_code = BT_AVDTP_BAD_ACP_SEID;
598596
}
599597

600-
LOG_DBG("open_ind err code:%d", error_code);
601-
net_buf_add_u8(rsp_buf, error_code);
598+
LOG_DBG("open_ind err code:%d", avdtp_err_code);
599+
net_buf_add_u8(rsp_buf, avdtp_err_code);
602600
} else {
603601
session->current_sep = sep;
604602
}
605603

606-
ret = bt_l2cap_chan_send(&session->br_chan.chan, rsp_buf);
607-
if (ret) {
604+
err = bt_l2cap_chan_send(&session->br_chan.chan, rsp_buf);
605+
if (err) {
608606
net_buf_unref(rsp_buf);
609-
LOG_ERR("Error:L2CAP send fail - result = %d", ret);
607+
LOG_ERR("Error:L2CAP send fail - result = %d", err);
610608
}
611609

612-
if (!err && !ret) {
610+
if (!err && !avdtp_err_code) {
613611
bt_avdtp_set_state(sep, AVDTP_OPENING);
614612
}
615613

@@ -663,22 +661,21 @@ static void avdtp_handle_reject(struct net_buf *buf, struct bt_avdtp_req *req)
663661
static void avdtp_start_cmd(struct bt_avdtp *session, struct net_buf *buf, uint8_t tid)
664662
{
665663
int err = 0;
666-
int ret;
667664
struct bt_avdtp_sep *sep;
668665
struct net_buf *rsp_buf;
669-
uint8_t error_code = 0;
666+
uint8_t avdtp_err_code = 0;
670667

671-
sep = avdtp_get_cmd_sep(buf, &error_code);
668+
sep = avdtp_get_cmd_sep(buf, &avdtp_err_code);
672669
avdtp_sep_lock(sep);
673670

674671
if ((sep == NULL) || (session->ops->start_ind == NULL)) {
675672
err = -ENOTSUP;
676673
} else {
677674
if (sep->state != AVDTP_OPEN) {
678675
err = -ENOTSUP;
679-
error_code = BT_AVDTP_BAD_STATE;
676+
avdtp_err_code = BT_AVDTP_BAD_STATE;
680677
} else {
681-
err = session->ops->start_ind(session, sep, &error_code);
678+
err = session->ops->start_ind(session, sep, &avdtp_err_code);
682679
}
683680
}
684681

@@ -690,21 +687,21 @@ static void avdtp_start_cmd(struct bt_avdtp *session, struct net_buf *buf, uint8
690687
}
691688

692689
if (err) {
693-
if (error_code == 0) {
694-
error_code = BT_AVDTP_BAD_ACP_SEID;
690+
if (avdtp_err_code == 0) {
691+
avdtp_err_code = BT_AVDTP_BAD_ACP_SEID;
695692
}
696693

697-
LOG_DBG("start err code:%d", error_code);
698-
net_buf_add_u8(rsp_buf, error_code);
694+
LOG_DBG("start err code:%d", avdtp_err_code);
695+
net_buf_add_u8(rsp_buf, avdtp_err_code);
699696
}
700697

701-
ret = bt_l2cap_chan_send(&session->br_chan.chan, rsp_buf);
702-
if (ret) {
698+
err = bt_l2cap_chan_send(&session->br_chan.chan, rsp_buf);
699+
if (err) {
703700
net_buf_unref(rsp_buf);
704-
LOG_ERR("Error:L2CAP send fail - result = %d", ret);
701+
LOG_ERR("Error:L2CAP send fail - result = %d", err);
705702
}
706703

707-
if (!err && !ret) {
704+
if (!err && !avdtp_err_code) {
708705
bt_avdtp_set_state(sep, AVDTP_STREAMING);
709706
}
710707

@@ -741,22 +738,21 @@ static void avdtp_start_rsp(struct bt_avdtp *session, struct net_buf *buf, uint8
741738
static void avdtp_close_cmd(struct bt_avdtp *session, struct net_buf *buf, uint8_t tid)
742739
{
743740
int err = 0;
744-
int ret;
745741
struct bt_avdtp_sep *sep;
746742
struct net_buf *rsp_buf;
747-
uint8_t error_code = 0;
743+
uint8_t avdtp_err_code = 0;
748744

749-
sep = avdtp_get_cmd_sep(buf, &error_code);
745+
sep = avdtp_get_cmd_sep(buf, &avdtp_err_code);
750746
avdtp_sep_lock(sep);
751747

752748
if ((sep == NULL) || (session->ops->close_ind == NULL)) {
753749
err = -ENOTSUP;
754750
} else {
755751
if (!(sep->state & (AVDTP_OPEN | AVDTP_STREAMING))) {
756752
err = -ENOTSUP;
757-
error_code = BT_AVDTP_BAD_STATE;
753+
avdtp_err_code = BT_AVDTP_BAD_STATE;
758754
} else {
759-
err = session->ops->close_ind(session, sep, &error_code);
755+
err = session->ops->close_ind(session, sep, &avdtp_err_code);
760756
}
761757
}
762758

@@ -768,23 +764,23 @@ static void avdtp_close_cmd(struct bt_avdtp *session, struct net_buf *buf, uint8
768764
}
769765

770766
if (err) {
771-
if (error_code == 0) {
772-
error_code = BT_AVDTP_BAD_ACP_SEID;
767+
if (avdtp_err_code == 0) {
768+
avdtp_err_code = BT_AVDTP_BAD_ACP_SEID;
773769
}
774770

775-
LOG_DBG("close err code:%d", error_code);
776-
net_buf_add_u8(rsp_buf, error_code);
771+
LOG_DBG("close err code:%d", avdtp_err_code);
772+
net_buf_add_u8(rsp_buf, avdtp_err_code);
777773
} else {
778774
bt_avdtp_set_state(sep, AVDTP_CLOSING);
779775
}
780776

781-
ret = bt_l2cap_chan_send(&session->br_chan.chan, rsp_buf);
782-
if (ret) {
777+
err = bt_l2cap_chan_send(&session->br_chan.chan, rsp_buf);
778+
if (err) {
783779
net_buf_unref(rsp_buf);
784-
LOG_ERR("Error:L2CAP send fail - result = %d", ret);
780+
LOG_ERR("Error:L2CAP send fail - result = %d", err);
785781
}
786782

787-
if (!err && !ret) {
783+
if (!err && !avdtp_err_code) {
788784
bt_avdtp_set_state(sep, AVDTP_IDLE);
789785
}
790786

@@ -820,22 +816,21 @@ static void avdtp_close_rsp(struct bt_avdtp *session, struct net_buf *buf, uint8
820816
static void avdtp_suspend_cmd(struct bt_avdtp *session, struct net_buf *buf, uint8_t tid)
821817
{
822818
int err = 0;
823-
int ret;
824819
struct bt_avdtp_sep *sep;
825820
struct net_buf *rsp_buf;
826-
uint8_t error_code = 0;
821+
uint8_t avdtp_err_code = 0;
827822

828-
sep = avdtp_get_cmd_sep(buf, &error_code);
823+
sep = avdtp_get_cmd_sep(buf, &avdtp_err_code);
829824
avdtp_sep_lock(sep);
830825

831826
if ((sep == NULL) || (session->ops->suspend_ind == NULL)) {
832827
err = -ENOTSUP;
833828
} else {
834829
if (sep->state != AVDTP_STREAMING) {
835830
err = -ENOTSUP;
836-
error_code = BT_AVDTP_BAD_STATE;
831+
avdtp_err_code = BT_AVDTP_BAD_STATE;
837832
} else {
838-
err = session->ops->suspend_ind(session, sep, &error_code);
833+
err = session->ops->suspend_ind(session, sep, &avdtp_err_code);
839834
}
840835
}
841836

@@ -847,21 +842,21 @@ static void avdtp_suspend_cmd(struct bt_avdtp *session, struct net_buf *buf, uin
847842
}
848843

849844
if (err) {
850-
if (error_code == 0) {
851-
error_code = BT_AVDTP_BAD_ACP_SEID;
845+
if (avdtp_err_code == 0) {
846+
avdtp_err_code = BT_AVDTP_BAD_ACP_SEID;
852847
}
853848

854-
LOG_DBG("suspend err code:%d", error_code);
855-
net_buf_add_u8(rsp_buf, error_code);
849+
LOG_DBG("suspend err code:%d", avdtp_err_code);
850+
net_buf_add_u8(rsp_buf, avdtp_err_code);
856851
}
857852

858-
ret = bt_l2cap_chan_send(&session->br_chan.chan, rsp_buf);
859-
if (ret) {
853+
err = bt_l2cap_chan_send(&session->br_chan.chan, rsp_buf);
854+
if (err) {
860855
net_buf_unref(rsp_buf);
861-
LOG_ERR("Error:L2CAP send fail - result = %d", ret);
856+
LOG_ERR("Error:L2CAP send fail - result = %d", err);
862857
}
863858

864-
if (!err && !ret) {
859+
if (!err && !avdtp_err_code) {
865860
bt_avdtp_set_state(sep, AVDTP_OPEN);
866861
}
867862

@@ -898,19 +893,18 @@ static void avdtp_suspend_rsp(struct bt_avdtp *session, struct net_buf *buf, uin
898893
static void avdtp_abort_cmd(struct bt_avdtp *session, struct net_buf *buf, uint8_t tid)
899894
{
900895
int err = 0;
901-
int ret;
902896
struct bt_avdtp_sep *sep;
903897
struct net_buf *rsp_buf;
904-
uint8_t error_code = 0;
898+
uint8_t avdtp_err_code = 0;
905899

906-
sep = avdtp_get_cmd_sep(buf, &error_code);
900+
sep = avdtp_get_cmd_sep(buf, &avdtp_err_code);
907901
avdtp_sep_lock(sep);
908902

909903
if ((sep == NULL) || (session->ops->abort_ind == NULL)) {
910904
err = -ENOTSUP;
911905
} else {
912906
/* all current sep state is OK for abort operation */
913-
err = session->ops->abort_ind(session, sep, &error_code);
907+
err = session->ops->abort_ind(session, sep, &avdtp_err_code);
914908
}
915909

916910
rsp_buf = avdtp_create_reply_pdu(err ? BT_AVDTP_REJECT : BT_AVDTP_ACCEPT,
@@ -921,21 +915,21 @@ static void avdtp_abort_cmd(struct bt_avdtp *session, struct net_buf *buf, uint8
921915
}
922916

923917
if (err) {
924-
if (error_code == 0) {
925-
error_code = BT_AVDTP_BAD_ACP_SEID;
918+
if (avdtp_err_code == 0) {
919+
avdtp_err_code = BT_AVDTP_BAD_ACP_SEID;
926920
}
927921

928-
LOG_DBG("abort err code:%d", error_code);
929-
net_buf_add_u8(rsp_buf, error_code);
922+
LOG_DBG("abort err code:%d", avdtp_err_code);
923+
net_buf_add_u8(rsp_buf, avdtp_err_code);
930924
}
931925

932-
ret = bt_l2cap_chan_send(&session->br_chan.chan, rsp_buf);
933-
if (ret) {
926+
err = bt_l2cap_chan_send(&session->br_chan.chan, rsp_buf);
927+
if (err) {
934928
net_buf_unref(rsp_buf);
935-
LOG_ERR("Error:L2CAP send fail - result = %d", ret);
929+
LOG_ERR("Error:L2CAP send fail - result = %d", err);
936930
}
937931

938-
if (!err && !ret) {
932+
if (!err && !avdtp_err_code) {
939933
if ((sep->state & (AVDTP_OPEN | AVDTP_STREAMING)) &&
940934
(sep->chan.state == BT_L2CAP_CONNECTED)) {
941935
bt_avdtp_set_state(sep, AVDTP_ABORTING);

0 commit comments

Comments
 (0)