Skip to content

Commit 1b25990

Browse files
elfringholtmann
authored andcommitted
Bluetooth: Use common error handling code in bt_init()
* Improve jump targets so that a bit of exception handling can be better reused at the end of this function. * Adjust five condition checks. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]>
1 parent ba8f359 commit 1b25990

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

net/bluetooth/af_bluetooth.c

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -766,43 +766,39 @@ static int __init bt_init(void)
766766
return err;
767767

768768
err = sock_register(&bt_sock_family_ops);
769-
if (err < 0) {
770-
bt_sysfs_cleanup();
771-
return err;
772-
}
769+
if (err)
770+
goto cleanup_sysfs;
773771

774772
BT_INFO("HCI device and connection manager initialized");
775773

776774
err = hci_sock_init();
777-
if (err < 0)
778-
goto error;
775+
if (err)
776+
goto unregister_socket;
779777

780778
err = l2cap_init();
781-
if (err < 0)
782-
goto sock_err;
779+
if (err)
780+
goto cleanup_socket;
783781

784782
err = sco_init();
785-
if (err < 0) {
786-
l2cap_exit();
787-
goto sock_err;
788-
}
783+
if (err)
784+
goto cleanup_cap;
789785

790786
err = mgmt_init();
791-
if (err < 0) {
792-
sco_exit();
793-
l2cap_exit();
794-
goto sock_err;
795-
}
787+
if (err)
788+
goto cleanup_sco;
796789

797790
return 0;
798791

799-
sock_err:
792+
cleanup_sco:
793+
sco_exit();
794+
cleanup_cap:
795+
l2cap_exit();
796+
cleanup_socket:
800797
hci_sock_cleanup();
801-
802-
error:
798+
unregister_socket:
803799
sock_unregister(PF_BLUETOOTH);
800+
cleanup_sysfs:
804801
bt_sysfs_cleanup();
805-
806802
return err;
807803
}
808804

0 commit comments

Comments
 (0)