* Re: [PATCH] media: nxp: imx8-isi: Fix small memory leak at unbind time
2026-11-30 2:23 [PATCH] media: nxp: imx8-isi: Fix small memory leak at unbind time Laurent Pinchart
@ 2026-11-30 2:28 ` sashiko-bot
2026-11-30 8:15 ` Paul Elder
2026-11-30 15:34 ` Frank Li
2 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-30 2:28 UTC (permalink / raw)
To: Laurent Pinchart; +Cc: imx, Frank.Li, media-ci
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] media: nxp: imx8-isi: missing pipe unregistration in
mxc_isi_v4l2_init() [1]
--
commit a31b14b46ef772648d300c8e857600dbf5ef7ce4
Author: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
media: nxp: imx8-isi: Fix small memory leak at unbind time
This commit switches the allocation of isi->pipes in mxc_isi_probe() from
kzalloc_objs() to devm_kzalloc_objs() so the array is freed on driver
unbind.
> 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 0ae5f35e017c6..9373a52562242 100644
> --- a/drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c
> +++ b/drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c
> @@ -488,7 +488,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_kzalloc_objs(dev, isi->pipes[0],
> + isi->pdata->num_channels);
> if (!isi->pipes)
> return -ENOMEM;
[Severity: High]
This problem wasn't introduced by this patch, but can a failure in
mxc_isi_v4l2_init() leak registered video devices and leave them
referencing devm-freed isi->pipes memory [1]?
drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c:mxc_isi_v4l2_init() {
...
for (i = 0; i < isi->pdata->num_channels; ++i) {
struct mxc_isi_pipe *pipe = &isi->pipes[i];
ret = mxc_isi_pipe_register(pipe);
if (ret < 0) {
dev_err(isi->dev, "Failed to register pipe%u: %d\n", i,
ret);
goto err_v4l2;
}
...
err_m2m:
mxc_isi_m2m_unregister(isi);
v4l2_async_nf_cleanup(&isi->notifier);
err_v4l2:
v4l2_device_unregister(v4l2_dev);
err_media:
media_device_cleanup(media_dev);
return ret;
}
mxc_isi_pipe_register() calls mxc_isi_video_register(), which registers a
capture video_device node and initializes V4L2 control handlers and media
entity pads. If a later step in mxc_isi_v4l2_init() fails, err_v4l2 only
calls v4l2_device_unregister(), which unregisters subdevs but does not
call mxc_isi_pipe_unregister() on the already-registered pipes. With
isi->pipes now managed by devm, probe failure frees the pipes array while
those /dev/videoN nodes remain registered, leading to a use-after-free if
userspace accesses them.
[1] https://sashiko.dev/#/bug/linux-aae9d84d-1755-4279-8a12-ff366e28c228
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130022322.22508-1-laurent.pinchart@ideasonboard.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] media: nxp: imx8-isi: Fix small memory leak at unbind time
2026-11-30 2:23 [PATCH] media: nxp: imx8-isi: Fix small memory leak at unbind time Laurent Pinchart
2026-11-30 2:28 ` sashiko-bot
@ 2026-11-30 8:15 ` Paul Elder
2026-11-30 15:34 ` Frank Li
2 siblings, 0 replies; 4+ messages in thread
From: Paul Elder @ 2026-11-30 8:15 UTC (permalink / raw)
To: Laurent Pinchart, linux-media; +Cc: Frank Li, imx
Quoting Laurent Pinchart (2026-11-30 11:23:22)
> The probe() function dynamically allocates the pipes array with
> kzalloc_objs(), and doesn't free it at remove time. This results in a
> small memory leak. Use devm_kzalloc_objs() to fix it.
>
> Fixes: cf21f328fcaf ("media: nxp: Add i.MX8 ISI driver")
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
> ---
> Not Cc'ing stable as devm_kzalloc_objs() is too new (v7.4-rc1) so
> applying the patch on older kernels will fail. Manual backporting isn't
> worth it as the leak is small and triggered by driver unbind only.
> ---
> drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c | 3 ++-
> 1 file changed, 2 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 0ae5f35e017c..9373a5256224 100644
> --- a/drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c
> +++ b/drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c
> @@ -488,7 +488,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_kzalloc_objs(dev, isi->pipes[0],
> + isi->pdata->num_channels);
> if (!isi->pipes)
> return -ENOMEM;
>
>
> base-commit: fb8b2c10a588f1384b98280b1c32307da9db4747
> --
> Regards,
>
> Laurent Pinchart
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] media: nxp: imx8-isi: Fix small memory leak at unbind time
2026-11-30 2:23 [PATCH] media: nxp: imx8-isi: Fix small memory leak at unbind time Laurent Pinchart
2026-11-30 2:28 ` sashiko-bot
2026-11-30 8:15 ` Paul Elder
@ 2026-11-30 15:34 ` Frank Li
2 siblings, 0 replies; 4+ messages in thread
From: Frank Li @ 2026-11-30 15:34 UTC (permalink / raw)
To: Laurent Pinchart; +Cc: linux-media, Frank Li, imx
On Mon, Nov 30, 2026 at 11:23:22AM +0900, Laurent Pinchart wrote:
> The probe() function dynamically allocates the pipes array with
> kzalloc_objs(), and doesn't free it at remove time. This results in a
> small memory leak. Use devm_kzalloc_objs() to fix it.
>
> Fixes: cf21f328fcaf ("media: nxp: Add i.MX8 ISI driver")
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.com>
> Not Cc'ing stable as devm_kzalloc_objs() is too new (v7.4-rc1) so
> applying the patch on older kernels will fail. Manual backporting isn't
> worth it as the leak is small and triggered by driver unbind only.
> ---
> drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c | 3 ++-
> 1 file changed, 2 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 0ae5f35e017c..9373a5256224 100644
> --- a/drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c
> +++ b/drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c
> @@ -488,7 +488,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_kzalloc_objs(dev, isi->pipes[0],
> + isi->pdata->num_channels);
> if (!isi->pipes)
> return -ENOMEM;
>
>
> base-commit: fb8b2c10a588f1384b98280b1c32307da9db4747
> --
> Regards,
>
> Laurent Pinchart
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread