Skip to content

Commit 9cda31a

Browse files
lylezhu2012kartben
authored andcommitted
Bluetooth: HFP_AG: Remove unnecessary lock for feature read access
The lock/unlock for AG/HF feature read access is unnecessary. For AG feature, it only be changed when creating new AG object. For HF feature, it only be changed when exchanging feature in SLC establishment. Remove the hfp_ag_lock/hfp_ag_unlock for AG/HF feature read access. Signed-off-by: Lyle Zhu <[email protected]>
1 parent d37f250 commit 9cda31a

File tree

1 file changed

+3
-51
lines changed

1 file changed

+3
-51
lines changed

subsys/bluetooth/host/classic/hfp_ag.c

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -275,14 +275,12 @@ static struct bt_hfp_ag_call *get_new_call(struct bt_hfp_ag *ag, const char *num
275275
call = &ag->calls[index];
276276

277277
if (!atomic_test_and_set_bit(call->flags, BT_HFP_AG_CALL_IN_USING)) {
278-
hfp_ag_lock(ag);
279278
/* Copy number to ag->number including null-character */
280279
strcpy(call->number, number);
281280
call->type = type;
282281
call->ag = ag;
283282
k_work_init_delayable(&call->deferred_work, bt_ag_deferred_work);
284283
k_work_init_delayable(&call->ringing_work, bt_ag_ringing_work);
285-
hfp_ag_unlock(ag);
286284
return call;
287285
}
288286
}
@@ -940,9 +938,7 @@ static int bt_hfp_ag_brsf_handler(struct bt_hfp_ag *ag, struct net_buf *buf)
940938
return -ENOTSUP;
941939
}
942940

943-
hfp_ag_lock(ag);
944941
ag->hf_features = hf_features;
945-
hfp_ag_unlock(ag);
946942

947943
return hfp_ag_send_data(ag, NULL, NULL, "\r\n+BRSF:%d\r\n", ag->ag_features);
948944
}
@@ -957,13 +953,10 @@ static int bt_hfp_ag_bac_handler(struct bt_hfp_ag *ag, struct net_buf *buf)
957953
return -ENOTSUP;
958954
}
959955

960-
hfp_ag_lock(ag);
961956
if (!(ag->hf_features & BT_HFP_HF_FEATURE_CODEC_NEG) ||
962957
!(ag->ag_features & BT_HFP_AG_FEATURE_CODEC_NEG)) {
963-
hfp_ag_unlock(ag);
964958
return -ENOEXEC;
965959
}
966-
hfp_ag_unlock(ag);
967960

968961
while (buf->len > 0) {
969962
err = get_number(buf, &codec);
@@ -1064,9 +1057,7 @@ static void bt_hfp_ag_set_in_band_ring(struct bt_hfp_ag *ag, void *user_data)
10641057
{
10651058
bool is_inband_ringtone;
10661059

1067-
hfp_ag_lock(ag);
10681060
is_inband_ringtone = (ag->ag_features & BT_HFP_AG_FEATURE_INBAND_RINGTONE) ? true : false;
1069-
hfp_ag_unlock(ag);
10701061

10711062
if (is_inband_ringtone && !atomic_test_bit(ag->flags, BT_HFP_AG_INBAND_RING)) {
10721063
int err = hfp_ag_send_data(ag, NULL, NULL, "\r\n+BSIR:1\r\n");
@@ -1522,13 +1513,10 @@ static int bt_hfp_ag_chld_handler(struct bt_hfp_ag *ag, struct net_buf *buf)
15221513
int err;
15231514
char *response;
15241515

1525-
hfp_ag_lock(ag);
15261516
if (!((ag->ag_features & BT_HFP_AG_FEATURE_3WAY_CALL) &&
15271517
(ag->hf_features & BT_HFP_HF_FEATURE_3WAY_CALL))) {
1528-
hfp_ag_unlock(ag);
15291518
return -ENOEXEC;
15301519
}
1531-
hfp_ag_unlock(ag);
15321520

15331521
if (!is_char(buf, '=')) {
15341522
return -ENOTSUP;
@@ -1581,23 +1569,18 @@ static int bt_hfp_ag_bind_handler(struct bt_hfp_ag *ag, struct net_buf *buf)
15811569
char *data;
15821570
uint32_t len;
15831571

1584-
hfp_ag_lock(ag);
15851572
if (!((ag->ag_features & BT_HFP_AG_FEATURE_HF_IND) &&
15861573
(ag->hf_features & BT_HFP_HF_FEATURE_HF_IND))) {
1587-
hfp_ag_unlock(ag);
15881574
return -ENOEXEC;
15891575
}
1590-
hfp_ag_unlock(ag);
15911576

15921577
if (is_char(buf, '?')) {
15931578
if (!is_char(buf, '\r')) {
15941579
return -ENOTSUP;
15951580
}
15961581

1597-
hfp_ag_lock(ag);
15981582
hf_indicators = ag->hf_indicators;
15991583
supported_indicators = ag->hf_indicators_of_ag & ag->hf_indicators_of_hf;
1600-
hfp_ag_unlock(ag);
16011584
len = MIN(NUM_BITS(sizeof(supported_indicators)), HFP_HF_IND_MAX);
16021585
for (int i = 1; i < len; i++) {
16031586
bool enabled;
@@ -1634,9 +1617,7 @@ static int bt_hfp_ag_bind_handler(struct bt_hfp_ag *ag, struct net_buf *buf)
16341617
data = &ag->buffer[0];
16351618
*data = '(';
16361619
data++;
1637-
hfp_ag_lock(ag);
16381620
hf_indicators = ag->hf_indicators_of_ag;
1639-
hfp_ag_unlock(ag);
16401621
len = MIN(NUM_BITS(sizeof(hf_indicators)), HFP_HF_IND_MAX);
16411622
for (int i = 1; (i < len) && (hf_indicators != 0); i++) {
16421623
if (BIT(i) & hf_indicators) {
@@ -1677,9 +1658,7 @@ static int bt_hfp_ag_bind_handler(struct bt_hfp_ag *ag, struct net_buf *buf)
16771658
}
16781659
}
16791660

1680-
hfp_ag_lock(ag);
16811661
ag->hf_indicators_of_hf = hf_indicators;
1682-
hfp_ag_unlock(ag);
16831662

16841663
return 0;
16851664
}
@@ -2904,13 +2883,10 @@ static int bt_hfp_ag_ccwa_handler(struct bt_hfp_ag *ag, struct net_buf *buf)
29042883
int err;
29052884
uint32_t value;
29062885

2907-
hfp_ag_lock(ag);
29082886
if (!((ag->ag_features & BT_HFP_AG_FEATURE_3WAY_CALL) &&
29092887
(ag->hf_features & BT_HFP_HF_FEATURE_3WAY_CALL))) {
2910-
hfp_ag_unlock(ag);
29112888
return -ENOEXEC;
29122889
}
2913-
hfp_ag_unlock(ag);
29142890

29152891
if (!is_char(buf, '=')) {
29162892
return -ENOTSUP;
@@ -2937,10 +2913,8 @@ static void bt_hfp_ag_vr_activate(struct bt_hfp_ag *ag, void *user_data)
29372913
{
29382914
bool feature;
29392915

2940-
hfp_ag_lock(ag);
29412916
feature = (ag->ag_features & BT_HFP_AG_FEATURE_ENH_VOICE_RECG) &&
29422917
(ag->hf_features & BT_HFP_HF_FEATURE_ENH_VOICE_RECG);
2943-
hfp_ag_unlock(ag);
29442918

29452919
#if defined(CONFIG_BT_HFP_AG_VOICE_RECG)
29462920
if (bt_ag && bt_ag->voice_recognition) {
@@ -2986,13 +2960,10 @@ static int bt_hfp_ag_bvra_handler(struct bt_hfp_ag *ag, struct net_buf *buf)
29862960
int err;
29872961
uint32_t value;
29882962

2989-
hfp_ag_lock(ag);
29902963
if (!((ag->ag_features & BT_HFP_AG_FEATURE_VOICE_RECG) &&
29912964
(ag->hf_features & BT_HFP_HF_FEATURE_VOICE_RECG))) {
2992-
hfp_ag_unlock(ag);
29932965
return -ENOEXEC;
29942966
}
2995-
hfp_ag_unlock(ag);
29962967

29972968
if (!is_char(buf, '=')) {
29982969
return -ENOTSUP;
@@ -3024,14 +2995,11 @@ static int bt_hfp_ag_bvra_handler(struct bt_hfp_ag *ag, struct net_buf *buf)
30242995
err = hfp_ag_next_step(ag, bt_hfp_ag_vr_activate, NULL);
30252996
break;
30262997
case BT_HFP_BVRA_READY_TO_ACCEPT:
3027-
hfp_ag_lock(ag);
30282998
if (!((ag->ag_features & BT_HFP_AG_FEATURE_ENH_VOICE_RECG) &&
30292999
(ag->hf_features & BT_HFP_HF_FEATURE_ENH_VOICE_RECG))) {
3030-
hfp_ag_unlock(ag);
30313000
LOG_WRN("Enhance voice recognition is not supported");
30323001
return -ENOEXEC;
30333002
}
3034-
hfp_ag_unlock(ag);
30353003
if (!atomic_test_bit(ag->flags, BT_HFP_AG_VRE_ACTIVATE)) {
30363004
LOG_WRN("Voice recognition is not activated");
30373005
return -ENOTSUP;
@@ -3053,12 +3021,9 @@ static int bt_hfp_ag_binp_handler(struct bt_hfp_ag *ag, struct net_buf *buf)
30533021
char *number = NULL;
30543022
#endif /* CONFIG_BT_HFP_AG_VOICE_TAG */
30553023

3056-
hfp_ag_lock(ag);
30573024
if (!(ag->ag_features & BT_HFP_AG_FEATURE_VOICE_TAG)) {
3058-
hfp_ag_unlock(ag);
30593025
return -ENOEXEC;
30603026
}
3061-
hfp_ag_unlock(ag);
30623027

30633028
if (!is_char(buf, '=')) {
30643029
return -ENOTSUP;
@@ -3966,7 +3931,6 @@ int bt_hfp_ag_reject(struct bt_hfp_ag_call *call)
39663931
int err = 0;
39673932
struct bt_hfp_ag *ag;
39683933
bt_hfp_call_state_t call_state;
3969-
uint32_t ag_features;
39703934

39713935
LOG_DBG("");
39723936

@@ -3987,14 +3951,13 @@ int bt_hfp_ag_reject(struct bt_hfp_ag_call *call)
39873951
}
39883952

39893953
call_state = call->call_state;
3990-
ag_features = ag->ag_features;
39913954
hfp_ag_unlock(ag);
39923955

39933956
if (!atomic_test_bit(call->flags, BT_HFP_AG_CALL_INCOMING)) {
39943957
return -EINVAL;
39953958
}
39963959

3997-
if (!(ag_features & BT_HFP_AG_FEATURE_REJECT_CALL)) {
3960+
if (!(ag->ag_features & BT_HFP_AG_FEATURE_REJECT_CALL)) {
39983961
LOG_ERR("AG has not ability to reject call");
39993962
return -ENOTSUP;
40003963
}
@@ -4599,13 +4562,12 @@ int bt_hfp_ag_vgm(struct bt_hfp_ag *ag, uint8_t vgm)
45994562
hfp_ag_unlock(ag);
46004563
return -ENOTCONN;
46014564
}
4565+
hfp_ag_unlock(ag);
46024566

46034567
if (!(ag->hf_features & BT_HFP_HF_FEATURE_VOLUME)) {
4604-
hfp_ag_unlock(ag);
46054568
LOG_ERR("Remote Audio Volume Control is unsupported");
46064569
return -ENOTSUP;
46074570
}
4608-
hfp_ag_unlock(ag);
46094571

46104572
err = hfp_ag_send_data(ag, NULL, NULL, "\r\n+VGM=%d\r\n", vgm);
46114573
if (err) {
@@ -4635,13 +4597,12 @@ int bt_hfp_ag_vgs(struct bt_hfp_ag *ag, uint8_t vgs)
46354597
hfp_ag_unlock(ag);
46364598
return -ENOTCONN;
46374599
}
4600+
hfp_ag_unlock(ag);
46384601

46394602
if (!(ag->hf_features & BT_HFP_HF_FEATURE_VOLUME)) {
4640-
hfp_ag_unlock(ag);
46414603
LOG_ERR("Remote Audio Volume Control is unsupported");
46424604
return -ENOTSUP;
46434605
}
4644-
hfp_ag_unlock(ag);
46454606

46464607
err = hfp_ag_send_data(ag, NULL, NULL, "\r\n+VGS=%d\r\n", vgs);
46474608
if (err) {
@@ -4706,11 +4667,8 @@ int bt_hfp_ag_voice_recognition(struct bt_hfp_ag *ag, bool activate)
47064667
return -ENOTSUP;
47074668
}
47084669

4709-
hfp_ag_lock(ag);
47104670
feature = (ag->ag_features & BT_HFP_AG_FEATURE_ENH_VOICE_RECG) &&
47114671
(ag->hf_features & BT_HFP_HF_FEATURE_ENH_VOICE_RECG);
4712-
hfp_ag_unlock(ag);
4713-
47144672
if (!feature) {
47154673
bvra = "";
47164674
} else {
@@ -4755,10 +4713,8 @@ int bt_hfp_ag_vre_state(struct bt_hfp_ag *ag, uint8_t state)
47554713
return -EINVAL;
47564714
}
47574715

4758-
hfp_ag_lock(ag);
47594716
feature = (ag->ag_features & BT_HFP_AG_FEATURE_ENH_VOICE_RECG) &&
47604717
(ag->hf_features & BT_HFP_HF_FEATURE_ENH_VOICE_RECG);
4761-
hfp_ag_unlock(ag);
47624718
if (!feature) {
47634719
return -ENOTSUP;
47644720
}
@@ -4806,18 +4762,14 @@ int bt_hfp_ag_vre_textual_representation(struct bt_hfp_ag *ag, uint8_t state, co
48064762
return -EINVAL;
48074763
}
48084764

4809-
hfp_ag_lock(ag);
48104765
feature = (ag->ag_features & BT_HFP_AG_FEATURE_ENH_VOICE_RECG) &&
48114766
(ag->hf_features & BT_HFP_HF_FEATURE_ENH_VOICE_RECG);
4812-
hfp_ag_unlock(ag);
48134767
if (!feature) {
48144768
return -ENOTSUP;
48154769
}
48164770

4817-
hfp_ag_lock(ag);
48184771
feature = (ag->ag_features & BT_HFP_AG_FEATURE_VOICE_RECG_TEXT) &&
48194772
(ag->hf_features & BT_HFP_HF_FEATURE_VOICE_RECG_TEXT);
4820-
hfp_ag_unlock(ag);
48214773
if (!feature) {
48224774
return -ENOTSUP;
48234775
}

0 commit comments

Comments
 (0)