Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2551812imu; Thu, 29 Nov 2018 06:47:09 -0800 (PST) X-Google-Smtp-Source: AFSGD/W8C7YeXMHNxeojzXkeqIGbGUioxAKUnp+4z+7DtKJr/Qq6NUCOwXpH91qZ4I4YjrOhKA2N X-Received: by 2002:a17:902:162:: with SMTP id 89-v6mr1718026plb.293.1543502829275; Thu, 29 Nov 2018 06:47:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543502829; cv=none; d=google.com; s=arc-20160816; b=qna1g6IkbwlaSxLzA/M7bnL5aoAH1mtt0AhrWuzkywlubbJYBl+urKjiHN2M23DhZD jiHMSZfAgEQG+33rHebIYXCBu37EoGSRf7qHZYXVTyh+9vpbFhCZbh4yrY7OBoYKp3A4 UGIqViEFsxr0poER617SR59HQWgWgw/r+bItnTVH4BnMaY+yudkAC4ouD9wG2j0Pt55b EH7hzdIzvswbQov4MZAG2ScxOsWEtggSLgGeLNePnXwAEDe4/jQekdReCLmk2Rv/OwZL unRSIMAlN4Ax3reKzVdIKrXesh9+Bb1aSv1Jolhue4Ms8xnLZNrQdCaRcgtg5Ttk+obY /H8w== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bFgBzmnIKVX6cQN3Hs4lbayK8w2uITZABQ02jubw83Q=; b=d1b+p5qrErUjyTovMo1YllTb+5RMoqfm0ftH9sR9i+WN6vLz6kEDQBt8oPdKcaGPMH tgeXjMw3W6vysKdU0TSPcQZIqASbtq1obZAKZEUVlp+qbeWYWQk/N+M8d4Rbt972pXKO KXfK/DOldZywE9nGvT3sd/j5FjoJq490iOCb0uvyb7xvM3/dsjbqJOAVOtSTSNd+kjmH r9clEy3Y5iOBom6ppwJKxhDpLTi5sid9mI/TfuoJInPU6fnvkGVB1Vr7Z1HqpsKWhBy8 t5FDE3Ceukmkt/L5bpfUgcoL3vlr68+QdgldjTiAsHjnUAolzszvGKJr22WSbjFn2oMN dCXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=f3GRrrhs; 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 q24si2536765pls.325.2018.11.29.06.46.54; Thu, 29 Nov 2018 06:47:09 -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=f3GRrrhs; 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 S2387569AbeK3Bch (ORCPT + 99 others); Thu, 29 Nov 2018 20:32:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:60888 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731824AbeK3Bcf (ORCPT ); Thu, 29 Nov 2018 20:32:35 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 B684D2145D; Thu, 29 Nov 2018 14:27:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543501623; bh=7NOd1hMWgwEE+mFTcMuToxVqPnwEMDXLJoPZzdb9Z6Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f3GRrrhsMA6E7PXIEi72KW0fxpXnhUaazWg0cfX6vnigi1ZwgppJbalP2NeAcYS/D Lcnq4Z00neHcbTDxjBY8BsrA37WTlSJeyNXY7k5CLGXmQigbYOuJzrJN0Ow2fwx9J5 TywBjosZAnbpzl6kQBgC5wNB5Z8wGMCJ6lzU3VUo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nicolas Ferre , Josh Wu , Boris Brezillon , Johan Hovold Subject: [PATCH 4.14 073/100] mtd: rawnand: atmel: fix OF child-node lookup Date: Thu, 29 Nov 2018 15:12:43 +0100 Message-Id: <20181129140105.114424159@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129140058.768942700@linuxfoundation.org> References: <20181129140058.768942700@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Johan Hovold commit 5d1e9c2212ea6b4dd735e4fc3dd6279a365d5d10 upstream. 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 Signed-off-by: Boris Brezillon Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/nand/atmel/nand-controller.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) --- a/drivers/mtd/nand/atmel/nand-controller.c +++ b/drivers/mtd/nand/atmel/nand-controller.c @@ -2077,8 +2077,7 @@ atmel_hsmc_nand_controller_legacy_init(s 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"); if (!nfc_np) { dev_err(dev, "Could not find device node for sama5d3-nfc\n"); return -ENODEV; @@ -2492,15 +2491,19 @@ static int atmel_nand_controller_probe(s } 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