Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6269393imu; Mon, 21 Jan 2019 06:08:36 -0800 (PST) X-Google-Smtp-Source: ALg8bN4JxI+plVp1eURe+Kuqk9Cvo1ND9lyo7e+aX5oD+pOdKfZeRKLUur7WWte7Kh5+IIYPsbet X-Received: by 2002:a63:8e43:: with SMTP id k64mr28000858pge.346.1548079715967; Mon, 21 Jan 2019 06:08:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548079715; cv=none; d=google.com; s=arc-20160816; b=k8KUOVy/dEENOXJ2AO9pEY3ptZGe/nGYtHWhtRh1xm94ITVojDkVHGll0YcNDC8IxL AbSdTm14ZNz2ouKlTK2vJuWO2AlxHOT59DnLaDtHzXHQgy0X/pgGBCFPxy4GMZJrtxHD dSwr5eoYAbU/rl9JQmDBXBJSAl0UtilXOGhe4gmg26saClVEoGPKvT/a0sSSaeqjVIBF Vm6otHJiSQGMssgdmA5qRsxiHvXJ3PqYsfg9d+5ypGWCIaXMRSuzDKkEHJu8JBbqZ1Lk rnz3QYnH2EdHKul+g08iQqp3Z7We0RTvdZViDfpGWWvOSU0nE1sHFdhNr51t/crSvVPB JFwg== 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=zNhhGt3DshuImCJjuaS3HniissJYC8wU9UgYnDwg6mc=; b=xciAkgm/suJSipV7DzqYM2QT+BAtSVn0zu9Rv2T2B1ewDeX4mK7hMLO4JZQYL8hVTh 7tRD4+oRrYewk9Brk+2LM/m6OqOPzrdKR0TfI1Wu+gHzQaPv7HIJY/5IIgeO6bTGIN0N lZle/LRYzLB0NV65kZ4s3YPB006Xm5Baps92n6o4XWcL9JRXUM/Ve4c5cyX5lyG4NPs0 /JgvtHSDzs3ywKogkYJXBMdI5GP3jI0xhHe6yZYhXuhXOsBJVWLDfTekP6A62kFsYdqv 2DcJQTTaibeA4KNeuB+cLNrN84PK++/gNTHBKuK8YY1wacNw6LyyAWdGuvsJllUJdFpa Nwxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YJSamXN9; 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 i4si12255058pfg.218.2019.01.21.06.08.20; Mon, 21 Jan 2019 06:08:35 -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=YJSamXN9; 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 S1732485AbfAUOAj (ORCPT + 99 others); Mon, 21 Jan 2019 09:00:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:47228 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731942AbfAUOAf (ORCPT ); Mon, 21 Jan 2019 09:00: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 0946420879; Mon, 21 Jan 2019 14:00:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548079234; bh=WFgOjWOoojWBy/l0tVKW/1nvzCPiR7k25e4VaQT8SOc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YJSamXN9v1Rn3UCxWGo9CTP05BtLJTSb2gsNl9LzdZmacy1SAQl9ruEqTN88KyoUn QL+lkaaD3kcL0nKRQ7MFIUlznnR0Kb2dA0MM/fxyoiSZrXrA4NiGR6ewzpoy6toKbN Twoeyq/0j5vr31wooRAPHlop4ZYHJ3NCVwHkuHQk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Linus Walleij , Johan Hovold , Andrew Lunn , "David S. Miller" Subject: [PATCH 4.19 55/99] net: dsa: realtek-smi: fix OF child-node lookup Date: Mon, 21 Jan 2019 14:48:47 +0100 Message-Id: <20190121134916.070292567@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190121134913.924726465@linuxfoundation.org> References: <20190121134913.924726465@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Johan Hovold commit 3f1bb6abdf19cfa89860b3bc9e7f31b44b6a0ba1 upstream. Use the new of_get_compatible_child() helper to look up child nodes to avoid ever matching non-child nodes elsewhere in the tree. Also fix up the related struct device_node leaks. Fixes: d8652956cf37 ("net: dsa: realtek-smi: Add Realtek SMI driver") Cc: stable # 4.19: 36156f9241cb0 Cc: Linus Walleij Signed-off-by: Johan Hovold Reviewed-by: Andrew Lunn Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/dsa/realtek-smi.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) --- a/drivers/net/dsa/realtek-smi.c +++ b/drivers/net/dsa/realtek-smi.c @@ -347,16 +347,17 @@ int realtek_smi_setup_mdio(struct realte struct device_node *mdio_np; int ret; - mdio_np = of_find_compatible_node(smi->dev->of_node, NULL, - "realtek,smi-mdio"); + mdio_np = of_get_compatible_child(smi->dev->of_node, "realtek,smi-mdio"); if (!mdio_np) { dev_err(smi->dev, "no MDIO bus node\n"); return -ENODEV; } smi->slave_mii_bus = devm_mdiobus_alloc(smi->dev); - if (!smi->slave_mii_bus) - return -ENOMEM; + if (!smi->slave_mii_bus) { + ret = -ENOMEM; + goto err_put_node; + } smi->slave_mii_bus->priv = smi; smi->slave_mii_bus->name = "SMI slave MII"; smi->slave_mii_bus->read = realtek_smi_mdio_read; @@ -371,10 +372,15 @@ int realtek_smi_setup_mdio(struct realte if (ret) { dev_err(smi->dev, "unable to register MDIO bus %s\n", smi->slave_mii_bus->id); - of_node_put(mdio_np); + goto err_put_node; } return 0; + +err_put_node: + of_node_put(mdio_np); + + return ret; } static int realtek_smi_probe(struct platform_device *pdev) @@ -457,6 +463,8 @@ static int realtek_smi_remove(struct pla struct realtek_smi *smi = dev_get_drvdata(&pdev->dev); dsa_unregister_switch(smi->ds); + if (smi->slave_mii_bus) + of_node_put(smi->slave_mii_bus->dev.of_node); gpiod_set_value(smi->reset, 1); return 0;