Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2565884lkm; Mon, 20 Sep 2021 18:52:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMdvk2U76RtX1JePn0ktrnRp5izHfPAMRKzfq7SgC7eUvLpOPlLYF73l8OeIpjYVBMDoQV X-Received: by 2002:a6b:cd43:: with SMTP id d64mr20663833iog.28.1632189027537; Mon, 20 Sep 2021 18:50:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632189027; cv=none; d=google.com; s=arc-20160816; b=lIOWbAByT80D9JY6qgEyRuBLPG+V+aWM8iJrIluGIeZRQaRoLimruakgUVZc2DYF03 bHpPtPToD+uo3AU3MPdWNAnEQQAImSlkgKk8Kx+BvMEBqoCCaxpPqAqJmfGtOvGKCc83 2Cxvw5iDbJUDXzIvRPKfDe/UpXAPzfw3S5UR/I8ztNnfT7kWYeAXev/7CiPNjr3Huzgp PuZgYoEl4DvkNmHKbkxSU0zcYTBO2tYlNRCp9LmsSzkLEp1FZD166Ti0VgNKtu2n4qPM fCEc+iD079PxiXoJ94UBOxsVWFWmO0pUYB1OlV2uwZg7++3Y4yvOAw1qsRwJP/s5B8mB 4ZJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=E65wIkJ77Xb+fixntS5HgfD6o9MLkryCVJVQ7F8ezZI=; b=eFua81dOBYB5OL63Wit2MS2/WBd6swgIn156n0Rt4ctedJINQTPEU1wnnSUxqgxbaW TWFYLvqN3kMyyoetjq685ud2rst0lNcyFP7k+AISxgooyD+ltdxT4Fi3iuefqR8zH0Yg HScEk4e0raaT+ncH//EOdiE8EXGwC4ZOw2X2tsil/vM8UI7tHbtqT+8MDINrpXBUw1bS 9E54j7F3O/EH+9T4mcz2Bib5Bs8mm+oQg4al1Ds0j0c4AKyM2U8UgI8lpFQbcylRoBeM L3W4vjL8x4pfzqYs2Y+Eg2l9G1C/YcJUNmFhKiQ7ra18+9EX6DDKYcXeM1Mle7XpBIKY NR3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oC3G4AC7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w3si9473731ilg.44.2021.09.20.18.50.16; Mon, 20 Sep 2021 18:50:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oC3G4AC7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356914AbhITSCQ (ORCPT + 99 others); Mon, 20 Sep 2021 14:02:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:55426 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349742AbhITRzv (ORCPT ); Mon, 20 Sep 2021 13:55:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 40C5061C16; Mon, 20 Sep 2021 17:14:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158042; bh=kHtKFT2USIlX41377D96jYNFZHEDSLiS+PgJ1Z4aG0Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oC3G4AC7J18OWxKK/NzDzVm6M1ir4nwvFlcQOTK7wnJbehHNPTpUgGMkzfSMJHCen 9XwDuVegCVCUGeG51QdgiGc1QkYz0SkGyowMey7TyACDQCbeK+mwnCn2Fwej8ryP44 qvN7gpl4Txzx3h6gsB3NctX/+jf7JRdVGR3oU/Vc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vladimir Oltean , Florian Fainelli , "Russell King (Oracle)" , Jakub Kicinski Subject: [PATCH 4.19 268/293] net: dsa: destroy the phylink instance on any error in dsa_slave_phy_setup Date: Mon, 20 Sep 2021 18:43:50 +0200 Message-Id: <20210920163942.586707272@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163933.258815435@linuxfoundation.org> References: <20210920163933.258815435@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vladimir Oltean commit 6a52e73368038f47f6618623d75061dc263b26ae upstream. DSA supports connecting to a phy-handle, and has a fallback to a non-OF based method of connecting to an internal PHY on the switch's own MDIO bus, if no phy-handle and no fixed-link nodes were present. The -ENODEV error code from the first attempt (phylink_of_phy_connect) is what triggers the second attempt (phylink_connect_phy). However, when the first attempt returns a different error code than -ENODEV, this results in an unbalance of calls to phylink_create and phylink_destroy by the time we exit the function. The phylink instance has leaked. There are many other error codes that can be returned by phylink_of_phy_connect. For example, phylink_validate returns -EINVAL. So this is a practical issue too. Fixes: aab9c4067d23 ("net: dsa: Plug in PHYLINK support") Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli Reviewed-by: Russell King (Oracle) Link: https://lore.kernel.org/r/20210914134331.2303380-1-vladimir.oltean@nxp.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/dsa/slave.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -1226,13 +1226,11 @@ static int dsa_slave_phy_setup(struct ne * use the switch internal MDIO bus instead */ ret = dsa_slave_phy_connect(slave_dev, dp->index); - if (ret) { - netdev_err(slave_dev, - "failed to connect to port %d: %d\n", - dp->index, ret); - phylink_destroy(dp->pl); - return ret; - } + } + if (ret) { + netdev_err(slave_dev, "failed to connect to PHY: %pe\n", + ERR_PTR(ret)); + phylink_destroy(dp->pl); } return ret;