Commit 7bb7d696 authored by Johan Hovold's avatar Johan Hovold Committed by Vinod Koul
Browse files

dmaengine: cv1800b-dmamux: fix device leak on route allocation



Make sure to drop the reference taken when looking up the DMA mux
platform device during route allocation.

Note that holding a reference to a device does not prevent its driver
data from going away so there is no point in keeping the reference.

Fixes: db7d07b5 ("dmaengine: add driver for Sophgo CV18XX/SG200X dmamux")
Cc: stable@vger.kernel.org	# 6.17
Cc: Inochi Amaoto <inochiama@gmail.com>
Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
Link: https://patch.msgid.link/20251117161258.10679-5-johan@kernel.org


Signed-off-by: default avatarVinod Koul <vkoul@kernel.org>
parent 7c3a46eb
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -102,11 +102,11 @@ static void *cv1800_dmamux_route_allocate(struct of_phandle_args *dma_spec,
	struct llist_node *node;
	unsigned long flags;
	unsigned int chid, devid, cpuid;
	int ret;
	int ret = -EINVAL;

	if (dma_spec->args_count != DMAMUX_NCELLS) {
		dev_err(&pdev->dev, "invalid number of dma mux args\n");
		return ERR_PTR(-EINVAL);
		goto err_put_pdev;
	}

	devid = dma_spec->args[0];
@@ -115,18 +115,18 @@ static void *cv1800_dmamux_route_allocate(struct of_phandle_args *dma_spec,

	if (devid > MAX_DMA_MAPPING_ID) {
		dev_err(&pdev->dev, "invalid device id: %u\n", devid);
		return ERR_PTR(-EINVAL);
		goto err_put_pdev;
	}

	if (cpuid > MAX_DMA_CPU_ID) {
		dev_err(&pdev->dev, "invalid cpu id: %u\n", cpuid);
		return ERR_PTR(-EINVAL);
		goto err_put_pdev;
	}

	dma_spec->np = of_parse_phandle(ofdma->of_node, "dma-masters", 0);
	if (!dma_spec->np) {
		dev_err(&pdev->dev, "can't get dma master\n");
		return ERR_PTR(-EINVAL);
		goto err_put_pdev;
	}

	spin_lock_irqsave(&dmamux->lock, flags);
@@ -136,8 +136,6 @@ static void *cv1800_dmamux_route_allocate(struct of_phandle_args *dma_spec,
			if (map->peripheral == devid && map->cpu == cpuid)
				goto found;
		}

		ret = -EINVAL;
		goto failed;
	} else {
		node = llist_del_first(&dmamux->free_maps);
@@ -171,12 +169,17 @@ static void *cv1800_dmamux_route_allocate(struct of_phandle_args *dma_spec,
	dev_dbg(&pdev->dev, "register channel %u for req %u (cpu %u)\n",
		chid, devid, cpuid);

	put_device(&pdev->dev);

	return map;

failed:
	spin_unlock_irqrestore(&dmamux->lock, flags);
	of_node_put(dma_spec->np);
	dev_err(&pdev->dev, "errno %d\n", ret);
err_put_pdev:
	put_device(&pdev->dev);

	return ERR_PTR(ret);
}