[PATCH net 2/2] net/stmmac: Verify provided DTS AXI setup
Jakub Raczynski
j.raczynski at samsung.com
Tue Jul 7 10:44:31 PDT 2026
During parsing of AXI setup, there are few issues:
- 'axi_blen' array is uninitialized value on stack without zero-init stack
configured. This can result in random AXI burst length config if
DTS config provides shorter array than AXI_BLEN.
Fix this by initializing it to zero, which allows to provide shorter configs,
which sometimes happens where only one value is used.
- stmmac_axi_blen_to_mask() is executed regardless of return of
of_property_read_u32_array(). This is not issue after axi_blen is
initialized to zero, as zero blen values are skipped in
stmmac_axi_blen_to_mask(), but that would be useless operation.
Fix it by checking return value of of_property_read_u32_array() and
parse any legit config.
- In case of failed memory allocation for AXI and error, there is no handling
of that. Fix it by checking if AXI config is error and return if so,
as this can only lack of memory. No AXI config, although is probably
wrong in most cases, is not treated as error, as generic config is mostly
provided in drivers.
Fixes: afea03656add ("stmmac: rework DMA bus setting and introduce new platform AXI structure")
Reported-by: Sashiko AI <sashiko-bot at kernel.org>
Signed-off-by: Jakub Raczynski <j.raczynski at samsung.com>
---
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index 9112cd69b9b1..0acc61a98292 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -95,7 +95,7 @@ static struct stmmac_axi *stmmac_axi_setup(struct platform_device *pdev)
{
struct device_node *np;
struct stmmac_axi *axi;
- u32 axi_blen[AXI_BLEN];
+ u32 axi_blen[AXI_BLEN] = { 0 };
np = of_parse_phandle(pdev->dev.of_node, "snps,axi-config", 0);
if (!np)
@@ -115,8 +115,8 @@ static struct stmmac_axi *stmmac_axi_setup(struct platform_device *pdev)
axi->axi_wr_osr_lmt = 1;
if (of_property_read_u32(np, "snps,rd_osr_lmt", &axi->axi_rd_osr_lmt))
axi->axi_rd_osr_lmt = 1;
- of_property_read_u32_array(np, "snps,blen", axi_blen, AXI_BLEN);
- stmmac_axi_blen_to_mask(&axi->axi_blen_regval, axi_blen, AXI_BLEN);
+ if (!of_property_read_u32_array(np, "snps,blen", axi_blen, AXI_BLEN))
+ stmmac_axi_blen_to_mask(&axi->axi_blen_regval, axi_blen, AXI_BLEN);
of_node_put(np);
return axi;
@@ -580,6 +580,10 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
of_property_read_u32(np, "snps,ps-speed", &plat->mac_port_sel_speed);
plat->axi = stmmac_axi_setup(pdev);
+ if (IS_ERR(plat->axi)) {
+ ret = plat->axi;
+ goto error_put_mdio;
+ }
rc = stmmac_mtl_setup(pdev, plat);
if (rc) {
--
2.34.1
More information about the linux-arm-kernel
mailing list