Skip to content

Commit 2969554

Browse files
pvVudentz
authored andcommitted
Bluetooth: hci_sync: hci_cmd_sync_queue_once() return -EEXIST if exists
hci_cmd_sync_queue_once() needs to indicate whether a queue item was added, so caller can know if callbacks are called, so it can avoid leaking resources. Change the function to return -EEXIST if queue item already exists. Modify all callsites to handle that. Signed-off-by: Pauli Virtanen <pav@iki.fi> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
1 parent 2b2bf47 commit 2969554

1 file changed

Lines changed: 36 additions & 17 deletions

File tree

net/bluetooth/hci_sync.c

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ int hci_cmd_sync_queue_once(struct hci_dev *hdev, hci_cmd_sync_work_func_t func,
780780
void *data, hci_cmd_sync_work_destroy_t destroy)
781781
{
782782
if (hci_cmd_sync_lookup_entry(hdev, func, data, destroy))
783-
return 0;
783+
return -EEXIST;
784784

785785
return hci_cmd_sync_queue(hdev, func, data, destroy);
786786
}
@@ -3262,6 +3262,8 @@ static int update_passive_scan_sync(struct hci_dev *hdev, void *data)
32623262

32633263
int hci_update_passive_scan(struct hci_dev *hdev)
32643264
{
3265+
int err;
3266+
32653267
/* Only queue if it would have any effect */
32663268
if (!test_bit(HCI_UP, &hdev->flags) ||
32673269
test_bit(HCI_INIT, &hdev->flags) ||
@@ -3271,8 +3273,9 @@ int hci_update_passive_scan(struct hci_dev *hdev)
32713273
hci_dev_test_flag(hdev, HCI_UNREGISTER))
32723274
return 0;
32733275

3274-
return hci_cmd_sync_queue_once(hdev, update_passive_scan_sync, NULL,
3275-
NULL);
3276+
err = hci_cmd_sync_queue_once(hdev, update_passive_scan_sync, NULL,
3277+
NULL);
3278+
return (err == -EEXIST) ? 0 : err;
32763279
}
32773280

32783281
int hci_write_sc_support_sync(struct hci_dev *hdev, u8 val)
@@ -6965,8 +6968,11 @@ static int hci_acl_create_conn_sync(struct hci_dev *hdev, void *data)
69656968

69666969
int hci_connect_acl_sync(struct hci_dev *hdev, struct hci_conn *conn)
69676970
{
6968-
return hci_cmd_sync_queue_once(hdev, hci_acl_create_conn_sync, conn,
6969-
NULL);
6971+
int err;
6972+
6973+
err = hci_cmd_sync_queue_once(hdev, hci_acl_create_conn_sync, conn,
6974+
NULL);
6975+
return (err == -EEXIST) ? 0 : err;
69706976
}
69716977

69726978
static void create_le_conn_complete(struct hci_dev *hdev, void *data, int err)
@@ -7002,8 +7008,11 @@ static void create_le_conn_complete(struct hci_dev *hdev, void *data, int err)
70027008

70037009
int hci_connect_le_sync(struct hci_dev *hdev, struct hci_conn *conn)
70047010
{
7005-
return hci_cmd_sync_queue_once(hdev, hci_le_create_conn_sync, conn,
7006-
create_le_conn_complete);
7011+
int err;
7012+
7013+
err = hci_cmd_sync_queue_once(hdev, hci_le_create_conn_sync, conn,
7014+
create_le_conn_complete);
7015+
return (err == -EEXIST) ? 0 : err;
70077016
}
70087017

70097018
int hci_cancel_connect_sync(struct hci_dev *hdev, struct hci_conn *conn)
@@ -7210,8 +7219,11 @@ static int hci_le_pa_create_sync(struct hci_dev *hdev, void *data)
72107219

72117220
int hci_connect_pa_sync(struct hci_dev *hdev, struct hci_conn *conn)
72127221
{
7213-
return hci_cmd_sync_queue_once(hdev, hci_le_pa_create_sync, conn,
7214-
create_pa_complete);
7222+
int err;
7223+
7224+
err = hci_cmd_sync_queue_once(hdev, hci_le_pa_create_sync, conn,
7225+
create_pa_complete);
7226+
return (err == -EEXIST) ? 0 : err;
72157227
}
72167228

72177229
static void create_big_complete(struct hci_dev *hdev, void *data, int err)
@@ -7273,8 +7285,11 @@ static int hci_le_big_create_sync(struct hci_dev *hdev, void *data)
72737285

72747286
int hci_connect_big_sync(struct hci_dev *hdev, struct hci_conn *conn)
72757287
{
7276-
return hci_cmd_sync_queue_once(hdev, hci_le_big_create_sync, conn,
7277-
create_big_complete);
7288+
int err;
7289+
7290+
err = hci_cmd_sync_queue_once(hdev, hci_le_big_create_sync, conn,
7291+
create_big_complete);
7292+
return (err == -EEXIST) ? 0 : err;
72787293
}
72797294

72807295
struct past_data {
@@ -7366,7 +7381,7 @@ int hci_past_sync(struct hci_conn *conn, struct hci_conn *le)
73667381
if (err)
73677382
kfree(data);
73687383

7369-
return err;
7384+
return (err == -EEXIST) ? 0 : err;
73707385
}
73717386

73727387
static void le_read_features_complete(struct hci_dev *hdev, void *data, int err)
@@ -7453,7 +7468,7 @@ int hci_le_read_remote_features(struct hci_conn *conn)
74537468
else
74547469
err = -EOPNOTSUPP;
74557470

7456-
return err;
7471+
return (err == -EEXIST) ? 0 : err;
74577472
}
74587473

74597474
static void pkt_type_changed(struct hci_dev *hdev, void *data, int err)
@@ -7479,6 +7494,7 @@ int hci_acl_change_pkt_type(struct hci_conn *conn, u16 pkt_type)
74797494
{
74807495
struct hci_dev *hdev = conn->hdev;
74817496
struct hci_cp_change_conn_ptype *cp;
7497+
int err;
74827498

74837499
cp = kmalloc_obj(*cp);
74847500
if (!cp)
@@ -7487,8 +7503,9 @@ int hci_acl_change_pkt_type(struct hci_conn *conn, u16 pkt_type)
74877503
cp->handle = cpu_to_le16(conn->handle);
74887504
cp->pkt_type = cpu_to_le16(pkt_type);
74897505

7490-
return hci_cmd_sync_queue_once(hdev, hci_change_conn_ptype_sync, cp,
7491-
pkt_type_changed);
7506+
err = hci_cmd_sync_queue_once(hdev, hci_change_conn_ptype_sync, cp,
7507+
pkt_type_changed);
7508+
return (err == -EEXIST) ? 0 : err;
74927509
}
74937510

74947511
static void le_phy_update_complete(struct hci_dev *hdev, void *data, int err)
@@ -7514,6 +7531,7 @@ int hci_le_set_phy(struct hci_conn *conn, u8 tx_phys, u8 rx_phys)
75147531
{
75157532
struct hci_dev *hdev = conn->hdev;
75167533
struct hci_cp_le_set_phy *cp;
7534+
int err;
75177535

75187536
cp = kmalloc_obj(*cp);
75197537
if (!cp)
@@ -7524,6 +7542,7 @@ int hci_le_set_phy(struct hci_conn *conn, u8 tx_phys, u8 rx_phys)
75247542
cp->tx_phys = tx_phys;
75257543
cp->rx_phys = rx_phys;
75267544

7527-
return hci_cmd_sync_queue_once(hdev, hci_le_set_phy_sync, cp,
7528-
le_phy_update_complete);
7545+
err = hci_cmd_sync_queue_once(hdev, hci_le_set_phy_sync, cp,
7546+
le_phy_update_complete);
7547+
return (err == -EEXIST) ? 0 : err;
75297548
}

0 commit comments

Comments
 (0)