Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp5236777ima; Tue, 5 Feb 2019 08:27:04 -0800 (PST) X-Google-Smtp-Source: AHgI3IbAqyDiOha08YJAffFYvE2u3V9CnRjecsRYdd81FgKosTmnFdbGC1baNJxPdZuCvNLiyJyn X-Received: by 2002:a17:902:d70b:: with SMTP id w11mr6017619ply.294.1549384023945; Tue, 05 Feb 2019 08:27:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549384023; cv=none; d=google.com; s=arc-20160816; b=DPhagRMttfkSA8aGdzM5DEFTygCmLRa67wX4bENnt1aig3z7PeMK9FDYA+DXfoTxag KvqxOYzP3LX61eeH305VJSiuJjwoEI1KTf/L+D59fSbLHaE0wCcAdfqcUl+k9eV5XcmK 6zz7broFMJhEi3f4WgYA8TuFjRzvin/1cEBbRLLPKanZGoCMAxLYSoIKinssuVP3LJVz n86DpuL2uxHkGQM16im/vFp3xv7MOa/FOUTaIqgcyqeqKJJNpTr29YzNSFjEz13JzIcH +OuyuSSy9UUAnzkMiAJtTVJeZY5UAR6x1TrrlMljgpaZCGLEOa4Hhz3lGgP9/Omy5j5V mzmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=gZnjSyk7tiBSycTx+uRpZK4KHMX1V/vgm3FdtGKeWMI=; b=BtJ/m5qBOf0Okw0453G+Dcjh4ppV1003VQ3C5eVoWcvXvjpxCiJdEJt/YauOf7uFNy 79028KzHaxvffFTPwJXekM1OUt6I1wjojpL52OBH/oDStHG+DANMS91S1ZBrPPHHwAGg 0b9biV76s2j4rjyxA8xw1vH7M4nOkalJEOTpM/bK9Fvs3jAw2GF/PSrfcttGwPHYcDoK fDxIGLYw6ktLT2G9G4Lh0mUpO6xbKB+HSw6SO8WbD/K+5aFQoxf01RLmwcvmqJJuoi4S jCKm10gkBTIbXZRde36mr7iJ4bsD2nx43dqR+FgHfRGEZTcqpgIq9YOTtBex2LJdkoIj 0TTA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r2si3414915pgk.389.2019.02.05.08.26.47; Tue, 05 Feb 2019 08:27:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728155AbfBEPzI convert rfc822-to-8bit (ORCPT + 99 others); Tue, 5 Feb 2019 10:55:08 -0500 Received: from relay12.mail.gandi.net ([217.70.178.232]:42277 "EHLO relay12.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726550AbfBEPzI (ORCPT ); Tue, 5 Feb 2019 10:55:08 -0500 Received: from xps13 (aaubervilliers-681-1-80-177.w90-88.abo.wanadoo.fr [90.88.22.177]) (Authenticated sender: miquel.raynal@bootlin.com) by relay12.mail.gandi.net (Postfix) with ESMTPSA id 634AA200014; Tue, 5 Feb 2019 15:55:04 +0000 (UTC) Date: Tue, 5 Feb 2019 16:55:02 +0100 From: Miquel Raynal To: Wen Yang Cc: "harveyhuntnexus@gmail.com" , "bbrezillon@kernel.org" , "richard@nod.at" , "dwmw2@infradead.org" , "computersforpeace@gmail.com" , "marek.vasut@gmail.com" , "nicolas.ferre@microchip.com" , "alexandre.belloni@bootlin.com" , "ludovic.desroches@microchip.com" , "linux-mtd@lists.infradead.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v2] mtd: rawnand: jz4780: fix possible object reference leak Message-ID: <20190205165502.2b8be890@xps13> In-Reply-To: References: Organization: Bootlin X-Mailer: Claws Mail 3.17.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Wen, Wen Yang wrote on Tue, 5 Feb 2019 15:07:21 +0000: > 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: ae02ab00aa3c ("mtd: nand: jz4780: driver for NAND devices on JZ4780 SoCs") > Signed-off-by: Wen Yang > Suggested-by: Miquel Raynal > Cc: Harvey Hunt > Cc: Boris Brezillon > Cc: Miquel Raynal > Cc: Richard Weinberger > Cc: David Woodhouse > Cc: Brian Norris > Cc: Marek Vasut > Cc: linux-mtd@lists.infradead.org > Cc: linux-kernel@vger.kernel.org > --- > v2->v1: Since there is the only one user, let's remove the err_put_device label. > > drivers/mtd/nand/raw/jz4780_bch.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/drivers/mtd/nand/raw/jz4780_bch.c b/drivers/mtd/nand/raw/jz4780_bch.c > index 7201827..363465c 100644 > --- a/drivers/mtd/nand/raw/jz4780_bch.c > +++ b/drivers/mtd/nand/raw/jz4780_bch.c > @@ -281,10 +281,12 @@ static struct jz4780_bch *jz4780_bch_get(struct device_node *np) > struct jz4780_bch *bch; > > pdev = of_find_device_by_node(np); > - if (!pdev || !platform_get_drvdata(pdev)) > + if (!pdev) > return ERR_PTR(-EPROBE_DEFER); > - > - get_device(&pdev->dev); > + if (!platform_get_drvdata(pdev)) { > + put_device(&pdev->dev); > + return ERR_PTR(-EPROBE_DEFER); > + } > > bch = platform_get_drvdata(pdev); > clk_prepare_enable(bch->clk); Acked-by: Miquel Raynal Thanks, Miquèl