[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20190203112452.2784ef5b@bbrezillon>
Date: Sun, 3 Feb 2019 11:24:52 +0100
From: Boris Brezillon <bbrezillon@...nel.org>
To: wen yang <yellowriver2010@...mail.com>
Cc: "tudor.ambarus@...rochip.com" <tudor.ambarus@...rochip.com>,
"miquel.raynal@...tlin.com" <miquel.raynal@...tlin.com>,
"richard@....at" <richard@....at>,
"dwmw2@...radead.org" <dwmw2@...radead.org>,
"computersforpeace@...il.com" <computersforpeace@...il.com>,
"marek.vasut@...il.com" <marek.vasut@...il.com>,
"alexandre.belloni@...tlin.com" <alexandre.belloni@...tlin.com>,
"nicolas.ferre@...rochip.com" <nicolas.ferre@...rochip.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"ludovic.desroches@...rochip.com" <ludovic.desroches@...rochip.com>,
"linux-mtd@...ts.infradead.org" <linux-mtd@...ts.infradead.org>,
"linux-arm-kernel@...ts.infradead.org"
<linux-arm-kernel@...ts.infradead.org>
Subject: Re: [PATCH] mtd: nand: fix object reference leaks in
atmel_pmecc_get_by_node
On Sun, 3 Feb 2019 09:37:31 +0000
wen yang <yellowriver2010@...mail.com> wrote:
> 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.
>
> Signed-off-by: Wen Yang <yellowriver2010@...mail.com>
> Cc: Tudor Ambarus <tudor.ambarus@...rochip.com>
> Cc: Boris Brezillon <bbrezillon@...nel.org>
> Cc: Miquel Raynal <miquel.raynal@...tlin.com>
> Cc: Richard Weinberger <richard@....at>
> Cc: David Woodhouse <dwmw2@...radead.org>
> Cc: Brian Norris <computersforpeace@...il.com>
> Cc: Marek Vasut <marek.vasut@...il.com>
> Cc: Nicolas Ferre <nicolas.ferre@...rochip.com>
> Cc: Alexandre Belloni <alexandre.belloni@...tlin.com>
> Cc: Ludovic Desroches <ludovic.desroches@...rochip.com>
> Cc: linux-mtd@...ts.infradead.org
> Cc: linux-arm-kernel@...ts.infradead.org
> Cc: linux-kernel@...r.kernel.org
> ---
> drivers/mtd/nand/raw/atmel/pmecc.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mtd/nand/raw/atmel/pmecc.c b/drivers/mtd/nand/raw/atmel/pmecc.c
> index 555a74e..bee6551 100644
> --- a/drivers/mtd/nand/raw/atmel/pmecc.c
> +++ b/drivers/mtd/nand/raw/atmel/pmecc.c
> @@ -878,14 +878,17 @@ static struct atmel_pmecc *atmel_pmecc_get_by_node(struct device *userdev,
> struct atmel_pmecc *pmecc, **ptr;
>
> pdev = of_find_device_by_node(np);
> - if (!pdev || !platform_get_drvdata(pdev))
> + if (!pdev)
> return ERR_PTR(-EPROBE_DEFER);
> + if (!platform_get_drvdata(pdev)) {
> + put_device(&pdev->dev);
> + return ERR_PTR(-EPROBE_DEFER);
> + }
>
> ptr = devres_alloc(devm_atmel_pmecc_put, sizeof(*ptr), GFP_KERNEL);
> if (!ptr)
> return ERR_PTR(-ENOMEM);
You forgot to call put_device() here. I'd suggest adding an
err_put_device label which calls put_device() before returning
ERR_PTR(ret).
>
> - get_device(&pdev->dev);
> pmecc = platform_get_drvdata(pdev);
>
> *ptr = pmecc;
Powered by blists - more mailing lists