Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2353185pxb; Mon, 20 Sep 2021 19:51:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykc5MEyPnpBqiGVokhSvCK0L6+AbV2SDvkLNzTko2pDHolhUZnkLDOHb1GfkTJqeqcCH3N X-Received: by 2002:a92:c548:: with SMTP id a8mr12487484ilj.295.1632192665936; Mon, 20 Sep 2021 19:51:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192665; cv=none; d=google.com; s=arc-20160816; b=syECbczqBnXrzksj0wrp7gUZJu0+RT/18zI7n71QLGQ6w0LXhaY6WpJwEggcuOe9sq 2TWWYgV583/Sx3esEJ064wx9gI5nlSbPTtKiK5YZAKV10af6yEf1UaTXxHQP7raJnbeE BBSAlqtqU7wvIHA2OpJov4xRsTHmRkQ2lomPwi/i4EUxjTV0tsMpizwLz13JuP6yRs6I QIP5lWNu1ornAVAkGghNY829cRRAfoa+SgnxD30dA4qlwLk+r/4cwNszdwDeRGPtroLv W39zrJ6KUv2dzPjoGmp3CmhCSBDfskBD3lr93b6pI9QQ+6SyKM8KUCcuegFOPRs2tKYe iR+w== 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=ZuFaJI1p1GucvRcHYSdZQirQD6XHsNojgKs3Fn3eOgU=; b=FFWarTfzyvV0XkzAXmt6z127sAp5M3Cj3HOJMzCwTplG7SKIHXD8bnGDFVgtCEAznn VQKhJZOfZMtFkbOY/vZibOaTZLYIadGWTReaTDT1ILByxsUZa+EbtBBDWuo30PY/ScID 7cctr0gHKubRqHjBY2roV3UHPTd5rtJcpzs+FMch4ikoloQRrBSacvKF4x7vUCuJ73EG OVteH1ZlUJwcEOuzd1DtafOhBWo3aoGDFWKWtIdpaYCMXdNi2J1sjvOt1YaERrZtAKef sNGLIS2Z5hppJ/lf+Ghyoz1FDQqrZK5HzA/zqzPEwxE8e0Gaxg9zlYi6phHNmfHl3ztt i8gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kh6M0CsN; 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 e24si10783569jak.17.2021.09.20.19.50.55; Mon, 20 Sep 2021 19:51:05 -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=kh6M0CsN; 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 S1349522AbhITSqs (ORCPT + 99 others); Mon, 20 Sep 2021 14:46:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:56446 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382710AbhITSmR (ORCPT ); Mon, 20 Sep 2021 14:42:17 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DB6996333B; Mon, 20 Sep 2021 17:31:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632159107; bh=25VZmXlBoEsaxOHHIKUAQV+S0QZHAPZdnMv/5iJxgwk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kh6M0CsNMBlOyySBbYSAdOQDE/2E1cBJYDXQgSvXYBA04SjGb2uhnWE0xfkzGbOU+ +0dPobgFQUnpkU+wWYkdf4ddCVsEZqTrTApJdzGb64HB2VQOrg29TVLecaC18z8v8E 8/PvCl5CigECHUKfdEtVCdrD5+0l4PTpFsw0HnHg= 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 5.14 062/168] net: dsa: destroy the phylink instance on any error in dsa_slave_phy_setup Date: Mon, 20 Sep 2021 18:43:20 +0200 Message-Id: <20210920163923.675441643@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163921.633181900@linuxfoundation.org> References: <20210920163921.633181900@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 @@ -1784,13 +1784,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, phy_flags); - 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;