Skip to content

Commit ebe937f

Browse files
Gianluca AnzolinGustavo Padovan
authored andcommitted
Bluetooth: Remove the device from the list in the destructor
The current code removes the device from the device list in several places. Do it only in the destructor instead and in the error path of rfcomm_add_dev() if the device couldn't be initialized. Signed-off-by: Gianluca Anzolin <gianluca@sottospazio.it> Reviewed-by: Peter Hurley <peter@hurleysoftware.com> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
1 parent 396dc22 commit ebe937f

1 file changed

Lines changed: 6 additions & 21 deletions

File tree

  • net/bluetooth/rfcomm

‎net/bluetooth/rfcomm/tty.c‎

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,16 @@ static void rfcomm_dev_modem_status(struct rfcomm_dlc *dlc, u8 v24_sig);
7676

7777
/* ---- Device functions ---- */
7878

79-
/*
80-
* The reason this isn't actually a race, as you no doubt have a little voice
81-
* screaming at you in your head, is that the refcount should never actually
82-
* reach zero unless the device has already been taken off the list, in
83-
* rfcomm_dev_del(). And if that's not true, we'll hit the BUG() in
84-
* rfcomm_dev_destruct() anyway.
85-
*/
8679
static void rfcomm_dev_destruct(struct tty_port *port)
8780
{
8881
struct rfcomm_dev *dev = container_of(port, struct rfcomm_dev, port);
8982
struct rfcomm_dlc *dlc = dev->dlc;
9083

9184
BT_DBG("dev %p dlc %p", dev, dlc);
9285

93-
/* Refcount should only hit zero when called from rfcomm_dev_del()
94-
which will have taken us off the list. Everything else are
95-
refcounting bugs. */
96-
BUG_ON(!list_empty(&dev->list));
86+
spin_lock(&rfcomm_dev_lock);
87+
list_del(&dev->list);
88+
spin_unlock(&rfcomm_dev_lock);
9789

9890
rfcomm_dlc_lock(dlc);
9991
/* Detach DLC if it's owned by this dev */
@@ -282,7 +274,9 @@ static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc)
282274
dev->id, NULL);
283275
if (IS_ERR(dev->tty_dev)) {
284276
err = PTR_ERR(dev->tty_dev);
277+
spin_lock(&rfcomm_dev_lock);
285278
list_del(&dev->list);
279+
spin_unlock(&rfcomm_dev_lock);
286280
goto free;
287281
}
288282

@@ -315,10 +309,6 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
315309
}
316310
spin_unlock_irqrestore(&dev->port.lock, flags);
317311

318-
spin_lock(&rfcomm_dev_lock);
319-
list_del_init(&dev->list);
320-
spin_unlock(&rfcomm_dev_lock);
321-
322312
tty_port_put(&dev->port);
323313
}
324314

@@ -750,13 +740,8 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
750740
dev->port.tty = NULL;
751741
rfcomm_dlc_unlock(dev->dlc);
752742

753-
if (test_bit(RFCOMM_TTY_RELEASED, &dev->flags)) {
754-
spin_lock(&rfcomm_dev_lock);
755-
list_del_init(&dev->list);
756-
spin_unlock(&rfcomm_dev_lock);
757-
743+
if (test_bit(RFCOMM_TTY_RELEASED, &dev->flags))
758744
tty_port_put(&dev->port);
759-
}
760745
} else
761746
spin_unlock_irqrestore(&dev->port.lock, flags);
762747

0 commit comments

Comments
 (0)