Skip to content

Commit f89b0d0

Browse files
Ziyang Xuangregkh
authored andcommitted
net: hso: add failure handler for add_net_device
[ Upstream commit ecdc28d ] If the network devices connected to the system beyond HSO_MAX_NET_DEVICES. add_net_device() in hso_create_net_device() will be failed for the network_table is full. It will lead to business failure which rely on network_table, for example, hso_suspend() and hso_resume(). It will also lead to memory leak because resource release process can not search the hso_device object from network_table in hso_free_interface(). Add failure handler for add_net_device() in hso_create_net_device() to solve the above problems. Fixes: 72dc1c0 ("HSO: add option hso driver") Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent f450958 commit f89b0d0

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎drivers/net/usb/hso.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,13 +2537,17 @@ static struct hso_device *hso_create_net_device(struct usb_interface *interface,
25372537
if (!hso_net->mux_bulk_tx_buf)
25382538
goto err_free_tx_urb;
25392539

2540-
add_net_device(hso_dev);
2540+
result = add_net_device(hso_dev);
2541+
if (result) {
2542+
dev_err(&interface->dev, "Failed to add net device\n");
2543+
goto err_free_tx_buf;
2544+
}
25412545

25422546
/* registering our net device */
25432547
result = register_netdev(net);
25442548
if (result) {
25452549
dev_err(&interface->dev, "Failed to register device\n");
2546-
goto err_free_tx_buf;
2550+
goto err_rmv_ndev;
25472551
}
25482552

25492553
hso_log_port(hso_dev);
@@ -2552,8 +2556,9 @@ static struct hso_device *hso_create_net_device(struct usb_interface *interface,
25522556

25532557
return hso_dev;
25542558

2555-
err_free_tx_buf:
2559+
err_rmv_ndev:
25562560
remove_net_device(hso_dev);
2561+
err_free_tx_buf:
25572562
kfree(hso_net->mux_bulk_tx_buf);
25582563
err_free_tx_urb:
25592564
usb_free_urb(hso_net->mux_bulk_tx_urb);

0 commit comments

Comments
 (0)