Skip to content

Commit e8a1b0e

Browse files
Luo binkuba-moo
authored andcommitted
hinic: fix a bug of ndo_stop
if some function in ndo_stop interface returns failure because of hardware fault, must go on excuting rest steps rather than return failure directly, otherwise will cause memory leak.And bump the timeout for SET_FUNC_STATE to ensure that cmd won't return failure when hw is busy. Otherwise hw may stomp host memory if we free memory regardless of the return value of SET_FUNC_STATE. Fixes: 51ba902 ("net-next/hinic: Initialize hw interface") Signed-off-by: Luo bin <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 3047211 commit e8a1b0e

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

drivers/net/ethernet/huawei/hinic/hinic_hw_mgmt.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545

4646
#define MGMT_MSG_TIMEOUT 5000
4747

48+
#define SET_FUNC_PORT_MGMT_TIMEOUT 25000
49+
4850
#define mgmt_to_pfhwdev(pf_mgmt) \
4951
container_of(pf_mgmt, struct hinic_pfhwdev, pf_to_mgmt)
5052

@@ -238,12 +240,13 @@ static int msg_to_mgmt_sync(struct hinic_pf_to_mgmt *pf_to_mgmt,
238240
u8 *buf_in, u16 in_size,
239241
u8 *buf_out, u16 *out_size,
240242
enum mgmt_direction_type direction,
241-
u16 resp_msg_id)
243+
u16 resp_msg_id, u32 timeout)
242244
{
243245
struct hinic_hwif *hwif = pf_to_mgmt->hwif;
244246
struct pci_dev *pdev = hwif->pdev;
245247
struct hinic_recv_msg *recv_msg;
246248
struct completion *recv_done;
249+
unsigned long timeo;
247250
u16 msg_id;
248251
int err;
249252

@@ -267,8 +270,9 @@ static int msg_to_mgmt_sync(struct hinic_pf_to_mgmt *pf_to_mgmt,
267270
goto unlock_sync_msg;
268271
}
269272

270-
if (!wait_for_completion_timeout(recv_done,
271-
msecs_to_jiffies(MGMT_MSG_TIMEOUT))) {
273+
timeo = msecs_to_jiffies(timeout ? timeout : MGMT_MSG_TIMEOUT);
274+
275+
if (!wait_for_completion_timeout(recv_done, timeo)) {
272276
dev_err(&pdev->dev, "MGMT timeout, MSG id = %d\n", msg_id);
273277
err = -ETIMEDOUT;
274278
goto unlock_sync_msg;
@@ -342,6 +346,7 @@ int hinic_msg_to_mgmt(struct hinic_pf_to_mgmt *pf_to_mgmt,
342346
{
343347
struct hinic_hwif *hwif = pf_to_mgmt->hwif;
344348
struct pci_dev *pdev = hwif->pdev;
349+
u32 timeout = 0;
345350

346351
if (sync != HINIC_MGMT_MSG_SYNC) {
347352
dev_err(&pdev->dev, "Invalid MGMT msg type\n");
@@ -353,9 +358,12 @@ int hinic_msg_to_mgmt(struct hinic_pf_to_mgmt *pf_to_mgmt,
353358
return -EINVAL;
354359
}
355360

361+
if (cmd == HINIC_PORT_CMD_SET_FUNC_STATE)
362+
timeout = SET_FUNC_PORT_MGMT_TIMEOUT;
363+
356364
return msg_to_mgmt_sync(pf_to_mgmt, mod, cmd, buf_in, in_size,
357365
buf_out, out_size, MGMT_DIRECT_SEND,
358-
MSG_NOT_RESP);
366+
MSG_NOT_RESP, timeout);
359367
}
360368

361369
/**

drivers/net/ethernet/huawei/hinic/hinic_main.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,6 @@ static int hinic_close(struct net_device *netdev)
483483
{
484484
struct hinic_dev *nic_dev = netdev_priv(netdev);
485485
unsigned int flags;
486-
int err;
487486

488487
down(&nic_dev->mgmt_lock);
489488

@@ -497,20 +496,9 @@ static int hinic_close(struct net_device *netdev)
497496

498497
up(&nic_dev->mgmt_lock);
499498

500-
err = hinic_port_set_func_state(nic_dev, HINIC_FUNC_PORT_DISABLE);
501-
if (err) {
502-
netif_err(nic_dev, drv, netdev,
503-
"Failed to set func port state\n");
504-
nic_dev->flags |= (flags & HINIC_INTF_UP);
505-
return err;
506-
}
499+
hinic_port_set_state(nic_dev, HINIC_PORT_DISABLE);
507500

508-
err = hinic_port_set_state(nic_dev, HINIC_PORT_DISABLE);
509-
if (err) {
510-
netif_err(nic_dev, drv, netdev, "Failed to set port state\n");
511-
nic_dev->flags |= (flags & HINIC_INTF_UP);
512-
return err;
513-
}
501+
hinic_port_set_func_state(nic_dev, HINIC_FUNC_PORT_DISABLE);
514502

515503
if (nic_dev->flags & HINIC_RSS_ENABLE) {
516504
hinic_rss_deinit(nic_dev);

0 commit comments

Comments
 (0)