Skip to content

Commit 9f13457

Browse files
Mingming Caodavem330
authored andcommitted
ibmvnic fix NULL tx_pools and rx_tools issue at do_reset
At the time of do_rest, ibmvnic tries to re-initalize the tx_pools and rx_pools to avoid re-allocating the long term buffer. However there is a window inside do_reset that the tx_pools and rx_pools were freed before re-initialized making it possible to deference null pointers. This patch fix this issue by always check the tx_pool and rx_pool are not NULL after ibmvnic_login. If so, re-allocating the pools. This will avoid getting into calling reset_tx/rx_pools with NULL adapter tx_pools/rx_pools pointer. Also add null pointer check in reset_tx_pools and reset_rx_pools to safe handle NULL pointer case. Signed-off-by: Mingming Cao <[email protected]> Signed-off-by: Dany Madden <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2c6500e commit 9f13457

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

drivers/net/ethernet/ibm/ibmvnic.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,9 @@ static int reset_rx_pools(struct ibmvnic_adapter *adapter)
479479
int i, j, rc;
480480
u64 *size_array;
481481

482+
if (!adapter->rx_pool)
483+
return -1;
484+
482485
size_array = (u64 *)((u8 *)(adapter->login_rsp_buf) +
483486
be32_to_cpu(adapter->login_rsp_buf->off_rxadd_buff_size));
484487

@@ -649,6 +652,9 @@ static int reset_tx_pools(struct ibmvnic_adapter *adapter)
649652
int tx_scrqs;
650653
int i, rc;
651654

655+
if (!adapter->tx_pool)
656+
return -1;
657+
652658
tx_scrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs);
653659
for (i = 0; i < tx_scrqs; i++) {
654660
rc = reset_one_tx_pool(adapter, &adapter->tso_pool[i]);
@@ -2011,7 +2017,10 @@ static int do_reset(struct ibmvnic_adapter *adapter,
20112017
adapter->req_rx_add_entries_per_subcrq !=
20122018
old_num_rx_slots ||
20132019
adapter->req_tx_entries_per_subcrq !=
2014-
old_num_tx_slots) {
2020+
old_num_tx_slots ||
2021+
!adapter->rx_pool ||
2022+
!adapter->tso_pool ||
2023+
!adapter->tx_pool) {
20152024
release_rx_pools(adapter);
20162025
release_tx_pools(adapter);
20172026
release_napi(adapter);
@@ -2024,10 +2033,14 @@ static int do_reset(struct ibmvnic_adapter *adapter,
20242033
} else {
20252034
rc = reset_tx_pools(adapter);
20262035
if (rc)
2036+
netdev_dbg(adapter->netdev, "reset tx pools failed (%d)\n",
2037+
rc);
20272038
goto out;
20282039

20292040
rc = reset_rx_pools(adapter);
20302041
if (rc)
2042+
netdev_dbg(adapter->netdev, "reset rx pools failed (%d)\n",
2043+
rc);
20312044
goto out;
20322045
}
20332046
ibmvnic_disable_irqs(adapter);

0 commit comments

Comments
 (0)