Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5642853imm; Mon, 27 Aug 2018 01:24:43 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZdPyhAvhAsKKdvOTHylxawFuJDw/0pBQxZUscRrvIE/L+NJ47TAEdzK3bmI29Lo7reb0Th X-Received: by 2002:a62:d085:: with SMTP id p127-v6mr13262081pfg.119.1535358283281; Mon, 27 Aug 2018 01:24:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535358283; cv=none; d=google.com; s=arc-20160816; b=kHNOBOwLkcSyw7pOlQ3kXriFjsj3lIJRXaAg8J3NwpNvYH1TRXBvOpLYmwczmxVxiN BFUmJs7ZSeSWtTkeFUZYlg0RgLspvsKq0LNXgu9WbkatIfpvAx3PLiVYX/YSiOzLrYi3 QLh8ty/pULXrkX6RmxpTp0/WcyH9gOq7JihdotdS8w7eTyvRXkNsE8sRW0Htt8K8+onj shJaT8yZ3pYZWJA+03Z9M8Pp+ntkIweiIJfhDZ/ZJ5TQZh6FWwwoUT4kvhpIG3BXP7Sg rEeHAvWXrfBQPbDUlkPN0c0/JWH8apeLwMpz0oh34MXhYxHPe2N7hlRmdSuMr2IgVDhF xEuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=ZNAYksAopsEQ5bLVYvPV8FzwGGcmlbAzmNT8NC9D34g=; b=p4N5FtZNy/6ha3btJT1w+2x7I4s2TDB/XHI/SkRsiyMP90oUgs9/5DyI23xNGI1HMW SL65ldZJiTiBufs79V4dzzMom9OL4r0x4IUB+mZdjreCMJmaAqE+pk4GtujZBlBi3Q8q 4n+0YfznwNi483Pb7De1Rd3vxZqIzw3PVISShaWzaQKxdFHU057QIlXPuJ989712utTI abahfGpdjD27vQbq2LJMin2wL4FfDxvWF4/O9i6Rlop15f+7VFEpmjuMBZrWbZDqc11+ TyCz2UllRud/XHl6Xuh86ITbkEfN7UJT/G6VKkSOluxedO5aWimHdrAJ8WneGxMsiWf7 NXRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Fzi7GNmM; 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=fail (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 b8-v6si12251264plx.110.2018.08.27.01.24.27; Mon, 27 Aug 2018 01:24:43 -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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Fzi7GNmM; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727374AbeH0MIj (ORCPT + 99 others); Mon, 27 Aug 2018 08:08:39 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:43956 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726894AbeH0MIP (ORCPT ); Mon, 27 Aug 2018 08:08:15 -0400 Received: by mail-lj1-f195.google.com with SMTP id m84-v6so11587581lje.10; Mon, 27 Aug 2018 01:22:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZNAYksAopsEQ5bLVYvPV8FzwGGcmlbAzmNT8NC9D34g=; b=Fzi7GNmMMyZEtg76T3LfNOS8zFvJ/xL98cm+6Wdjs6gY0gBvY6rsEKbgOXEsMRCFc8 I42EerwKTwUsNqpNZV76TZFN9n24T35hPhCKmo0XwSNKGR+mF2kmOxp+RlfQECuenZV/ 9pOh+qTrBKj9C8mdx99GH2GVQDx2CbgWXhdZ3I+3kNKic+4yp6qMywyci3q5mVCR+gJ7 LJzMqpDhoG9Cfjw7Z2CPZCiP/LMIZ0VxpFUKyIKstoVEU/+DDTREf0K6QNDy8jiuhnHT mP8tNffzeOOHBPIK6G6IXgj86vVleelRDQux4olT4LySd6PMsho/Z1NUoTFFyCGYH1jQ 3KSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=ZNAYksAopsEQ5bLVYvPV8FzwGGcmlbAzmNT8NC9D34g=; b=VrsLiAKA8VUmh8ZQjww5O1KHfSmAJIQrIynoI0JBj6GMEyN1g0JiEUI+vMEFT8k/mf a86p6YM5TxAw5W8ZE/Q554YULaBo8/HG9V9B5H9oKTDcyTvdfwvKRPmEnv+MiuBX3hWB BnNr1pD63BRmvHsSWgmCAgveu6gPXZ+kpMTXi0viHtRehf8eFmmfpOQovU6QZ+o01lqY g53eF29cFXUaWZCFhTN6EoppXokilt5x4VaWsyoZXkUsQLZDzOqq3rkdLXpuXhiPJ4dL xCOeVgCxY2GVZXNd8CjzDjWhIRSXNTK5KdKW4BOOA7WscoS/mvqLIAvfwPSDn3po1xzV 5zFw== X-Gm-Message-State: APzg51CfajZdNdGmbo1yOlmvQqC0c/Bgvf3hq6p4WE8jhtxPvgxAzU54 fJTFqq6eZjxE/GCtiYSWJg4= X-Received: by 2002:a2e:2e02:: with SMTP id u2-v6mr8107552lju.77.1535358157432; Mon, 27 Aug 2018 01:22:37 -0700 (PDT) Received: from xi.terra ([85.230.190.116]) by smtp.gmail.com with ESMTPSA id q23-v6sm2729468lfj.80.2018.08.27.01.22.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Aug 2018 01:22:36 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.91) (envelope-from ) id 1fuCn6-0005sm-UV; Mon, 27 Aug 2018 10:22:28 +0200 From: Johan Hovold To: Rob Herring , Greg Kroah-Hartman Cc: Frank Rowand , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable , Nicolas Ferre , Josh Wu , Boris Brezillon Subject: [PATCH v2 5/9] mtd: nand: atmel: fix OF child-node lookup Date: Mon, 27 Aug 2018 10:21:49 +0200 Message-Id: <20180827082153.22537-6-johan@kernel.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180827082153.22537-1-johan@kernel.org> References: <20180827082153.22537-1-johan@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 -- 2.18.0