Skip to content

Commit 9e7f211

Browse files
wangxiaoningnxpdavem330
authored andcommitted
net: enetc: optimize the allocation of tx_bdr
There is a situation where num_tx_rings cannot be divided by bdr_int_num. For example, num_tx_rings is 8 and bdr_int_num is 3. According to the previous logic, this results in two tx_bdr corresponding memories not being allocated, so when sending packets to tx ring 6 or 7, wild pointers will be accessed. Of course, this issue doesn't exist on LS1028A, because its num_tx_rings is 8, and bdr_int_num is either 1 or 2. However, there is a risk for the upcoming i.MX95. Therefore, it is necessary to ensure that each tx_bdr can be allocated to the corresponding memory. Signed-off-by: Clark Wang <[email protected]> Signed-off-by: Wei Fang <[email protected]> Reviewed-by: Claudiu Manoil <[email protected]> Reviewed-by: Frank Li <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b4bfd0a commit 9e7f211

File tree

1 file changed

+8
-2
lines changed
  • drivers/net/ethernet/freescale/enetc

1 file changed

+8
-2
lines changed

drivers/net/ethernet/freescale/enetc/enetc.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3084,10 +3084,10 @@ static void enetc_int_vector_destroy(struct enetc_ndev_priv *priv, int i)
30843084
int enetc_alloc_msix(struct enetc_ndev_priv *priv)
30853085
{
30863086
struct pci_dev *pdev = priv->si->pdev;
3087+
int v_tx_rings, v_remainder;
30873088
int num_stack_tx_queues;
30883089
int first_xdp_tx_ring;
30893090
int i, n, err, nvec;
3090-
int v_tx_rings;
30913091

30923092
nvec = ENETC_BDR_INT_BASE_IDX + priv->bdr_int_num;
30933093
/* allocate MSIX for both messaging and Rx/Tx interrupts */
@@ -3101,9 +3101,15 @@ int enetc_alloc_msix(struct enetc_ndev_priv *priv)
31013101

31023102
/* # of tx rings per int vector */
31033103
v_tx_rings = priv->num_tx_rings / priv->bdr_int_num;
3104+
v_remainder = priv->num_tx_rings % priv->bdr_int_num;
31043105

31053106
for (i = 0; i < priv->bdr_int_num; i++) {
3106-
err = enetc_int_vector_init(priv, i, v_tx_rings);
3107+
/* Distribute the remaining TX rings to the first v_remainder
3108+
* interrupt vectors
3109+
*/
3110+
int num_tx_rings = i < v_remainder ? v_tx_rings + 1 : v_tx_rings;
3111+
3112+
err = enetc_int_vector_init(priv, i, num_tx_rings);
31073113
if (err)
31083114
goto fail;
31093115
}

0 commit comments

Comments
 (0)