diff options
author | Peter Hurley <peter@hurleysoftware.com> | 2014-02-09 20:59:20 -0500 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2014-02-14 16:39:32 -0500 |
commit | fb856e50900a84dd9f8d50d3882eb4a26ba6ea54 (patch) | |
tree | b04ea2e97ced0ca36862e776b779679e5546c9b3 | |
parent | f355095756c2a0b77a5b0aa0384c0c09d9735252 (diff) |
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>
-rw-r--r-- | net/bluetooth/rfcomm/tty.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c index 0537a0501595..375b60dae04d 100644 --- a/net/bluetooth/rfcomm/tty.c +++ b/net/bluetooth/rfcomm/tty.c | |||
@@ -93,7 +93,8 @@ static void rfcomm_dev_destruct(struct tty_port *port) | |||
93 | 93 | ||
94 | rfcomm_dlc_put(dlc); | 94 | rfcomm_dlc_put(dlc); |
95 | 95 | ||
96 | tty_unregister_device(rfcomm_tty_driver, dev->id); | 96 | if (dev->tty_dev) |
97 | tty_unregister_device(rfcomm_tty_driver, dev->id); | ||
97 | 98 | ||
98 | spin_lock(&rfcomm_dev_lock); | 99 | spin_lock(&rfcomm_dev_lock); |
99 | list_del(&dev->list); | 100 | list_del(&dev->list); |
@@ -317,16 +318,15 @@ static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc) | |||
317 | BT_DBG("id %d channel %d", req->dev_id, req->channel); | 318 | BT_DBG("id %d channel %d", req->dev_id, req->channel); |
318 | 319 | ||
319 | dev = __rfcomm_dev_add(req, dlc); | 320 | dev = __rfcomm_dev_add(req, dlc); |
320 | if (IS_ERR(dev)) | 321 | if (IS_ERR(dev)) { |
322 | rfcomm_dlc_put(dlc); | ||
321 | return PTR_ERR(dev); | 323 | return PTR_ERR(dev); |
324 | } | ||
322 | 325 | ||
323 | tty = tty_port_register_device(&dev->port, rfcomm_tty_driver, | 326 | tty = tty_port_register_device(&dev->port, rfcomm_tty_driver, |
324 | dev->id, NULL); | 327 | dev->id, NULL); |
325 | if (IS_ERR(tty)) { | 328 | if (IS_ERR(tty)) { |
326 | spin_lock(&rfcomm_dev_lock); | 329 | tty_port_put(&dev->port); |
327 | list_del(&dev->list); | ||
328 | spin_unlock(&rfcomm_dev_lock); | ||
329 | kfree(dev); | ||
330 | return PTR_ERR(tty); | 330 | return PTR_ERR(tty); |
331 | } | 331 | } |
332 | 332 | ||
@@ -420,10 +420,8 @@ static int __rfcomm_create_dev(struct sock *sk, void __user *arg) | |||
420 | } | 420 | } |
421 | 421 | ||
422 | id = rfcomm_dev_add(&req, dlc); | 422 | id = rfcomm_dev_add(&req, dlc); |
423 | if (id < 0) { | 423 | if (id < 0) |
424 | rfcomm_dlc_put(dlc); | ||
425 | return id; | 424 | return id; |
426 | } | ||
427 | 425 | ||
428 | if (req.flags & (1 << RFCOMM_REUSE_DLC)) { | 426 | if (req.flags & (1 << RFCOMM_REUSE_DLC)) { |
429 | /* DLC is now used by device. | 427 | /* DLC is now used by device. |