Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5646942imm; Mon, 27 Aug 2018 01:30:34 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZPorgNlX0I+74GmwPeJsu5ja/8sKMe8vue3VG5qO+PEObJRj6eK+XmTpai6wie/+bQEvVu X-Received: by 2002:aa7:82c3:: with SMTP id f3-v6mr13520147pfn.136.1535358634698; Mon, 27 Aug 2018 01:30:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535358634; cv=none; d=google.com; s=arc-20160816; b=eZIVuCNx48ntNfWkUvysw9CIMxSf3qxgMr51Ue7tXiu2SIp66sEynSAnsZ4pHbQn0B jZJ4Uydc14xrppcvdd3E5ebQUeaTB0V6p8FANKOweqU9coIaDbG9uicHdjrCSxI8+94K Ltn7AkN47uvBhCvhiJbRXUcM308Gvzzrgox5YaRamaikKISD8+te1tcxRMT7OBfVtUln GVtavpJeXG3S/9K7h064fUzkl+KWUvsXQlRnE5J+1LDFX8aqIiKBHMA79l0fc5jecuII hPFgJyGYUCFo0tUF2Yf1ZjasimbpTfJdZROnpFc/Pz5FUmJMKKslfLl7cms3BTytuCT7 speQ== 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 :arc-authentication-results; bh=a3FjxLY26JsZ4rlveVqm6tXazAjrE68n+lm/zwca5GA=; b=KL0FHyqqFKodxZufGWQjRR+KpXmN3hR/NJl6jBj38fbKQ3WEkipw7lgDVrsonmwttF ue9O+ingsn/qRIQk1WbWN7w+XL1LeMFVMUHo5VX22I0pBA/ccwhZfoOh5Lte3wVqhymp 3A3gQBLtgbEubB0dHVm1/4YUlOx7Uph+7u5tsR9+Yuk5BcYfXhccRqFWJFFBNJaKDgn0 YtoRYgfHLSsvo5hEm3EHuQmMXmLX2m4aD1dR+Acxiz9+3xE1iKbrT90tcueIgOiq3bRl w7gLjy5TaNB3Cwk42hqfrsr+i2Vw3AUO5wMAb5NWvjKmGtR+JNMbd5vUNG1US0+X+OZe hOaQ== 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 g34-v6si10706986pgm.31.2018.08.27.01.30.19; Mon, 27 Aug 2018 01:30:34 -0700 (PDT) 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 S1727144AbeH0MOe (ORCPT + 99 others); Mon, 27 Aug 2018 08:14:34 -0400 Received: from mail.bootlin.com ([62.4.15.54]:60568 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726802AbeH0MOe (ORCPT ); Mon, 27 Aug 2018 08:14:34 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id B40BA20799; Mon, 27 Aug 2018 10:28:55 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (AAubervilliers-681-1-53-19.w90-88.abo.wanadoo.fr [90.88.170.19]) by mail.bootlin.com (Postfix) with ESMTPSA id 2211622A3C; Mon, 27 Aug 2018 10:28:22 +0200 (CEST) Date: Mon, 27 Aug 2018 10:28:20 +0200 From: Boris Brezillon To: Johan Hovold Cc: Rob Herring , Greg Kroah-Hartman , Frank Rowand , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, stable , Nicolas Ferre , Josh Wu Subject: Re: [PATCH v2 5/9] mtd: nand: atmel: fix OF child-node lookup Message-ID: <20180827102820.3abf7291@bbrezillon> In-Reply-To: <20180827082153.22537-6-johan@kernel.org> References: <20180827082153.22537-1-johan@kernel.org> <20180827082153.22537-6-johan@kernel.org> X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; 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 Hi Johan On Mon, 27 Aug 2018 10:21:49 +0200 Johan Hovold wrote: > Use the new of_get_compatible_child() helper to lookup the nfc child > node instead of using of_find_compatible_node(), which searches the > entire tree from a given start node and thus can return an unrelated > (i.e. non-child) node. > > This also addresses a potential use-after-free (e.g. after probe > deferral) as the tree-wide helper drops a reference to its first > argument (i.e. the node of the device being probed). > > While at it, also fix a related nfc-node reference leak. > > Fixes: f88fc122cc34 ("mtd: nand: Cleanup/rework the atmel_nand driver") > Cc: stable # 4.11 > Cc: Nicolas Ferre > Cc: Josh Wu > Cc: Boris Brezillon > Signed-off-by: Johan Hovold Acked-by: Boris Brezillon I'll let Miquel queue this patch to the nand/next branch, unless you want it to be merged in 4.19, in which case I'll queue it to the mtd/fixes branch. Thanks, Boris > --- > drivers/mtd/nand/raw/atmel/nand-controller.c | 11 +++++++---- > 1 file changed, 7 insertions(+), 4 deletions(-) > > diff --git a/drivers/mtd/nand/raw/atmel/nand-controller.c b/drivers/mtd/nand/raw/atmel/nand-controller.c > index a068b214ebaa..d3dfe63956ac 100644 > --- a/drivers/mtd/nand/raw/atmel/nand-controller.c > +++ b/drivers/mtd/nand/raw/atmel/nand-controller.c > @@ -2061,8 +2061,7 @@ atmel_hsmc_nand_controller_legacy_init(struct atmel_hsmc_nand_controller *nc) > int ret; > > nand_np = dev->of_node; > - nfc_np = of_find_compatible_node(dev->of_node, NULL, > - "atmel,sama5d3-nfc"); > + nfc_np = of_get_compatible_child(dev->of_node, "atmel,sama5d3-nfc"); > > nc->clk = of_clk_get(nfc_np, 0); > if (IS_ERR(nc->clk)) { > @@ -2472,15 +2471,19 @@ static int atmel_nand_controller_probe(struct platform_device *pdev) > } > > if (caps->legacy_of_bindings) { > + struct device_node *nfc_node; > u32 ale_offs = 21; > > /* > * If we are parsing legacy DT props and the DT contains a > * valid NFC node, forward the request to the sama5 logic. > */ > - if (of_find_compatible_node(pdev->dev.of_node, NULL, > - "atmel,sama5d3-nfc")) > + nfc_node = of_get_compatible_child(pdev->dev.of_node, > + "atmel,sama5d3-nfc"); > + if (nfc_node) { > caps = &atmel_sama5_nand_caps; > + of_node_put(nfc_node); > + } > > /* > * Even if the compatible says we are dealing with an