Skip to content

Commit 25ab2db

Browse files
iulia-tanasescuVudentz
authored andcommitted
Bluetooth: hci_conn: Remove alloc from critical section
This removes the kzalloc memory allocation inside critical section in create_pa_sync, fixing the following message that appears when the kernel is compiled with CONFIG_DEBUG_ATOMIC_SLEEP enabled: BUG: sleeping function called from invalid context at include/linux/sched/mm.h:321 Signed-off-by: Iulia Tanasescu <[email protected]> Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent dc26097 commit 25ab2db

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

net/bluetooth/hci_conn.c

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,7 +2079,7 @@ static bool hci_conn_check_create_pa_sync(struct hci_conn *conn)
20792079

20802080
static int create_pa_sync(struct hci_dev *hdev, void *data)
20812081
{
2082-
struct hci_cp_le_pa_create_sync *cp = NULL;
2082+
struct hci_cp_le_pa_create_sync cp = {0};
20832083
struct hci_conn *conn;
20842084
int err = 0;
20852085

@@ -2108,19 +2108,13 @@ static int create_pa_sync(struct hci_dev *hdev, void *data)
21082108
if (hci_conn_check_create_pa_sync(conn)) {
21092109
struct bt_iso_qos *qos = &conn->iso_qos;
21102110

2111-
cp = kzalloc(sizeof(*cp), GFP_KERNEL);
2112-
if (!cp) {
2113-
err = -ENOMEM;
2114-
goto unlock;
2115-
}
2116-
2117-
cp->options = qos->bcast.options;
2118-
cp->sid = conn->sid;
2119-
cp->addr_type = conn->dst_type;
2120-
bacpy(&cp->addr, &conn->dst);
2121-
cp->skip = cpu_to_le16(qos->bcast.skip);
2122-
cp->sync_timeout = cpu_to_le16(qos->bcast.sync_timeout);
2123-
cp->sync_cte_type = qos->bcast.sync_cte_type;
2111+
cp.options = qos->bcast.options;
2112+
cp.sid = conn->sid;
2113+
cp.addr_type = conn->dst_type;
2114+
bacpy(&cp.addr, &conn->dst);
2115+
cp.skip = cpu_to_le16(qos->bcast.skip);
2116+
cp.sync_timeout = cpu_to_le16(qos->bcast.sync_timeout);
2117+
cp.sync_cte_type = qos->bcast.sync_cte_type;
21242118

21252119
break;
21262120
}
@@ -2131,17 +2125,15 @@ static int create_pa_sync(struct hci_dev *hdev, void *data)
21312125

21322126
hci_dev_unlock(hdev);
21332127

2134-
if (cp) {
2128+
if (bacmp(&cp.addr, BDADDR_ANY)) {
21352129
hci_dev_set_flag(hdev, HCI_PA_SYNC);
21362130
set_bit(HCI_CONN_CREATE_PA_SYNC, &conn->flags);
21372131

21382132
err = __hci_cmd_sync_status(hdev, HCI_OP_LE_PA_CREATE_SYNC,
2139-
sizeof(*cp), cp, HCI_CMD_TIMEOUT);
2133+
sizeof(cp), &cp, HCI_CMD_TIMEOUT);
21402134
if (!err)
21412135
err = hci_update_passive_scan_sync(hdev);
21422136

2143-
kfree(cp);
2144-
21452137
if (err) {
21462138
hci_dev_clear_flag(hdev, HCI_PA_SYNC);
21472139
clear_bit(HCI_CONN_CREATE_PA_SYNC, &conn->flags);

0 commit comments

Comments
 (0)