]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
airoha: an7583: fix AN7583 PCS port count
authorRobert Marko <robert.marko@sartura.hr>
Thu, 16 Jul 2026 12:27:41 +0000 (14:27 +0200)
committerRobert Marko <robimarko@gmail.com>
Thu, 16 Jul 2026 12:30:21 +0000 (14:30 +0200)
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>
target/linux/airoha/patches-6.18/606-net-pcs-airoha-fix-an7583-port-count.patch [new file with mode: 0644]

diff --git a/target/linux/airoha/patches-6.18/606-net-pcs-airoha-fix-an7583-port-count.patch b/target/linux/airoha/patches-6.18/606-net-pcs-airoha-fix-an7583-port-count.patch
new file mode 100644 (file)
index 0000000..b948321
--- /dev/null
@@ -0,0 +1,61 @@
+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,
+ };