Commit fb856e50 authored by Peter Hurley's avatar Peter Hurley Committed by Marcel Holtmann

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: default avatarPeter Hurley <peter@hurleysoftware.com>
Tested-By: default avatarAlexander Holler <holler@ahsoftware.de>
Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
parent f3550957
...@@ -93,7 +93,8 @@ static void rfcomm_dev_destruct(struct tty_port *port) ...@@ -93,7 +93,8 @@ static void rfcomm_dev_destruct(struct tty_port *port)
rfcomm_dlc_put(dlc); rfcomm_dlc_put(dlc);
tty_unregister_device(rfcomm_tty_driver, dev->id); if (dev->tty_dev)
tty_unregister_device(rfcomm_tty_driver, dev->id);
spin_lock(&rfcomm_dev_lock); spin_lock(&rfcomm_dev_lock);
list_del(&dev->list); list_del(&dev->list);
...@@ -317,16 +318,15 @@ static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc) ...@@ -317,16 +318,15 @@ static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc)
BT_DBG("id %d channel %d", req->dev_id, req->channel); BT_DBG("id %d channel %d", req->dev_id, req->channel);
dev = __rfcomm_dev_add(req, dlc); dev = __rfcomm_dev_add(req, dlc);
if (IS_ERR(dev)) if (IS_ERR(dev)) {
rfcomm_dlc_put(dlc);
return PTR_ERR(dev); return PTR_ERR(dev);
}
tty = tty_port_register_device(&dev->port, rfcomm_tty_driver, tty = tty_port_register_device(&dev->port, rfcomm_tty_driver,
dev->id, NULL); dev->id, NULL);
if (IS_ERR(tty)) { if (IS_ERR(tty)) {
spin_lock(&rfcomm_dev_lock); tty_port_put(&dev->port);
list_del(&dev->list);
spin_unlock(&rfcomm_dev_lock);
kfree(dev);
return PTR_ERR(tty); return PTR_ERR(tty);
} }
...@@ -420,10 +420,8 @@ static int __rfcomm_create_dev(struct sock *sk, void __user *arg) ...@@ -420,10 +420,8 @@ static int __rfcomm_create_dev(struct sock *sk, void __user *arg)
} }
id = rfcomm_dev_add(&req, dlc); id = rfcomm_dev_add(&req, dlc);
if (id < 0) { if (id < 0)
rfcomm_dlc_put(dlc);
return id; return id;
}
if (req.flags & (1 << RFCOMM_REUSE_DLC)) { if (req.flags & (1 << RFCOMM_REUSE_DLC)) {
/* DLC is now used by device. /* DLC is now used by device.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment