Skip to contentSkip to conversation

media: nxp: imx8-isi: remove kzalloc_objs

PATCH New Rosen Penev 1 participant 1 message Mar 20

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 media: nxp: imx8-isi: remove kzalloc_objs

Use a flexible array member to combine allocations.

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

Fixes cf21f328fcaf ("media: nxp: Add i.MX8 ISI driver")

---
v2: add fixes tag, fix typo, and move pdata assignment to original place.

 drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c | 10 ++++------
 drivers/media/platform/nxp/imx8-isi/imx8-isi-core.h |  3 ++-
 2 files changed, 6 insertions(+), 7 deletions(-)
drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c +4 -6
index 16392420903a..8d8ee1b3076b 100644
@@ -459,24 +459,22 @@ 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);
-
-	isi->pipes = kzalloc_objs(isi->pipes[0], isi->pdata->num_channels);
-	if (!isi->pipes)
-		return -ENOMEM;
+	isi->pdata = pdata;
 
 	isi->num_clks = devm_clk_bulk_get_all(dev, &isi->clks);
 	if (isi->num_clks < 0)
drivers/media/platform/nxp/imx8-isi/imx8-isi-core.h +2 -1
index 3cbd35305af0..99532efa4e41 100644
@@ -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;

--
2.53.0