Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Pauli Virtanen and committed by
Luiz Augusto von Dentz
2969554b 2b2bf47c

+36 -17
+36 -17
net/bluetooth/hci_sync.c
··· 780 780 void *data, hci_cmd_sync_work_destroy_t destroy) 781 781 { 782 782 if (hci_cmd_sync_lookup_entry(hdev, func, data, destroy)) 783 - return 0; 783 + return -EEXIST; 784 784 785 785 return hci_cmd_sync_queue(hdev, func, data, destroy); 786 786 } ··· 3262 3262 3263 3263 int hci_update_passive_scan(struct hci_dev *hdev) 3264 3264 { 3265 + int err; 3266 + 3265 3267 /* Only queue if it would have any effect */ 3266 3268 if (!test_bit(HCI_UP, &hdev->flags) || 3267 3269 test_bit(HCI_INIT, &hdev->flags) || ··· 3273 3271 hci_dev_test_flag(hdev, HCI_UNREGISTER)) 3274 3272 return 0; 3275 3273 3276 - return hci_cmd_sync_queue_once(hdev, update_passive_scan_sync, NULL, 3277 - NULL); 3274 + err = hci_cmd_sync_queue_once(hdev, update_passive_scan_sync, NULL, 3275 + NULL); 3276 + return (err == -EEXIST) ? 0 : err; 3278 3277 } 3279 3278 3280 3279 int hci_write_sc_support_sync(struct hci_dev *hdev, u8 val) ··· 6968 6965 6969 6966 int hci_connect_acl_sync(struct hci_dev *hdev, struct hci_conn *conn) 6970 6967 { 6971 - return hci_cmd_sync_queue_once(hdev, hci_acl_create_conn_sync, conn, 6972 - NULL); 6968 + int err; 6969 + 6970 + err = hci_cmd_sync_queue_once(hdev, hci_acl_create_conn_sync, conn, 6971 + NULL); 6972 + return (err == -EEXIST) ? 0 : err; 6973 6973 } 6974 6974 6975 6975 static void create_le_conn_complete(struct hci_dev *hdev, void *data, int err) ··· 7008 7002 7009 7003 int hci_connect_le_sync(struct hci_dev *hdev, struct hci_conn *conn) 7010 7004 { 7011 - return hci_cmd_sync_queue_once(hdev, hci_le_create_conn_sync, conn, 7012 - create_le_conn_complete); 7005 + int err; 7006 + 7007 + err = hci_cmd_sync_queue_once(hdev, hci_le_create_conn_sync, conn, 7008 + create_le_conn_complete); 7009 + return (err == -EEXIST) ? 0 : err; 7013 7010 } 7014 7011 7015 7012 int hci_cancel_connect_sync(struct hci_dev *hdev, struct hci_conn *conn) ··· 7219 7210 7220 7211 int hci_connect_pa_sync(struct hci_dev *hdev, struct hci_conn *conn) 7221 7212 { 7222 - return hci_cmd_sync_queue_once(hdev, hci_le_pa_create_sync, conn, 7223 - create_pa_complete); 7213 + int err; 7214 + 7215 + err = hci_cmd_sync_queue_once(hdev, hci_le_pa_create_sync, conn, 7216 + create_pa_complete); 7217 + return (err == -EEXIST) ? 0 : err; 7224 7218 } 7225 7219 7226 7220 static void create_big_complete(struct hci_dev *hdev, void *data, int err) ··· 7285 7273 7286 7274 int hci_connect_big_sync(struct hci_dev *hdev, struct hci_conn *conn) 7287 7275 { 7288 - return hci_cmd_sync_queue_once(hdev, hci_le_big_create_sync, conn, 7289 - create_big_complete); 7276 + int err; 7277 + 7278 + err = hci_cmd_sync_queue_once(hdev, hci_le_big_create_sync, conn, 7279 + create_big_complete); 7280 + return (err == -EEXIST) ? 0 : err; 7290 7281 } 7291 7282 7292 7283 struct past_data { ··· 7381 7366 if (err) 7382 7367 kfree(data); 7383 7368 7384 - return err; 7369 + return (err == -EEXIST) ? 0 : err; 7385 7370 } 7386 7371 7387 7372 static void le_read_features_complete(struct hci_dev *hdev, void *data, int err) ··· 7468 7453 else 7469 7454 err = -EOPNOTSUPP; 7470 7455 7471 - return err; 7456 + return (err == -EEXIST) ? 0 : err; 7472 7457 } 7473 7458 7474 7459 static void pkt_type_changed(struct hci_dev *hdev, void *data, int err) ··· 7494 7479 { 7495 7480 struct hci_dev *hdev = conn->hdev; 7496 7481 struct hci_cp_change_conn_ptype *cp; 7482 + int err; 7497 7483 7498 7484 cp = kmalloc_obj(*cp); 7499 7485 if (!cp) ··· 7503 7487 cp->handle = cpu_to_le16(conn->handle); 7504 7488 cp->pkt_type = cpu_to_le16(pkt_type); 7505 7489 7506 - return hci_cmd_sync_queue_once(hdev, hci_change_conn_ptype_sync, cp, 7507 - pkt_type_changed); 7490 + err = hci_cmd_sync_queue_once(hdev, hci_change_conn_ptype_sync, cp, 7491 + pkt_type_changed); 7492 + return (err == -EEXIST) ? 0 : err; 7508 7493 } 7509 7494 7510 7495 static void le_phy_update_complete(struct hci_dev *hdev, void *data, int err) ··· 7531 7514 { 7532 7515 struct hci_dev *hdev = conn->hdev; 7533 7516 struct hci_cp_le_set_phy *cp; 7517 + int err; 7534 7518 7535 7519 cp = kmalloc_obj(*cp); 7536 7520 if (!cp) ··· 7542 7524 cp->tx_phys = tx_phys; 7543 7525 cp->rx_phys = rx_phys; 7544 7526 7545 - return hci_cmd_sync_queue_once(hdev, hci_le_set_phy_sync, cp, 7546 - le_phy_update_complete); 7527 + err = hci_cmd_sync_queue_once(hdev, hci_le_set_phy_sync, cp, 7528 + le_phy_update_complete); 7529 + return (err == -EEXIST) ? 0 : err; 7547 7530 }