Skip to content

Commit

Permalink
Bluetooth: Fix error handling for l2cap_init()
Browse files Browse the repository at this point in the history
create_singlethread_workqueue() may fail with errors such as -ENOMEM. If
this happens, the return value is not set to a negative value and the
module load will succeed. It will then crash on module unload because of
a destroy_workqueue() call on a NULL pointer.

Additionally, the _busy_wq workqueue is not being destroyed if any
errors happen on l2cap_init().

Signed-off-by: Anderson Lizardo <anderson.lizardo@openbossa.org>
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
  • Loading branch information
Anderson Lizardo authored and Gustavo F. Padovan committed Dec 1, 2010
1 parent eeb3665 commit b78d7b4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions net/bluetooth/l2cap.c
Original file line number Diff line number Diff line change
Expand Up @@ -4871,8 +4871,10 @@ static int __init l2cap_init(void)
return err;

_busy_wq = create_singlethread_workqueue("l2cap");
if (!_busy_wq)
goto error;
if (!_busy_wq) {
proto_unregister(&l2cap_proto);
return -ENOMEM;
}

err = bt_sock_register(BTPROTO_L2CAP, &l2cap_sock_family_ops);
if (err < 0) {
Expand Down Expand Up @@ -4900,6 +4902,7 @@ static int __init l2cap_init(void)
return 0;

error:
destroy_workqueue(_busy_wq);
proto_unregister(&l2cap_proto);
return err;
}
Expand Down

0 comments on commit b78d7b4

Please sign in to comment.