Skip to content

Commit fb856e5

Browse files
peterhurleyholtmann
authored andcommitted
Bluetooth: Cleanup RFCOMM device registration error handling
If RFCOMM tty device registration fails, cleanup by releasing the tty_port reference to trigger rfcomm_dev destruction (rather than open-coding it). The dlc reference release is moved into rfcomm_dev_add(), which ensures cleanup in both error paths -- ie., if __rfcomm_dev_add() fails or if tty_port_register_device() fails. Fixes releasing the module reference if device registration fails. Signed-off-by: Peter Hurley <peter@hurleysoftware.com> Tested-By: Alexander Holler <holler@ahsoftware.de> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent f355095 commit fb856e5

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

  • net/bluetooth/rfcomm

‎net/bluetooth/rfcomm/tty.c‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ static void rfcomm_dev_destruct(struct tty_port *port)
9393

9494
rfcomm_dlc_put(dlc);
9595

96-
tty_unregister_device(rfcomm_tty_driver, dev->id);
96+
if (dev->tty_dev)
97+
tty_unregister_device(rfcomm_tty_driver, dev->id);
9798

9899
spin_lock(&rfcomm_dev_lock);
99100
list_del(&dev->list);
@@ -317,16 +318,15 @@ static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc)
317318
BT_DBG("id %d channel %d", req->dev_id, req->channel);
318319

319320
dev = __rfcomm_dev_add(req, dlc);
320-
if (IS_ERR(dev))
321+
if (IS_ERR(dev)) {
322+
rfcomm_dlc_put(dlc);
321323
return PTR_ERR(dev);
324+
}
322325

323326
tty = tty_port_register_device(&dev->port, rfcomm_tty_driver,
324327
dev->id, NULL);
325328
if (IS_ERR(tty)) {
326-
spin_lock(&rfcomm_dev_lock);
327-
list_del(&dev->list);
328-
spin_unlock(&rfcomm_dev_lock);
329-
kfree(dev);
329+
tty_port_put(&dev->port);
330330
return PTR_ERR(tty);
331331
}
332332

@@ -420,10 +420,8 @@ static int __rfcomm_create_dev(struct sock *sk, void __user *arg)
420420
}
421421

422422
id = rfcomm_dev_add(&req, dlc);
423-
if (id < 0) {
424-
rfcomm_dlc_put(dlc);
423+
if (id < 0)
425424
return id;
426-
}
427425

428426
if (req.flags & (1 << RFCOMM_REUSE_DLC)) {
429427
/* DLC is now used by device.

0 commit comments

Comments
 (0)