Skip to content

Commit ecdc28d

Browse files
Ziyang Xuandavem330
authored andcommitted
net: hso: add failure handler for add_net_device
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>
1 parent b9edbfe commit ecdc28d

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
@@ -2535,13 +2535,17 @@ static struct hso_device *hso_create_net_device(struct usb_interface *interface,
25352535
if (!hso_net->mux_bulk_tx_buf)
25362536
goto err_free_tx_urb;
25372537

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

25402544
/* registering our net device */
25412545
result = register_netdev(net);
25422546
if (result) {
25432547
dev_err(&interface->dev, "Failed to register device\n");
2544-
goto err_free_tx_buf;
2548+
goto err_rmv_ndev;
25452549
}
25462550

25472551
hso_log_port(hso_dev);
@@ -2550,8 +2554,9 @@ static struct hso_device *hso_create_net_device(struct usb_interface *interface,
25502554

25512555
return hso_dev;
25522556

2553-
err_free_tx_buf:
2557+
err_rmv_ndev:
25542558
remove_net_device(hso_dev);
2559+
err_free_tx_buf:
25552560
kfree(hso_net->mux_bulk_tx_buf);
25562561
err_free_tx_urb:
25572562
usb_free_urb(hso_net->mux_bulk_tx_urb);

0 commit comments

Comments
 (0)