[PATCH] net: zynq: Free allocated buffers in case of error

Michal Simek monstr at monstr.eu
Fri Feb 28 12:18:11 CET 2020


čt 6. 2. 2020 v 16:04 odesílatel Michal Simek <michal.simek at xilinx.com> napsal:
>
> Driver probe function is called again and again in case of error.
> Malloc space is getting full which is is reported by:
>  Insufficient RAM for page table: 0x15000 > 0x14000.
>  Please increase the size in get_page_table_size()
>  ### ERROR ### Please RESET the board ###
>
> The patch is freeing allocated buffers on error path to avoid panic.
>
> Signed-off-by: Michal Simek <michal.simek at xilinx.com>
> ---
>
>  drivers/net/zynq_gem.c | 22 +++++++++++++++++-----
>  1 file changed, 17 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/zynq_gem.c b/drivers/net/zynq_gem.c
> index 879129653df3..745c65cf471c 100644
> --- a/drivers/net/zynq_gem.c
> +++ b/drivers/net/zynq_gem.c
> @@ -659,8 +659,10 @@ static int zynq_gem_probe(struct udevice *dev)
>
>         /* Align bd_space to MMU_SECTION_SHIFT */
>         bd_space = memalign(1 << MMU_SECTION_SHIFT, BD_SPACE);
> -       if (!bd_space)
> -               return -ENOMEM;
> +       if (!bd_space) {
> +               ret = -ENOMEM;
> +               goto err1;
> +       }
>
>         mmu_set_region_dcache_behaviour((phys_addr_t)bd_space,
>                                         BD_SPACE, DCACHE_OFF);
> @@ -672,7 +674,7 @@ static int zynq_gem_probe(struct udevice *dev)
>         ret = clk_get_by_name(dev, "tx_clk", &priv->clk);
>         if (ret < 0) {
>                 dev_err(dev, "failed to get clock\n");
> -               return -EINVAL;
> +               goto err1;
>         }
>
>         priv->bus = mdio_alloc();
> @@ -682,9 +684,19 @@ static int zynq_gem_probe(struct udevice *dev)
>
>         ret = mdio_register_seq(priv->bus, dev->seq);
>         if (ret)
> -               return ret;
> +               goto err2;
>
> -       return zynq_phy_init(dev);
> +       ret = zynq_phy_init(dev);
> +       if (ret)
> +               goto err2;
> +
> +       return ret;
> +
> +err2:
> +       free(priv->rxbuffers);
> +err1:
> +       free(priv->tx_bd);
> +       return ret;
>  }
>
>  static int zynq_gem_remove(struct udevice *dev)
> --
> 2.25.0
>

Applied.
M

-- 
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Xilinx Microblaze
Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs
U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs


More information about the U-Boot mailing list