Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5643425imm; Mon, 27 Aug 2018 01:25:27 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYsZPfWc78GejERz2kTfnCB7T9g2VRKex1nHPBgQovYpgmOUiqJzORqXCMFwBHyb/Unx0/M X-Received: by 2002:a17:902:9696:: with SMTP id n22-v6mr12352514plp.212.1535358327725; Mon, 27 Aug 2018 01:25:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535358327; cv=none; d=google.com; s=arc-20160816; b=Nz+Ctn6PqOcz1Ibx38krQmHQ0IENASk+hLZxtO8ccBNYhSy4xNxOipBOby1qZzXnZn irdQMDa3YISzfRjEnX48M9jyI1qx1mc8/UGpeG0RsL7hItSh9yOoyo4ZgPJYjOAud/kI DkTGef9MKwvgEC4/071afwpHJPKmJgoPJJxqdNn8xiAjrEXv6AdjjwuwEtcdWqs6Pb8c 4Se3t9lsQGMbXXbuGhYCZFNOAHs2xJ8sMoSAJBscYYDl3V5ZGfc4V1e5WteXqOIX0XRq rd1D9JFgx8y7M1eP4S353e/rHcDT2MVeWS6Kq2FVrUBw1MoCFc9fpJyfB8ASmaqZVrhm e3dg== 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=MT9TmywIaElj/9I+MStyljoZP2SLsnF9wGCpCMKLUw8=; b=fd4qcnzDUsAPl7lgkUbUKnOP8zVcjERVq0MaDJrdZd0QYBSMUU1dmVLQxowtb/yvyV 2Cy1w3rhZc0yQYmnQi2y4KxBinfV/YeUT8cHhktz2HXBU+w6G3CWyrE9WdrV5lu5NHPx ZLvsN79nz3fvpaNDfTBMaV3dSgef2gfb59AE4lIqHV5vO3S+DKvF3YFuGKKPvU78sjhD AhYchBPrWMP3hzyQAvfQ48ZAmFZWQfhBpIWR6el23lIhmjGR8FoK0Kco5w/5p5qRqo+4 ZQ0WfRdQjGKrY98D4r1HA6G22+8oIAdFXU3Xg8aEUu3yiSKpuM0CtGOro0yZBqXZSUpT MZ5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="Cdcgk5/M"; 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 d30-v6si14729084pld.452.2018.08.27.01.25.11; Mon, 27 Aug 2018 01:25:27 -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="Cdcgk5/M"; 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 S1727062AbeH0MIK (ORCPT + 99 others); Mon, 27 Aug 2018 08:08:10 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:40223 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726802AbeH0MIK (ORCPT ); Mon, 27 Aug 2018 08:08:10 -0400 Received: by mail-lf1-f65.google.com with SMTP id x26-v6so9179307lfi.7; Mon, 27 Aug 2018 01:22:33 -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=MT9TmywIaElj/9I+MStyljoZP2SLsnF9wGCpCMKLUw8=; b=Cdcgk5/MaYKrp0oDqqwXTGfTzSBNdx3DXNoVBbiQUOWFTbXnlJ++9m5I3XRyBB3zkr e+K3xHSJPcDfE+IeiCH6Fq4I41Ty++jR2pbyKgGTO3RYZG11BZLU6xaX9q12csSTEpKx OfByA2rAzcZIA6OTaTgghEMebt4YOc1UB1GA+gDVMUm1M6bneo8HZkx5rqiCqnsGXJVn 7/viqgRE0LnJqlEXMugzuaaeFbCjETGYYEaQt6TyLxwX8U7Sk6bmPOcEq/vRb85ct0hg Ek7cWOe3wUk0CYTVIoX9rDzuo1iMJNiPXebNmr42EdSAPY5A5S/uoCtGbSLDl8rYgHIT lZUA== 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=MT9TmywIaElj/9I+MStyljoZP2SLsnF9wGCpCMKLUw8=; b=nxGodQd0Kgs7EneiotOVJwEi4NPoaLVqUOJ5cmg6777xHqNhknSpYeBSyKPjkZLQZo oRopz76He7y6rO+B/X3Wh1lGi/MKA5kp7DPcOdGB7ppI0tdRDiuJlqOndiCmAjrgOHlo aT/r76wI8r6q7jBaRMdrfGCTQtdnZ6zv84kG0eKoVPloi3e3Xx8qqJgbWrCxa1aFrnfx V+qTaPIkKNV1pnEBFupyDwtkinULWeK5c/kVXG4rR5Nk8WHxaKgtnwGA0Wo2Fo6opOU9 nM8sHhEcq5gLl/ROh7O3xA4f0G4VrZ9DTfDsL8FPfYgfOcXJo7p0MQAfa8gHfWXSPm1K rdcw== X-Gm-Message-State: APzg51D8UE5bUDyo4juch8qwxEiexm4AnFWDxfwNGSJpt/NLoTbv87iW CmsdqKBjox5okb8nq/yCPPg= X-Received: by 2002:a19:4803:: with SMTP id v3-v6mr7285611lfa.46.1535358152476; Mon, 27 Aug 2018 01:22:32 -0700 (PDT) Received: from xi.terra ([85.230.190.116]) by smtp.gmail.com with ESMTPSA id f18-v6sm2627464lja.85.2018.08.27.01.22.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Aug 2018 01:22:31 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.91) (envelope-from ) id 1fuCn7-0005sw-59; Mon, 27 Aug 2018 10:22:29 +0200 From: Johan Hovold To: Rob Herring , Greg Kroah-Hartman Cc: Frank Rowand , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , Corentin Labbe , Andrew Lunn , Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S . Miller" Subject: [PATCH v2 7/9] net: stmmac: dwmac-sun8i: fix OF child-node lookup Date: Mon, 27 Aug 2018 10:21:51 +0200 Message-Id: <20180827082153.22537-8-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 mdio-internal 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 mdio-mux node). Fortunately, this was inadvertently balanced by a failure to drop the mdio-mux reference after lookup. While at it, also fix the related mdio-internal- and phy-node reference leaks. Fixes: 634db83b8265 ("net: stmmac: dwmac-sun8i: Handle integrated/external MDIOs") Cc: Corentin Labbe Cc: Andrew Lunn Cc: Giuseppe Cavallaro Cc: Alexandre Torgue Cc: Jose Abreu Cc: David S. Miller Signed-off-by: Johan Hovold --- drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c index f9a61f90cfbc..0f660af01a4b 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c @@ -714,8 +714,9 @@ static int get_ephy_nodes(struct stmmac_priv *priv) return -ENODEV; } - mdio_internal = of_find_compatible_node(mdio_mux, NULL, + mdio_internal = of_get_compatible_child(mdio_mux, "allwinner,sun8i-h3-mdio-internal"); + of_node_put(mdio_mux); if (!mdio_internal) { dev_err(priv->device, "Cannot get internal_mdio node\n"); return -ENODEV; @@ -729,13 +730,20 @@ static int get_ephy_nodes(struct stmmac_priv *priv) gmac->rst_ephy = of_reset_control_get_exclusive(iphynode, NULL); if (IS_ERR(gmac->rst_ephy)) { ret = PTR_ERR(gmac->rst_ephy); - if (ret == -EPROBE_DEFER) + if (ret == -EPROBE_DEFER) { + of_node_put(iphynode); + of_node_put(mdio_internal); return ret; + } continue; } dev_info(priv->device, "Found internal PHY node\n"); + of_node_put(iphynode); + of_node_put(mdio_internal); return 0; } + + of_node_put(mdio_internal); return -ENODEV; } -- 2.18.0