Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp2574422ima; Sun, 3 Feb 2019 02:26:47 -0800 (PST) X-Google-Smtp-Source: AHgI3IZHq4gKJU8ZXQllAc7eIkl4YUEpOR20hysnfvtTS1uohQEswmOPGtunZAKVpsd4QyZZonvL X-Received: by 2002:a63:2744:: with SMTP id n65mr8997863pgn.65.1549189607544; Sun, 03 Feb 2019 02:26:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549189607; cv=none; d=google.com; s=arc-20160816; b=BU0KJI79ixJTxiI2EIg+aAoxPPzuvR/E58Y4CSooSJbOPN0+OtUAPm2e7u/joVgqT9 uhFpZHsX9HNTsN9GkCVcsRtxXZXidxhcYrp5wEwGu7AQOtioBI2BjiAyXzf5IgRecKbx +egOsQQUTU1mgjyv1tYBJdePuUzPfGeFskWmTSd+Axt0ZXkNc0JvL6TvBP5txHw1PXBx Y5Ks54kyHp3LmtKSt+QsmucEQBtAThSK1sBOqGEsN25IwaQu9/6MK6cIWjn/38p/A0+9 bMum4InpYQ9CYRwQzhkdxMAmQ0rrlx/Ecr8MDaW/MDzD7L4scMHkZNiVbZ4iDObIjHvR HNYQ== 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=kXPAvrQsmVi8jd/ZLbhNB7ahNIlO1H90+78F0ox4tw4=; b=lOj+8XB42aZgspGxdxiU/DUEZc1p1zospFG1/SrieIO4EBWhOKKV1MoFfQ0svFHRcc 0MIdVR/aqBlGHg5HuOyLMlmnIuqAicH+kB05W7uoU3G9I+eekylJ1G8HCX2O1yPqhm4E z9ysDStK5Bba6pipfFk7CLKD+a3aVqix9Sz7aQeonYhX9/UxSMrs7cm0iWNKB6WXJrT7 +D6lo47hCocg7Mvi7VjuQ15JOWTovWeUeYjy2P+uHIl/JISBLH77S8FWe361N5w38en+ Vl18hSuSx3l2Vf/ugeuJJcKFyoIvK0OHRW+OPFUpWh1nBjcCI0ixvXn/0FqIs6eIgzkY KTHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="k/cVNsSY"; 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 m39si12569343plg.315.2019.02.03.02.26.32; Sun, 03 Feb 2019 02:26:47 -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="k/cVNsSY"; 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 S1727694AbfBCKZp (ORCPT + 99 others); Sun, 3 Feb 2019 05:25:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:39960 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727586AbfBCKZo (ORCPT ); Sun, 3 Feb 2019 05:25:44 -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 8258920855; Sun, 3 Feb 2019 10:25:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549189543; bh=SjK88TvLdzOJBa9K/8vtx9sSV/IoeN/fyPFyvUXlTU4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=k/cVNsSYxiIvsUdzT/F34wCUabYYexl9v6FYmerncKRFQ+OtdjCykp2Z/r3POpKgG RmP6ICJynQkvCJe6bu+APAupWXUdznrCMk69BGnpX6H9D8B24vF0zrcwWb3pPPYCD6 0xghyzeqwmLfF9tdu5tb3xHjf/ly/pylo+SdrcHk= Date: Sun, 3 Feb 2019 11:25:31 +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: <20190203112531.080c15a7@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. > Missing Fixes tag. > 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); > > - get_device(&pdev->dev); > pmecc = platform_get_drvdata(pdev); > > *ptr = pmecc;