[PATCH 3/3] media: imx8-isi: fix resource leaks in probe error paths and remove

Frank Li Frank.li at nxp.com
Mon May 4 09:21:49 PDT 2026


On Sat, Apr 25, 2026 at 07:19:26AM +0800, Xiaolei Wang wrote:
> mxc_isi_probe() allocates isi->pipes with kzalloc_objs() but never
> frees it on any probe failure path or in mxc_isi_remove(), leaking
> the allocation on every failed probe and every normal unbind.
>
> Additionally, when mxc_isi_pipe_init() fails partway through the
> channel loop or when mxc_isi_v4l2_init() fails, the already
> initialized pipes are not cleaned up — their media entities and
> mutexes are leaked.

Although it simple change, it is two problems, suggest use two patches to
fix it.

Frank
>
> Fix the pipes memory leak by switching from kzalloc_objs() to
> devm_kcalloc(), which ties the allocation lifetime to the device
> and eliminates the need for explicit kfree() in all error paths
> and in mxc_isi_remove().
>
> Fix the pipe init leak by cleaning up already-initialized pipes
> in the err_xbar error path.
>
> Fixes: cf21f328fcaf ("media: nxp: Add i.MX8 ISI driver")
> Cc: stable at vger.kernel.org
> Signed-off-by: Xiaolei Wang <xiaolei.wang at windriver.com>
> ---
>  drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c b/drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c
> index 2d639b789910..8533a979d60a 100644
> --- a/drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c
> +++ b/drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c
> @@ -485,7 +485,8 @@ static int mxc_isi_probe(struct platform_device *pdev)
>
>  	isi->pdata = of_device_get_match_data(dev);
>
> -	isi->pipes = kzalloc_objs(isi->pipes[0], isi->pdata->num_channels);
> +	isi->pipes = devm_kcalloc(dev, isi->pdata->num_channels,
> +				  sizeof(*isi->pipes), GFP_KERNEL);
>  	if (!isi->pipes)
>  		return -ENOMEM;
>
> @@ -538,6 +539,8 @@ static int mxc_isi_probe(struct platform_device *pdev)
>  	return 0;
>
>  err_xbar:
> +	while (i--)
> +		mxc_isi_pipe_cleanup(&isi->pipes[i]);
>  	mxc_isi_crossbar_cleanup(&isi->crossbar);
>
>  	return ret;
> --
> 2.43.0
>



More information about the linux-arm-kernel mailing list