Skip to content

Commit 812feb9

Browse files
tasksetambarus
authored andcommitted
mtd: rawnand: atmel: fix possible object reference leak
of_find_device_by_node() takes a reference to the struct device when it finds a match via get_device, there is no need to call get_device() twice. We also should make sure to drop the reference to the device taken by of_find_device_by_node() on driver unbind. Fixes: f88fc12 ("mtd: nand: Cleanup/rework the atmel_nand driver") Signed-off-by: Wen Yang <yellowriver2010@hotmail.com> Suggested-by: Boris Brezillon <bbrezillon@kernel.org> Reviewed-by: Boris Brezillon <bbrezillon@kernel.org> Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com> Acked-by: Miquel Raynal <miquel.raynal@bootlin.com> Cc: Tudor Ambarus <tudor.ambarus@microchip.com> Cc: Boris Brezillon <bbrezillon@kernel.org> Cc: Miquel Raynal <miquel.raynal@bootlin.com> Cc: Richard Weinberger <richard@nod.at> Cc: David Woodhouse <dwmw2@infradead.org> Cc: Brian Norris <computersforpeace@gmail.com> Cc: Marek Vasut <marek.vasut@gmail.com> Cc: Nicolas Ferre <nicolas.ferre@microchip.com> Cc: Alexandre Belloni <alexandre.belloni@bootlin.com> Cc: Ludovic Desroches <ludovic.desroches@microchip.com> Cc: linux-mtd@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> (cherry picked from commit a12085d) Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
1 parent 7990018 commit 812feb9

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

drivers/mtd/nand/raw/atmel/pmecc.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -870,23 +870,32 @@ static struct atmel_pmecc *atmel_pmecc_get_by_node(struct device *userdev,
870870
{
871871
struct platform_device *pdev;
872872
struct atmel_pmecc *pmecc, **ptr;
873+
int ret;
873874

874875
pdev = of_find_device_by_node(np);
875-
if (!pdev || !platform_get_drvdata(pdev))
876+
if (!pdev)
876877
return ERR_PTR(-EPROBE_DEFER);
878+
pmecc = platform_get_drvdata(pdev);
879+
if (!pmecc) {
880+
ret = -EPROBE_DEFER;
881+
goto err_put_device;
882+
}
877883

878884
ptr = devres_alloc(devm_atmel_pmecc_put, sizeof(*ptr), GFP_KERNEL);
879-
if (!ptr)
880-
return ERR_PTR(-ENOMEM);
881-
882-
get_device(&pdev->dev);
883-
pmecc = platform_get_drvdata(pdev);
885+
if (!ptr) {
886+
ret = -ENOMEM;
887+
goto err_put_device;
888+
}
884889

885890
*ptr = pmecc;
886891

887892
devres_add(userdev, ptr);
888893

889894
return pmecc;
895+
896+
err_put_device:
897+
put_device(&pdev->dev);
898+
return ERR_PTR(ret);
890899
}
891900

892901
static const int atmel_pmecc_strengths[] = { 2, 4, 8, 12, 24, 32 };

0 commit comments

Comments
 (0)