Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6283229imu; Mon, 21 Jan 2019 06:21:09 -0800 (PST) X-Google-Smtp-Source: ALg8bN5mTfJGEEoTK/ByR/45/+r/7+VdApeQ3ImFooN90pTMyyfEkd8Da+/qXn6fnX+tFOmf8I0Y X-Received: by 2002:a17:902:34a:: with SMTP id 68mr30828025pld.268.1548080469398; Mon, 21 Jan 2019 06:21:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548080469; cv=none; d=google.com; s=arc-20160816; b=vLT4SKAqz7b8GSmqfRhlfCYdCmbuIo7T4Axko1LNdWyK0CpehiOB328ERYeMVlRQ5Z 8MqkbL/K/+BDbKoOXj3mMy5fvz+VUJlHSUI1NFCkb9VPSpudksaymdDXBQah+zLb5Bj2 v9fUptNyL8I9WN9QEwwp5nJ2/AplMoLyYqJTkCHbz8zRkpPllTzHUCa/1+zzpX1at8F4 1TmDw3C+q4qKe8ox+EVoPHs1GtDro9fTE2PujrFY9WfrjKKizD36mFLSIv4MLyBicZcf CfLYtE3puOtSGe5jwI9RTdo2na493OcGJ8pidQxNnedkmsRdDU2fGAXAnu8HABp3oYsR IjAQ== 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=ca05fdhGKc7ECbuDUiwuKfjzwuuvQihgvKKoAxGld3I=; b=lTUOj5hraop8HtBsIdSp8WBBR/FT88wdPhecIlHdVEtfAkuKPoVFaeyKQ89d9221cy mdb9Y3sXnrICGt+/Id6goYHBgToXWDdA38eODVFXbiprCWzUw7UNHHvyQPsv27D6gBqF RNrI/pv3UwlIbtKWim0i2QuU6Sv6LT2IC/FZ+UvsnDjSGXp0+f++Jx52cVgrdGZBC50T 8WUQINdJR99NzJt+v3DKNpB9OBsbdWto5nyRIqSQ89Y3lSeNdpoLFyyjWs8MwVLZEYLj AZr7Rye30n3ohen9JHbw9ncnS2F0X+2AANVpN+chWjsw9FthU4wccr/dRXoqmI1SLzF3 46yA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JXPCNE+h; 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 a28si12652119pgl.530.2019.01.21.06.20.51; Mon, 21 Jan 2019 06:21: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=JXPCNE+h; 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 S1730018AbfAUOTb (ORCPT + 99 others); Mon, 21 Jan 2019 09:19:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:58842 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729397AbfAUNso (ORCPT ); Mon, 21 Jan 2019 08:48:44 -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 7F6AB20861; Mon, 21 Jan 2019 13:48:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548078524; bh=w+0h2kDubArd3hdoGBVRy/zSIz+a9Ln7Fu+qzVNwyi4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JXPCNE+hIZrpDeqE1zx3FPOsiQdGiOiCgEo4r/3Lw0IMIY+Er1plb+Xyc5VPauPdV v2ESRB2Vk2SYSEeT6jEz8FlkTCe2RjT8k8bH6JMJdffVQ5FuemGd9o9WXnyt1g1dkA jKJQla1a3+ytSsFB1cPFLs5B9p3n6ybekxy6dI0s= 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.20 063/111] net: dsa: realtek-smi: fix OF child-node lookup Date: Mon, 21 Jan 2019 14:42:57 +0100 Message-Id: <20190121122503.195129232@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190121122455.819406896@linuxfoundation.org> References: <20190121122455.819406896@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.20-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;