Skip to content

Commit 7bb7d69

Browse files
jhovoldvinodkoul
authored andcommitted
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: db7d07b ("dmaengine: add driver for Sophgo CV18XX/SG200X dmamux") Cc: stable@vger.kernel.org # 6.17 Cc: Inochi Amaoto <inochiama@gmail.com> Signed-off-by: Johan Hovold <johan@kernel.org> Link: https://patch.msgid.link/20251117161258.10679-5-johan@kernel.org Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent 7c3a46e commit 7bb7d69

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

drivers/dma/cv1800b-dmamux.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ static void *cv1800_dmamux_route_allocate(struct of_phandle_args *dma_spec,
102102
struct llist_node *node;
103103
unsigned long flags;
104104
unsigned int chid, devid, cpuid;
105-
int ret;
105+
int ret = -EINVAL;
106106

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

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

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

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

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

132132
spin_lock_irqsave(&dmamux->lock, flags);
@@ -136,8 +136,6 @@ static void *cv1800_dmamux_route_allocate(struct of_phandle_args *dma_spec,
136136
if (map->peripheral == devid && map->cpu == cpuid)
137137
goto found;
138138
}
139-
140-
ret = -EINVAL;
141139
goto failed;
142140
} else {
143141
node = llist_del_first(&dmamux->free_maps);
@@ -171,12 +169,17 @@ static void *cv1800_dmamux_route_allocate(struct of_phandle_args *dma_spec,
171169
dev_dbg(&pdev->dev, "register channel %u for req %u (cpu %u)\n",
172170
chid, devid, cpuid);
173171

172+
put_device(&pdev->dev);
173+
174174
return map;
175175

176176
failed:
177177
spin_unlock_irqrestore(&dmamux->lock, flags);
178178
of_node_put(dma_spec->np);
179179
dev_err(&pdev->dev, "errno %d\n", ret);
180+
err_put_pdev:
181+
put_device(&pdev->dev);
182+
180183
return ERR_PTR(ret);
181184
}
182185

0 commit comments

Comments
 (0)