Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp172980imd; Wed, 31 Oct 2018 16:47:25 -0700 (PDT) X-Google-Smtp-Source: AJdET5d+Pe8kLVcYTZCbd6oJLL1V8i8NSjWTYgXaYBebXHOZ2ey4bukjy0pgbPQppg2X4vMQBjxt X-Received: by 2002:aa7:8603:: with SMTP id p3-v6mr5384218pfn.247.1541029645610; Wed, 31 Oct 2018 16:47:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541029645; cv=none; d=google.com; s=arc-20160816; b=OgLRLZ/9kwdUNXCGEFuS2yGm6gRmPOTooWrKJefVbyavjAtgnwhj1vP81xQ3RnVqo/ RXHyi8x5SXXz24CjAU6n02LizyOt15iVA9JDjBqt9Z8P++Ag6sec3JtG5L2uKqA6OVc8 jfSJxjkV994thBsAyznAgI251fGM92LkKCms3lwPHp/slMhQjYx9DZXd/rYnwb/Ujh/D N0JdkmmE7L/AEm/e7Vfq1nqpQcFqM1qdqBQ6EBbwF+BinNkThLs3SP2e351SaSgeKrEx MhjMqfp68RKcb4+MJnQZMZh6nH90RYkC+mW81iJcv5s3P7YkRLzhd0RPQNQqrJpGFN2P J9dA== 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; bh=Yg4W6lt8OMB5mc+96baqVrJik4dJT9RtWf4l21Aee7Q=; b=tXvdFlpNqPRu2ACwUWMW+4A45MU985L/vvn28ebDgIKd+Xkl9VjTbkMiesmwJ8N8Ko tv071ZAfiAqzP2rXA8TiwadEosQCyCmW8RorNaNcoIwRingEFWpI2kg/3hM6WroiX5I+ jLw9mg1fhdZonaAME24ItY7kqsq++5jlSR+XDFK26MUJ14+ZvltvPCCUTgiX8G9JtPqR 8u4aCpUt3VuImPPiAAudEKOU14CY+mHSRsEAUfxqie6Xk08SnN0lEnfpXPcB6GCdZABz QuyEe63Kr3Vg1cVo0d9CS/rI0BKa7NigsM6+kxcfVovqhvNpMntrs+em4H8AXSi8n0L2 oAnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="0/NmBIq8"; 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 p12-v6si30781950pll.1.2018.10.31.16.47.10; Wed, 31 Oct 2018 16:47:25 -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=pass header.i=@kernel.org header.s=default header.b="0/NmBIq8"; 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 S1728679AbeKAIHN (ORCPT + 99 others); Thu, 1 Nov 2018 04:07:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:54748 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728646AbeKAIHM (ORCPT ); Thu, 1 Nov 2018 04:07:12 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E4F5720830; Wed, 31 Oct 2018 23:07:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027221; bh=lnwAYRnij7/dG5MTGCKc2ZqWr+tKNp1FUnymCKTx1sA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0/NmBIq82DBSqNrZat8bCPjoyolxmhXumE3r3QncJJBZj3rHX0PEfpkEm7gl6H85e 3VBKbEMhC3Wuu1K/0YkDdjbQgmyjY24OO1t3/jItfSfL9SKjhQD3tSLZmCG1spTBz6 4HDNcjBfJK6P1abksyw6arRsCCwrDLRe+YNiM3OM= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Johan Hovold , Andrew Lunn , Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S . Miller" , Rob Herring , Sasha Levin Subject: [PATCH AUTOSEL 4.19 087/146] net: stmmac: dwmac-sun8i: fix OF child-node lookup Date: Wed, 31 Oct 2018 19:04:42 -0400 Message-Id: <20181031230541.28822-87-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Johan Hovold [ Upstream commit ac63043d8cb5503c7e0fe110f947eacf2663804e ] 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") Tested-by: Corentin Labbe Cc: Andrew Lunn Cc: Giuseppe Cavallaro Cc: Alexandre Torgue Cc: Jose Abreu Cc: David S. Miller Signed-off-by: Johan Hovold Signed-off-by: Rob Herring Signed-off-by: Sasha Levin --- 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.17.1