Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2350857pxb; Mon, 20 Sep 2021 19:46:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7OtoMalPXroIq0fTXHPXqLF4Rg8ocmq5FVnJ84PM2YtT3l8axGWjNYpsxaQxgQYf/2Shy X-Received: by 2002:a17:907:2d0b:: with SMTP id gs11mr31840266ejc.151.1632192379482; Mon, 20 Sep 2021 19:46:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192379; cv=none; d=google.com; s=arc-20160816; b=erc8DEmZA4Y7zWQGiGmV0pKgiXjAvdxQ0sJYpVKgXS+syNkfk+j30IurwKYTEUekwG UXOTi6n1T3ygRYqlE4vVDOA1wDwO0IAY0Q40F41mQtSwM1xSVkCCOJBxXnH2F8mS9m7d iEezBDh4jFCE+FprN4jrsykWiUMTx1UMm0rgwFEaaW6U9leyTePUxRXHibp/rx8oS/oz 5jYnuIMiJDmfDXDtkP4SQhx0w7JPCZLV4wpAzEQFRxfXC4WO17Wyr3ivWre+m8onSgkA ni0jZ39BaHqVhTz4W9PQ1bZ8INUIuEFewBSZ2DG9kvxxxzVvXBbq8e44qDU9gRrziKkw jVtQ== 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=mBu4C8JqeCAF9/falyTy/bsaIUTWZXVtyeCcpjfkN3Q=; b=dr7urlQ4ofAfLDyA5VJLecznJH6ZX5Ces9MfKNFbXjKV2vYf4RDPNOBL7XFuXqGLCP a3rQuH4NMz86NadDz+scippNRyWvlZnpvSRYrrE5i+DPPCRX7QoARjcpfvOT3H/3VVle qoVpZE34y/Yq7tqbM6SKfbktdMRXxwVNJ2y1pS5gYiTTjIiWrlWUspQMFm+9j4RqUW8N xlUkzENqxYVjAtEqAwQGvtJ1VmfiqagDDvLXX8viQ1sY/Ry1wZwFB5UBvmcVShelPyYy D/Q8cBwSMa2fg7KczLUktC4Ue6YVIR4sMlq0TbGW5K9Eq8acBolcVzUPj5/LIxPm42zb foZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lnBQVr0M; 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 b6si22249884edu.126.2021.09.20.19.45.56; Mon, 20 Sep 2021 19:46:19 -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=lnBQVr0M; 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 S1378827AbhITS0l (ORCPT + 99 others); Mon, 20 Sep 2021 14:26:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:41848 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377672AbhITSUR (ORCPT ); Mon, 20 Sep 2021 14:20:17 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 00950632A7; Mon, 20 Sep 2021 17:23:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158597; bh=zc/V4mTUSYONcVf5ckmwjTjjPBP3eUHTCEbvYXSfPys=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lnBQVr0Mc9HktU3gQUGRsUJob42U3DXyydvr7ezmvztjPmH9YXJ3kW6bR8tDO3fAA bRtGd5olMOiJvZx1OfwgafwO4450h4KQxbd7HdUli2dwVe74IpJIBr26NC2i+6i1Z1 ZpzvvtEkGi8pb4kBRNYLPD5i2OGjcURVg2Lsf4oc= 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.4 222/260] net: dsa: destroy the phylink instance on any error in dsa_slave_phy_setup Date: Mon, 20 Sep 2021 18:44:00 +0200 Message-Id: <20210920163938.650479778@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163931.123590023@linuxfoundation.org> References: <20210920163931.123590023@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 @@ -1327,13 +1327,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;