Thread (13 messages) 13 messages, 5 authors, 2026-03-26

Re: [PATCH] media: nxp: imx8-isi: remove kzalloc_objs

From: Rosen Penev <hidden>
Date: 2026-03-20 00:11:35
Also in: imx, linux-hardening, linux-media, lkml

On Thu, Mar 19, 2026 at 3:09 PM Laurent Pinchart
[off-list ref] wrote:
On Thu, Mar 05, 2026 at 08:45:36PM -0800, Rosen Penev wrote:
quoted
Use a flexible arraay member to combine allocations.

It looks like pipes never gets freed anywhere. Meaning this effectively
fixes a memory leak.

Signed-off-by: Rosen Penev <redacted>
---
 drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c | 11 ++++-------
 drivers/media/platform/nxp/imx8-isi/imx8-isi-core.h |  3 ++-
 2 files changed, 6 insertions(+), 8 deletions(-)
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 16392420903a..657ffecc4d7e 100644
--- a/drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c
+++ b/drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c
@@ -459,25 +459,21 @@ static const struct dev_pm_ops mxc_isi_pm_ops = {

 static int mxc_isi_probe(struct platform_device *pdev)
 {
+     const struct mxc_isi_plat_data *pdata;
      struct device *dev = &pdev->dev;
      struct mxc_isi_dev *isi;
      unsigned int dma_size;
      unsigned int i;
      int ret = 0;

-     isi = devm_kzalloc(dev, sizeof(*isi), GFP_KERNEL);
+     pdata = of_device_get_match_data(dev);
+     isi = devm_kzalloc(dev, struct_size(isi, pipes, pdata->num_channels), GFP_KERNEL);
      if (!isi)
              return -ENOMEM;

      isi->dev = dev;
      platform_set_drvdata(pdev, isi);

-     isi->pdata = of_device_get_match_data(dev);
I'd keep

        isi->pdata = pdata;

here and not below.
Sure
quoted
-
-     isi->pipes = kzalloc_objs(isi->pipes[0], isi->pdata->num_channels);
Wouldn't it be simpler to just replace this with devm_kcalloc() ?
That would only make sense if pipes remained a pointer. A flex array
member allows combining allocations since it doesn't take up extra
space.

Technically kzalloc_flex is simpler but I assume a devm version of
that will be handled in another treewide commit.
        isi->pipes = devm_kcalloc(dev, isi->pdata->num_channels,
                                  sizeof(isi->pipes[0]), GFP_KERNEL);

No other change would be needed.
With a flex array member, that's a compile time error, which I use as
a hint to complete the conversion.
quoted
-     if (!isi->pipes)
-             return -ENOMEM;
-
      isi->num_clks = devm_clk_bulk_get_all(dev, &isi->clks);
      if (isi->num_clks < 0)
              return dev_err_probe(dev, isi->num_clks, "Failed to get clocks\n");
@@ -487,6 +483,7 @@ static int mxc_isi_probe(struct platform_device *pdev)
              return dev_err_probe(dev, PTR_ERR(isi->regs),
                                   "Failed to get ISI register map\n");

+     isi->pdata = pdata;
      if (isi->pdata->gasket_ops) {
              isi->gasket = syscon_regmap_lookup_by_phandle(dev->of_node,
                                                            "fsl,blk-ctrl");
diff --git a/drivers/media/platform/nxp/imx8-isi/imx8-isi-core.h b/drivers/media/platform/nxp/imx8-isi/imx8-isi-core.h
index 3cbd35305af0..99532efa4e41 100644
--- a/drivers/media/platform/nxp/imx8-isi/imx8-isi-core.h
+++ b/drivers/media/platform/nxp/imx8-isi/imx8-isi-core.h
@@ -286,7 +286,6 @@ struct mxc_isi_dev {
      struct regmap                   *gasket;

      struct mxc_isi_crossbar         crossbar;
-     struct mxc_isi_pipe             *pipes;
      struct mxc_isi_m2m              m2m;

      struct media_device             media_dev;
@@ -294,6 +293,8 @@ struct mxc_isi_dev {
      struct v4l2_async_notifier      notifier;

      struct dentry                   *debugfs_root;
+
+     struct mxc_isi_pipe             pipes[];
 };

 extern const struct mxc_gasket_ops mxc_imx8_gasket_ops;
--
Regards,

Laurent Pinchart
  
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help