[PATCH v2] memory: brcmstb_dpfe: Fix memory leak

Markus Mayer markus.mayer at broadcom.com
Thu Aug 20 13:44:15 EDT 2020


On Thu, 20 Aug 2020 at 10:21, Alex Dewar <alex.dewar90 at gmail.com> wrote:
>
> In brcmstb_dpfe_download_firmware(), memory is allocated to variable fw by
> firmware_request_nowarn(), but never released. Fix up to release fw on
> all return paths.

Thanks for the fix!

Acked-by: Markus Mayer <mmayer at broadcom.com>

> Signed-off-by: Alex Dewar <alex.dewar90 at gmail.com>
> ---
> v2: Don't assign ret unnecessarily (Krzysztof)
> ---
>  drivers/memory/brcmstb_dpfe.c | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/memory/brcmstb_dpfe.c b/drivers/memory/brcmstb_dpfe.c
> index 60e8633b1175..e08528b12cbd 100644
> --- a/drivers/memory/brcmstb_dpfe.c
> +++ b/drivers/memory/brcmstb_dpfe.c
> @@ -647,8 +647,10 @@ static int brcmstb_dpfe_download_firmware(struct brcmstb_dpfe_priv *priv)
>                 return (ret == -ENOENT) ? -EPROBE_DEFER : ret;
>
>         ret = __verify_firmware(&init, fw);
> -       if (ret)
> -               return -EFAULT;
> +       if (ret) {
> +               ret = -EFAULT;
> +               goto release_fw;
> +       }
>
>         __disable_dcpu(priv);
>
> @@ -667,18 +669,20 @@ static int brcmstb_dpfe_download_firmware(struct brcmstb_dpfe_priv *priv)
>
>         ret = __write_firmware(priv->dmem, dmem, dmem_size, is_big_endian);
>         if (ret)
> -               return ret;
> +               goto release_fw;
>         ret = __write_firmware(priv->imem, imem, imem_size, is_big_endian);
>         if (ret)
> -               return ret;
> +               goto release_fw;
>
>         ret = __verify_fw_checksum(&init, priv, header, init.chksum);
>         if (ret)
> -               return ret;
> +               goto release_fw;
>
>         __enable_dcpu(priv);
>
> -       return 0;
> +release_fw:
> +       release_firmware(fw);
> +       return ret;
>  }
>
>  static ssize_t generic_show(unsigned int command, u32 response[],
> --
> 2.28.0
>



More information about the linux-arm-kernel mailing list