[PATCH net-next v4 2/6] net: enetc: Allocate int_vector array dynamically

From: Claudiu Manoil

Date: Fri Nov 13 2026 - 11:07:16 EST


The number of Rx/Tx ring interrupt vectors, priv->bdr_int_num, is set
in enetc_init_si_rings_params() to the lesser of the number of online
CPUs and the number of Rx rings of the station interface. The
int_vector[] array in struct enetc_ndev_priv, however, has a fixed
size of ENETC_MAX_BDR_INT (6), a limit that dates back to the maximum
CPU count of the SoCs integrating ENETC at the time.

That assumption does not hold for S32N79, which has 8 CPUs and gives
the ENETC PF up to 8 Rx rings. There, bdr_int_num can reach 8, and
enetc_alloc_msix() writes priv->int_vector[i] past the end of the
array, corrupting the adjacent fields of the netdev private area.
No SoC currently supported upstream exceeds 6 vectors, so this is not
reachable today; it must be fixed before S32N79 devices can be enabled
by a following patch.

Allocate int_vector[] with devm_kcalloc() in enetc_alloc_msix(), once
bdr_int_num is known. The memory is released together with the PCI
device, so no explicit free is needed on the error or teardown paths.
This is common code, so the PF and VF drivers benefit alike. Drop the
ENETC_MAX_BDR_INT define, which only existed to size this array.

Signed-off-by: Claudiu Manoil <claudiu.manoil@xxxxxxx>
---
v4:
- New patch. Prevents an out-of-bounds access to priv->int_vector[]
when bdr_int_num exceeds 6, as is the case on S32N79, as requested
in review.

drivers/net/ethernet/freescale/enetc/enetc.c | 8 ++++++++
drivers/net/ethernet/freescale/enetc/enetc.h | 3 +--
2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c
index c6571b5cc842..855b2d3b8718 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc.c
@@ -3641,6 +3641,13 @@ int enetc_alloc_msix(struct enetc_ndev_priv *priv)
if (n != nvec)
return -EPERM;

+ priv->int_vector = devm_kcalloc(&pdev->dev, priv->bdr_int_num,
+ sizeof(*priv->int_vector), GFP_KERNEL);
+ if (!priv->int_vector) {
+ err = -ENOMEM;
+ goto fail_int_vector;
+ }
+
/* # of tx rings per int vector */
v_tx_rings = priv->num_tx_rings / priv->bdr_int_num;
v_remainder = priv->num_tx_rings % priv->bdr_int_num;
@@ -3676,6 +3683,7 @@ int enetc_alloc_msix(struct enetc_ndev_priv *priv)
while (i--)
enetc_int_vector_destroy(priv, i);

+fail_int_vector:
pci_free_irq_vectors(pdev);

return err;
diff --git a/drivers/net/ethernet/freescale/enetc/enetc.h b/drivers/net/ethernet/freescale/enetc/enetc.h
index d9e91832a9c1..689ad82b2949 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc.h
+++ b/drivers/net/ethernet/freescale/enetc/enetc.h
@@ -407,7 +407,6 @@ struct enetc_cls_rule {
int used;
};

-#define ENETC_MAX_BDR_INT 6 /* fixed to max # of available cpus */
struct psfp_cap {
u32 max_streamid;
u32 max_psfp_filter;
@@ -456,7 +455,7 @@ struct enetc_ndev_priv {
struct enetc_si *si;

int bdr_int_num; /* number of Rx/Tx ring interrupts */
- struct enetc_int_vector *int_vector[ENETC_MAX_BDR_INT];
+ struct enetc_int_vector **int_vector;
u16 num_rx_rings, num_tx_rings;
u16 rx_bd_count, tx_bd_count;

--
2.34.1