Skip to content

Commit fecbd4a

Browse files
Conchy-Conchymiquelraynal
authored andcommitted
mtd: rawnand: atmel: fix refcount issue in atmel_nand_controller_init
The reference counting issue happens in several error handling paths on a refcounted object "nc->dmac". In these paths, the function simply returns the error code, forgetting to balance the reference count of "nc->dmac", increased earlier by dma_request_channel(), which may cause refcount leaks. Fix it by decrementing the refcount of specific object in those error paths. Fixes: f88fc12 ("mtd: nand: Cleanup/rework the atmel_nand driver") Co-developed-by: Xiyu Yang <xiyuyang19@fudan.edu.cn> Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn> Co-developed-by: Xin Tan <tanxin.ctf@gmail.com> Signed-off-by: Xin Tan <tanxin.ctf@gmail.com> Signed-off-by: Xin Xiong <xiongx18@fudan.edu.cn> Reviewed-by: Claudiu Beznea <claudiu.beznea@microchip.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://lore.kernel.org/linux-mtd/20220304085330.3610-1-xiongx18@fudan.edu.cn
1 parent fba6eb4 commit fecbd4a

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

drivers/mtd/nand/raw/atmel/nand-controller.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,24 +2060,32 @@ static int atmel_nand_controller_init(struct atmel_nand_controller *nc,
20602060
nc->mck = of_clk_get(dev->parent->of_node, 0);
20612061
if (IS_ERR(nc->mck)) {
20622062
dev_err(dev, "Failed to retrieve MCK clk\n");
2063-
return PTR_ERR(nc->mck);
2063+
ret = PTR_ERR(nc->mck);
2064+
goto out_release_dma;
20642065
}
20652066

20662067
np = of_parse_phandle(dev->parent->of_node, "atmel,smc", 0);
20672068
if (!np) {
20682069
dev_err(dev, "Missing or invalid atmel,smc property\n");
2069-
return -EINVAL;
2070+
ret = -EINVAL;
2071+
goto out_release_dma;
20702072
}
20712073

20722074
nc->smc = syscon_node_to_regmap(np);
20732075
of_node_put(np);
20742076
if (IS_ERR(nc->smc)) {
20752077
ret = PTR_ERR(nc->smc);
20762078
dev_err(dev, "Could not get SMC regmap (err = %d)\n", ret);
2077-
return ret;
2079+
goto out_release_dma;
20782080
}
20792081

20802082
return 0;
2083+
2084+
out_release_dma:
2085+
if (nc->dmac)
2086+
dma_release_channel(nc->dmac);
2087+
2088+
return ret;
20812089
}
20822090

20832091
static int

0 commit comments

Comments
 (0)