Skip to content

Commit 09f3c31

Browse files
lylezhu2012kartben
authored andcommitted
Bluetooth: Classic: HFP_AG: Remove unnecessary lock/unlock
For read-only access to fields, `lock/unlock` is unnecessary. Remove unnecessary `lock/unlock` protection for read-only access fields of AG. Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
1 parent 2b4de08 commit 09f3c31

File tree

1 file changed

+13
-90
lines changed

1 file changed

+13
-90
lines changed

subsys/bluetooth/host/classic/hfp_ag.c

Lines changed: 13 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,7 @@ static int hfp_ag_send_data(struct bt_hfp_ag *ag, bt_hfp_ag_tx_cb_t cb, void *us
378378

379379
LOG_DBG("AG %p sending data cb %p user_data %p", ag, cb, user_data);
380380

381-
hfp_ag_lock(ag);
382381
state = ag->state;
383-
hfp_ag_unlock(ag);
384382
if ((state == BT_HFP_DISCONNECTED) || (state == BT_HFP_DISCONNECTING)) {
385383
LOG_ERR("AG %p is not connected", ag);
386384
err = -ENOTCONN;
@@ -1382,16 +1380,12 @@ static void bt_hfp_ag_call_ringing_cb(struct bt_hfp_ag_call *call, bool in_bond)
13821380
static void hfp_ag_sco_connected(struct bt_sco_chan *chan)
13831381
{
13841382
struct bt_hfp_ag *ag = CONTAINER_OF(chan, struct bt_hfp_ag, sco_chan);
1385-
bt_hfp_call_state_t call_state;
13861383
struct bt_hfp_ag_call *call;
13871384

13881385
call = get_call_clear_flag(ag, BT_HFP_AG_CALL_OPEN_SCO);
13891386

13901387
if (call) {
1391-
hfp_ag_lock(ag);
1392-
call_state = call->call_state;
1393-
hfp_ag_unlock(ag);
1394-
if ((call_state == BT_HFP_CALL_INCOMING) ||
1388+
if ((call->call_state == BT_HFP_CALL_INCOMING) ||
13951389
atomic_test_and_clear_bit(call->flags, BT_HFP_AG_CALL_ALERTING)) {
13961390
bt_hfp_ag_set_call_state(call, BT_HFP_CALL_ALERTING);
13971391
bt_hfp_ag_call_ringing_cb(call, true);
@@ -1419,9 +1413,7 @@ static void hfp_ag_sco_disconnected(struct bt_sco_chan *chan, uint8_t reason)
14191413
return;
14201414
}
14211415

1422-
hfp_ag_lock(ag);
14231416
call_state = call->call_state;
1424-
hfp_ag_unlock(ag);
14251417
if ((call_state == BT_HFP_CALL_INCOMING) || (call_state == BT_HFP_CALL_OUTGOING)) {
14261418
bt_hfp_ag_call_reject(ag, call);
14271419
}
@@ -1457,7 +1449,6 @@ static struct bt_conn *bt_hfp_ag_create_sco(struct bt_hfp_ag *ag)
14571449
static int hfp_ag_open_sco(struct bt_hfp_ag *ag, struct bt_hfp_ag_call *call)
14581450
{
14591451
bool create_sco;
1460-
bt_hfp_call_state_t call_state;
14611452

14621453
if (atomic_test_bit(ag->flags, BT_HFP_AG_CREATING_SCO)) {
14631454
LOG_WRN("SCO connection is creating!");
@@ -1490,11 +1481,7 @@ static int hfp_ag_open_sco(struct bt_hfp_ag *ag, struct bt_hfp_ag_call *call)
14901481
LOG_DBG("SCO connection created (%p)", sco_conn);
14911482
} else {
14921483
if (call) {
1493-
hfp_ag_lock(ag);
1494-
call_state = call->call_state;
1495-
hfp_ag_unlock(ag);
1496-
1497-
if ((call_state == BT_HFP_CALL_INCOMING) ||
1484+
if ((call->call_state == BT_HFP_CALL_INCOMING) ||
14981485
atomic_test_and_clear_bit(call->flags, BT_HFP_AG_CALL_ALERTING)) {
14991486
bt_hfp_ag_set_call_state(call, BT_HFP_CALL_ALERTING);
15001487
bt_hfp_ag_call_ringing_cb(call, true);
@@ -1733,10 +1720,7 @@ static int chld_release_all(struct bt_hfp_ag *ag)
17331720
continue;
17341721
}
17351722

1736-
hfp_ag_lock(ag);
17371723
call_state = call->call_state;
1738-
hfp_ag_unlock(ag);
1739-
17401724
if ((call_state != BT_HFP_CALL_ACTIVE) ||
17411725
((call_state == BT_HFP_CALL_ACTIVE) &&
17421726
atomic_test_bit(call->flags, BT_HFP_AG_CALL_INCOMING_HELD))) {
@@ -1759,9 +1743,7 @@ static void bt_hfp_ag_accept_other_cb(struct bt_hfp_ag *ag, void *user_data)
17591743
return;
17601744
}
17611745

1762-
hfp_ag_lock(ag);
17631746
call_state = call->call_state;
1764-
hfp_ag_unlock(ag);
17651747

17661748
bt_hfp_ag_set_call_state(call, BT_HFP_CALL_ACTIVE);
17671749

@@ -1818,10 +1800,7 @@ static struct bt_hfp_ag_call *get_none_accept_calls(struct bt_hfp_ag *ag)
18181800
continue;
18191801
}
18201802

1821-
hfp_ag_lock(ag);
18221803
call_state = call->call_state;
1823-
hfp_ag_unlock(ag);
1824-
18251804
if ((call_state == BT_HFP_CALL_OUTGOING) || (call_state == BT_HFP_CALL_INCOMING) ||
18261805
(call_state == BT_HFP_CALL_ALERTING)) {
18271806
return call;
@@ -1843,10 +1822,7 @@ static struct bt_hfp_ag_call *get_none_active_calls(struct bt_hfp_ag *ag)
18431822
continue;
18441823
}
18451824

1846-
hfp_ag_lock(ag);
18471825
call_state = call->call_state;
1848-
hfp_ag_unlock(ag);
1849-
18501826
if (call_state != BT_HFP_CALL_ACTIVE) {
18511827
return call;
18521828
} else if ((call_state == BT_HFP_CALL_ACTIVE) &&
@@ -1861,7 +1837,6 @@ static struct bt_hfp_ag_call *get_none_active_calls(struct bt_hfp_ag *ag)
18611837
static int chld_deactivate_calls_and_accept_other_call(struct bt_hfp_ag *ag, bool release)
18621838
{
18631839
struct bt_hfp_ag_call *call;
1864-
bt_hfp_call_state_t call_state;
18651840
struct bt_hfp_ag_call *none_active_call;
18661841

18671842
none_active_call = get_none_accept_calls(ag);
@@ -1882,11 +1857,7 @@ static int chld_deactivate_calls_and_accept_other_call(struct bt_hfp_ag *ag, boo
18821857
continue;
18831858
}
18841859

1885-
hfp_ag_lock(ag);
1886-
call_state = call->call_state;
1887-
hfp_ag_unlock(ag);
1888-
1889-
if ((call_state == BT_HFP_CALL_ACTIVE) &&
1860+
if ((call->call_state == BT_HFP_CALL_ACTIVE) &&
18901861
!atomic_test_bit(call->flags, BT_HFP_AG_CALL_INCOMING_HELD)) {
18911862
if (release) {
18921863
ag_terminate_call(call);
@@ -1906,7 +1877,6 @@ static int chld_deactivate_calls_and_accept_other_call(struct bt_hfp_ag *ag, boo
19061877
static int chld_activate_held_call(struct bt_hfp_ag *ag)
19071878
{
19081879
struct bt_hfp_ag_call *call;
1909-
bt_hfp_call_state_t call_state;
19101880

19111881
for (size_t index = 0; index < ARRAY_SIZE(ag->calls); index++) {
19121882
call = &ag->calls[index];
@@ -1915,11 +1885,7 @@ static int chld_activate_held_call(struct bt_hfp_ag *ag)
19151885
continue;
19161886
}
19171887

1918-
hfp_ag_lock(ag);
1919-
call_state = call->call_state;
1920-
hfp_ag_unlock(ag);
1921-
1922-
if (call_state == BT_HFP_CALL_HOLD) {
1888+
if (call->call_state == BT_HFP_CALL_HOLD) {
19231889
bt_hfp_ag_set_call_state(call, BT_HFP_CALL_ACTIVE);
19241890

19251891
if (bt_ag && bt_ag->retrieve) {
@@ -1936,7 +1902,6 @@ static int chld_activate_held_call(struct bt_hfp_ag *ag)
19361902
static int chld_drop_conversation(struct bt_hfp_ag *ag)
19371903
{
19381904
struct bt_hfp_ag_call *call;
1939-
bt_hfp_call_state_t call_state;
19401905

19411906
for (size_t index = 0; index < ARRAY_SIZE(ag->calls); index++) {
19421907
call = &ag->calls[index];
@@ -1945,11 +1910,7 @@ static int chld_drop_conversation(struct bt_hfp_ag *ag)
19451910
continue;
19461911
}
19471912

1948-
hfp_ag_lock(ag);
1949-
call_state = call->call_state;
1950-
hfp_ag_unlock(ag);
1951-
1952-
if (call_state != BT_HFP_CALL_ACTIVE) {
1913+
if (call->call_state != BT_HFP_CALL_ACTIVE) {
19531914
return -ENOTSUP;
19541915
}
19551916
}
@@ -1996,10 +1957,7 @@ static int chld_release_call(struct bt_hfp_ag *ag, uint8_t call_index)
19961957
continue;
19971958
}
19981959

1999-
hfp_ag_lock(ag);
20001960
call_state = call->call_state;
2001-
hfp_ag_unlock(ag);
2002-
20031961
if ((call_state == BT_HFP_CALL_HOLD) ||
20041962
((call_state == BT_HFP_CALL_ACTIVE) &&
20051963
!atomic_test_bit(call->flags, BT_HFP_AG_CALL_INCOMING_HELD))) {
@@ -2017,7 +1975,6 @@ static int chld_release_call(struct bt_hfp_ag *ag, uint8_t call_index)
20171975
static int chld_held_other_calls(struct bt_hfp_ag *ag, uint8_t call_index)
20181976
{
20191977
struct bt_hfp_ag_call *call;
2020-
bt_hfp_call_state_t call_state;
20211978

20221979
for (size_t index = 0; index < ARRAY_SIZE(ag->calls); index++) {
20231980
call = &ag->calls[index];
@@ -2030,11 +1987,7 @@ static int chld_held_other_calls(struct bt_hfp_ag *ag, uint8_t call_index)
20301987
continue;
20311988
}
20321989

2033-
hfp_ag_lock(ag);
2034-
call_state = call->call_state;
2035-
hfp_ag_unlock(ag);
2036-
2037-
if ((call_state == BT_HFP_CALL_ACTIVE) &&
1990+
if ((call->call_state == BT_HFP_CALL_ACTIVE) &&
20381991
!atomic_test_bit(call->flags, BT_HFP_AG_CALL_INCOMING_HELD)) {
20391992
bt_hfp_ag_set_call_state(call, BT_HFP_CALL_HOLD);
20401993

@@ -2045,11 +1998,7 @@ static int chld_held_other_calls(struct bt_hfp_ag *ag, uint8_t call_index)
20451998
}
20461999

20472000
call = &ag->calls[call_index];
2048-
hfp_ag_lock(ag);
2049-
call_state = call->call_state;
2050-
hfp_ag_unlock(ag);
2051-
2052-
if (call_state == BT_HFP_CALL_HOLD) {
2001+
if (call->call_state == BT_HFP_CALL_HOLD) {
20532002
bt_hfp_ag_set_call_state(call, BT_HFP_CALL_ACTIVE);
20542003
if (bt_ag && bt_ag->retrieve) {
20552004
bt_ag->retrieve(call);
@@ -2333,10 +2282,7 @@ static int bt_hfp_ag_chup_handler(struct bt_hfp_ag *ag, struct net_buf *buf)
23332282
return 0;
23342283
}
23352284

2336-
hfp_ag_lock(ag);
23372285
call_state = call->call_state;
2338-
hfp_ag_unlock(ag);
2339-
23402286
if (call_state == BT_HFP_CALL_ALERTING) {
23412287
if (!atomic_test_bit(call->flags, BT_HFP_AG_CALL_INCOMING)) {
23422288
next_step = bt_hfp_ag_call_terminate;
@@ -2346,6 +2292,7 @@ static int bt_hfp_ag_chup_handler(struct bt_hfp_ag *ag, struct net_buf *buf)
23462292
} else if (call_state == BT_HFP_CALL_ACTIVE) {
23472293
next_step = bt_hfp_ag_unit_call_terminate;
23482294
}
2295+
23492296
if (next_step) {
23502297
err = hfp_ag_next_step(ag, next_step, call);
23512298
return err;
@@ -2361,11 +2308,7 @@ static int bt_hfp_ag_chup_handler(struct bt_hfp_ag *ag, struct net_buf *buf)
23612308
continue;
23622309
}
23632310

2364-
hfp_ag_lock(ag);
2365-
call_state = call->call_state;
2366-
hfp_ag_unlock(ag);
2367-
2368-
if (call_state == BT_HFP_CALL_ACTIVE) {
2311+
if (call->call_state == BT_HFP_CALL_ACTIVE) {
23692312
err = hfp_ag_next_step(ag, bt_hfp_ag_unit_call_terminate, call);
23702313
}
23712314
}
@@ -2730,17 +2673,12 @@ static int bt_hfp_ag_bcs_handler(struct bt_hfp_ag *ag, struct net_buf *buf)
27302673
}
27312674
err = hfp_ag_next_step(ag, bt_hfp_ag_unit_codec_conn_setup, call);
27322675
} else {
2733-
bt_hfp_call_state_t call_state;
2734-
27352676
if (codec_conn && bt_ag && bt_ag->codec_negotiate) {
27362677
bt_ag->codec_negotiate(ag, err);
27372678
}
27382679

27392680
if (call) {
2740-
hfp_ag_lock(ag);
2741-
call_state = call->call_state;
2742-
hfp_ag_unlock(ag);
2743-
if (call_state != BT_HFP_CALL_TERMINATE) {
2681+
if (call->call_state != BT_HFP_CALL_TERMINATE) {
27442682
(void)hfp_ag_next_step(ag, bt_hfp_ag_unit_call_terminate, call);
27452683
}
27462684
}
@@ -2790,7 +2728,6 @@ static void bt_hfp_ag_unit_call_outgoing(struct bt_hfp_ag *ag, void *user_data)
27902728
static void bt_hfp_ag_call_held_cb(struct bt_hfp_ag *ag, void *user_data)
27912729
{
27922730
struct bt_hfp_ag_call *call = (struct bt_hfp_ag_call *)user_data;
2793-
bt_hfp_call_state_t call_state;
27942731

27952732
for (size_t index = 0; index < ARRAY_SIZE(ag->calls); index++) {
27962733
call = &ag->calls[index];
@@ -2799,11 +2736,7 @@ static void bt_hfp_ag_call_held_cb(struct bt_hfp_ag *ag, void *user_data)
27992736
continue;
28002737
}
28012738

2802-
hfp_ag_lock(ag);
2803-
call_state = call->call_state;
2804-
hfp_ag_unlock(ag);
2805-
2806-
if ((call_state == BT_HFP_CALL_ACTIVE) &&
2739+
if ((call->call_state == BT_HFP_CALL_ACTIVE) &&
28072740
!atomic_test_bit(call->flags, BT_HFP_AG_CALL_INCOMING_HELD)) {
28082741
bt_hfp_ag_set_call_state(call, BT_HFP_CALL_HOLD);
28092742
if (bt_ag && bt_ag->held) {
@@ -3148,15 +3081,11 @@ static int bt_hfp_ag_btrh_handler(struct bt_hfp_ag *ag, struct net_buf *buf)
31483081
{
31493082
int err;
31503083
uint32_t action;
3151-
bt_hfp_call_state_t call_state;
31523084
struct bt_hfp_ag_call *call;
31533085

31543086
if (is_char(buf, '?')) {
31553087
call = get_call_with_flag(ag, BT_HFP_AG_CALL_INCOMING_HELD);
3156-
hfp_ag_lock(ag);
3157-
call_state = call->call_state;
3158-
hfp_ag_unlock(ag);
3159-
if (call && (call_state == BT_HFP_CALL_ACTIVE)) {
3088+
if (call && (call->call_state == BT_HFP_CALL_ACTIVE)) {
31603089
err = hfp_ag_send_data(ag, NULL, NULL, "\r\n+BTRH:%d\r\n",
31613090
BT_HFP_BTRH_ON_HOLD);
31623091
if (err) {
@@ -3641,9 +3570,7 @@ static void bt_hfp_ag_thread(void *p1, void *p2, void *p3)
36413570
bt_ag_tx_free(tx);
36423571

36433572
if (err < 0) {
3644-
hfp_ag_lock(ag);
36453573
state = ag->state;
3646-
hfp_ag_unlock(ag);
36473574
if ((state != BT_HFP_DISCONNECTED) && (state != BT_HFP_DISCONNECTING)) {
36483575
bt_hfp_ag_set_state(ag, BT_HFP_DISCONNECTING);
36493576
bt_rfcomm_dlc_disconnect(&ag->rfcomm_dlc);
@@ -3815,15 +3742,11 @@ static void bt_ag_deferred_work(struct k_work *work)
38153742
static void bt_ag_ringing_work_cb(struct bt_hfp_ag *ag, void *user_data)
38163743
{
38173744
int err;
3818-
bt_hfp_call_state_t call_state;
38193745
struct bt_hfp_ag_call *call = (struct bt_hfp_ag_call *)user_data;
38203746

38213747
LOG_DBG("");
38223748

3823-
hfp_ag_lock(ag);
3824-
call_state = call->call_state;
3825-
hfp_ag_unlock(ag);
3826-
if (call_state == BT_HFP_CALL_ALERTING) {
3749+
if (call->call_state == BT_HFP_CALL_ALERTING) {
38273750

38283751
if (!atomic_test_bit(call->flags, BT_HFP_AG_CALL_INCOMING)) {
38293752
return;

0 commit comments

Comments
 (0)