]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
dmaengine: sh: rz-dmac: fix device leak on probe failure
authorJohan Hovold <johan@kernel.org>
Mon, 17 Nov 2025 16:12:51 +0000 (17:12 +0100)
committerVinod Koul <vkoul@kernel.org>
Sun, 14 Dec 2025 09:17:24 +0000 (14:47 +0530)
Make sure to drop the reference taken when looking up the ICU device
during probe also on probe failures (e.g. probe deferral).

Fixes: 7de873201c44 ("dmaengine: sh: rz-dmac: Add RZ/V2H(P) support")
Cc: stable@vger.kernel.org # 6.16
Cc: Fabrizio Castro <fabrizio.castro.jz@renesas.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
Reviewed-by: Fabrizio Castro <fabrizio.castro.jz@renesas.com>
Link: https://patch.msgid.link/20251117161258.10679-10-johan@kernel.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/dma/sh/rz-dmac.c

index 1f687b08d6b8677d9300b5c7274559bfc9574643..38137e8d80b9f5ace716ccbc5c98116a9005a829 100644 (file)
@@ -854,6 +854,13 @@ static int rz_dmac_chan_probe(struct rz_dmac *dmac,
        return 0;
 }
 
+static void rz_dmac_put_device(void *_dev)
+{
+       struct device *dev = _dev;
+
+       put_device(dev);
+}
+
 static int rz_dmac_parse_of_icu(struct device *dev, struct rz_dmac *dmac)
 {
        struct device_node *np = dev->of_node;
@@ -876,6 +883,10 @@ static int rz_dmac_parse_of_icu(struct device *dev, struct rz_dmac *dmac)
                return -ENODEV;
        }
 
+       ret = devm_add_action_or_reset(dev, rz_dmac_put_device, &dmac->icu.pdev->dev);
+       if (ret)
+               return ret;
+
        dmac_index = args.args[0];
        if (dmac_index > RZV2H_MAX_DMAC_INDEX) {
                dev_err(dev, "DMAC index %u invalid.\n", dmac_index);
@@ -1055,8 +1066,6 @@ static void rz_dmac_remove(struct platform_device *pdev)
        reset_control_assert(dmac->rstc);
        pm_runtime_put(&pdev->dev);
        pm_runtime_disable(&pdev->dev);
-
-       platform_device_put(dmac->icu.pdev);
 }
 
 static const struct of_device_id of_rz_dmac_match[] = {