Files
eternalwrt-mt798x/target/linux/airoha/patches-6.18/606-net-pcs-airoha-fix-an7583-port-count.patch
T
Robert MarkoandRobert Marko 4be1036213 airoha: an7583: fix AN7583 PCS port count
The AN7583 PCS match data does not initialize num_port. This leaves it at
zero, so probe allocates a zero-sized ports array and a later PCS lookup
returns a pointer derived from NULL.

Set the number of ports for each AN7583 PCS instance. Also reject
out-of-range PCS indices defensively.

Fixes kernel crashing on boot once ethernet starts probing on AN7583.

Signed-off-by: Robert Marko <robert.marko@sartura.hr>
2026-07-16 14:30:21 +02:00

62 lines
1.9 KiB
Diff

From: Robert Marko <robert.marko@sartura.hr>
Date: Thu, 16 Jul 2026 14:00:00 +0200
Subject: [PATCH] net: pcs: airoha: fix AN7583 PCS port count
The AN7583 PCS match data does not initialize num_port. This leaves it at
zero, so probe allocates a zero-sized ports array and a later PCS lookup
returns a pointer derived from NULL.
Set the number of ports for each AN7583 PCS instance. Also reject
out-of-range PCS indices defensively.
Signed-off-by: Robert Marko <robert.marko@sartura.hr>
---
drivers/net/pcs/airoha/pcs-airoha-common.c | 10 ++++++++++
1 file changed, 10 insertions(+)
--- a/drivers/net/pcs/airoha/pcs-airoha-common.c
+++ b/drivers/net/pcs/airoha/pcs-airoha-common.c
@@ -1170,6 +1170,10 @@ static struct phylink_pcs *airoha_pcs_ge
if (pcsspec->nargs)
index = pcsspec->args[0];
+ if (index >= priv->data->num_port)
+ return dev_err_ptr_probe(dev, -EINVAL,
+ "invalid PCS index %d\n", index);
+
return &priv->ports[index].pcs;
}
@@ -1418,6 +1422,7 @@ static const struct airoha_pcs_match_dat
};
static const struct airoha_pcs_match_data an7583_pcs_eth = {
+ .num_port = 1,
.port_type = AIROHA_PCS_ETH,
.usxgmii_rx_gb_out_vld_tweak = true,
.usxgmii_xfi_mode_sel = true,
@@ -1426,6 +1431,7 @@ static const struct airoha_pcs_match_dat
};
static const struct airoha_pcs_match_data an7583_pcs_pon = {
+ .num_port = 1,
.port_type = AIROHA_PCS_PON,
.usxgmii_rx_gb_out_vld_tweak = true,
.usxgmii_xfi_mode_sel = true,
@@ -1434,6 +1440,7 @@ static const struct airoha_pcs_match_dat
};
static const struct airoha_pcs_match_data an7583_pcs_pcie = {
+ .num_port = 2,
.port_type = AIROHA_PCS_PCIE,
.usxgmii_rx_gb_out_vld_tweak = true,
.usxgmii_xfi_mode_sel = true,
@@ -1442,6 +1449,7 @@ static const struct airoha_pcs_match_dat
};
static const struct airoha_pcs_match_data an7583_pcs_usb = {
+ .num_port = 1,
.port_type = AIROHA_PCS_USB,
.bringup = an7583_pcs_usb_phya_bringup,
};