Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp2574203ima; Sun, 3 Feb 2019 02:26:27 -0800 (PST) X-Google-Smtp-Source: AHgI3IZYNDUW/XEvYlYHIC5bVCl+hwgtHJBLkJ2PgilxoVKbzGfdf1RO3ZCIsD6ekrpz7Fy9z1xP X-Received: by 2002:a63:7044:: with SMTP id a4mr8850654pgn.359.1549189587070; Sun, 03 Feb 2019 02:26:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549189587; cv=none; d=google.com; s=arc-20160816; b=sHey2jcYncmRXRaJJTJPBXxBrZgdGWsgcLcREPcjT6rUxLWLSTSdiSb9y6pEt+KdHY wGpPvY7MvIAnct7NqxCKGSWWYoDZRdnFjidW5/LBlIKM0rBRLgdd7QS12IVN7AsD4T5v o9GJh+DT6Cme76JwE0ijEdbjCv5xWkNrug2KWt6TBmjpgAl0chdx4z3hgA6ByGC5XbUl ImqTG4HTmZd33KI7QPitnDHBz3dmk7HWvNo0CjBdWG0zsebyqihTEI6dW07MQTS5asy1 RPwzdoCB0m+QwOgL2ovCTLIkkE3ebIs5rVCu2ONPOU0jkZAlhW8Ho6u3mqcKuLW+r2XY ZC+g== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=R395RQfm4922fjXgTnZWqr5idVAFJUGf6Auf0q5dO1o=; b=Pr8GamQQbo9VWeJuajhF7gfMVzp4YDBfP75el4gJd2w1p9Jg7tyZaAakCj17ZvDTqm QdlRXYdjSgBDNiWfw19gAw1jrUbvgmuw9zK26is/Wt5DbnS/EUTDKErEPJY8rZ3c0n8S ovuoLWMFBXmmmeX5wwefEk9RUpVStGcz1F/uAnvBt98N70dv8eFktihzgJXATA82NJl2 Ctx7KBFuLwTcXYBXqs86EFzebitGBlwwhuBSJFBgMq4rCCVak5OozZILOc+CIBn0glbY C+LqawnimoJfbh2Bnj2NjcXdj72bVjWLB8BNBMezXf21+Q2f57MgjL+ntwA78TEwG6R2 io+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fxfEwvgS; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n2si12333025pgr.67.2019.02.03.02.25.57; Sun, 03 Feb 2019 02:26:27 -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; dkim=pass header.i=@kernel.org header.s=default header.b=fxfEwvgS; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727583AbfBCKZE (ORCPT + 99 others); Sun, 3 Feb 2019 05:25:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:39750 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727029AbfBCKZE (ORCPT ); Sun, 3 Feb 2019 05:25:04 -0500 Received: from bbrezillon (91-160-177-164.subs.proxad.net [91.160.177.164]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 987EF20855; Sun, 3 Feb 2019 10:24:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549189503; bh=OlPivz3jh9XIX9845oGVBQc9wnYVWskV0PrC7azoYAo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=fxfEwvgStMGlo8q/+lMybtJmsyDXcqC4XF5h645rkmOCdUi/PCdGxGcbblKZ4Bpci Z/JLcqLc8kf5YCqDad2hYQvwhr3bmZxQXPWc7/i4/Xr60lHSEqdHYSIkt8A1l/57Ln e4EVIC99xzkEgvncFLk+plGFhoeCVvUClhVI3VRE= Date: Sun, 3 Feb 2019 11:24:52 +0100 From: Boris Brezillon To: wen yang Cc: "tudor.ambarus@microchip.com" , "miquel.raynal@bootlin.com" , "richard@nod.at" , "dwmw2@infradead.org" , "computersforpeace@gmail.com" , "marek.vasut@gmail.com" , "alexandre.belloni@bootlin.com" , "nicolas.ferre@microchip.com" , "linux-kernel@vger.kernel.org" , "ludovic.desroches@microchip.com" , "linux-mtd@lists.infradead.org" , "linux-arm-kernel@lists.infradead.org" Subject: Re: [PATCH] mtd: nand: fix object reference leaks in atmel_pmecc_get_by_node Message-ID: <20190203112452.2784ef5b@bbrezillon> In-Reply-To: References: X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 3 Feb 2019 09:37:31 +0000 wen yang 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 > Cc: Tudor Ambarus > Cc: Boris Brezillon > Cc: Miquel Raynal > Cc: Richard Weinberger > Cc: David Woodhouse > Cc: Brian Norris > Cc: Marek Vasut > Cc: Nicolas Ferre > Cc: Alexandre Belloni > Cc: Ludovic Desroches > Cc: linux-mtd@lists.infradead.org > Cc: linux-arm-kernel@lists.infradead.org > Cc: linux-kernel@vger.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;