Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1863864pxb; Mon, 13 Sep 2021 07:09:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3QBfOqdzRl37DiHjIEkn/M2iH3aPuP8eclTY2l6ygDcmmmEi4v1F+oW0q5NBFiinFeknA X-Received: by 2002:a17:906:5855:: with SMTP id h21mr12846526ejs.230.1631542195533; Mon, 13 Sep 2021 07:09:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631542195; cv=none; d=google.com; s=arc-20160816; b=nj/RlOMyRWimg9ZdzZPKDT3rwrs73qpqPIlhAm4MtopmutaVCAzLbnh5+EUBoSyvlR LMdymZubhLSmNCDbHDg0YMLCYpruhEhDypvHS4zBCBgQX/uJsl6cZCqJldd1cJw7FPkI LAqk8m+kJM0ZtvbA+Wa9clDap1ZYIe71F0Sw/CK4MsYNScQE0uhQSvRSlqZT7kPffqat Nr4i8ToThU/k+xZk9+bEeivs2szsulIrrIP7xdVBosFo/aSjyci87J4TGXA18CDEwjY3 bJuBPCQbbggTO9v4NiNwic39ipippC4DTvWZN4//t5QgDUP3BuUDPko+BH0U8akTM7z1 Et9A== 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=3U7lzitMMaeKP+vm6TbqCBiOLHCNlMnOPrhfiq976Ek=; b=0PcscXfFP33BhLa/t31CrE+FNlalxPe3u7hixXDA2V7d8N7m4OnBIKvpDpAlfYX2d8 KspOuvV0QDt2QmYQmKh1ZnoH0rPavHX53RqLuS4bZ2RrUMyS9DlQbfbJx9E72AMplQPq fD50OOcOorIDnkjQfwVaC+r3oq19USWt8L9wHYS1VVA3LQWEi4EGi4KKeLBskttFB4l4 WOImJtXB39PfgtGoTL7kxXZVsk+vEzjYLOJ7ZAH1ngpkqwdOPMrbhydM1t+M/eOwKbYp JHuNhObA/s6sAUoyArknrs12JOVPlD31ZDo3FHb6BttgLXs93PuHbCyv/7j+9Np47uur 8Ztw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GvNiksvV; 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 x42si1506452edy.427.2021.09.13.07.09.30; Mon, 13 Sep 2021 07:09:55 -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=GvNiksvV; 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 S245356AbhIMOIL (ORCPT + 99 others); Mon, 13 Sep 2021 10:08:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:54798 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344326AbhIMOEq (ORCPT ); Mon, 13 Sep 2021 10:04:46 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B7EBA61A65; Mon, 13 Sep 2021 13:39:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631540365; bh=wEGxYt0NRMm/HmyEG2GpPfJ1BKVhbutcfRASDllrfoc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GvNiksvVcoEGeOOfWKLCFadJqIRG5RAxKRF4KhD9zmx80w2qpWAuEHKsYVQDAGJwd 9PrEq1x9GO+1zMgjQ8KbZ6TGW2Ojh6VTOa/A5ni4HJeJ9jj05IxYD5/crDgeR+SVrd rePw+me/uFMYmqZ6b2Tp88RAlmhthMIWkliNuABs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Leon Romanovsky , "David S. Miller" , Sasha Levin Subject: [PATCH 5.13 132/300] net: ti: am65-cpsw-nuss: fix wrong devlink release order Date: Mon, 13 Sep 2021 15:13:13 +0200 Message-Id: <20210913131113.850740100@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131109.253835823@linuxfoundation.org> References: <20210913131109.253835823@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: Leon Romanovsky [ Upstream commit acf34954efd17d4f65c7bb3e614381e6afc33222 ] The commit that introduced devlink support released devlink resources in wrong order, that made an unwind flow to be asymmetrical. In addition, the am65-cpsw-nuss used internal to devlink core field - registered. In order to fix the unwind flow and remove such access to the registered field, rewrite the code to call devlink_port_unregister only on registered ports. Fixes: 58356eb31d60 ("net: ti: am65-cpsw-nuss: Add devlink support") Signed-off-by: Leon Romanovsky Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 34 ++++++++++++------------ 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/drivers/net/ethernet/ti/am65-cpsw-nuss.c b/drivers/net/ethernet/ti/am65-cpsw-nuss.c index 67a08cbba859..fb58fc470773 100644 --- a/drivers/net/ethernet/ti/am65-cpsw-nuss.c +++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.c @@ -2388,21 +2388,6 @@ static const struct devlink_param am65_cpsw_devlink_params[] = { am65_cpsw_dl_switch_mode_set, NULL), }; -static void am65_cpsw_unregister_devlink_ports(struct am65_cpsw_common *common) -{ - struct devlink_port *dl_port; - struct am65_cpsw_port *port; - int i; - - for (i = 1; i <= common->port_num; i++) { - port = am65_common_get_port(common, i); - dl_port = &port->devlink_port; - - if (dl_port->registered) - devlink_port_unregister(dl_port); - } -} - static int am65_cpsw_nuss_register_devlink(struct am65_cpsw_common *common) { struct devlink_port_attrs attrs = {}; @@ -2464,7 +2449,12 @@ static int am65_cpsw_nuss_register_devlink(struct am65_cpsw_common *common) return ret; dl_port_unreg: - am65_cpsw_unregister_devlink_ports(common); + for (i = i - 1; i >= 1; i--) { + port = am65_common_get_port(common, i); + dl_port = &port->devlink_port; + + devlink_port_unregister(dl_port); + } dl_unreg: devlink_unregister(common->devlink); dl_free: @@ -2475,6 +2465,17 @@ dl_free: static void am65_cpsw_unregister_devlink(struct am65_cpsw_common *common) { + struct devlink_port *dl_port; + struct am65_cpsw_port *port; + int i; + + for (i = 1; i <= common->port_num; i++) { + port = am65_common_get_port(common, i); + dl_port = &port->devlink_port; + + devlink_port_unregister(dl_port); + } + if (!AM65_CPSW_IS_CPSW2G(common) && IS_ENABLED(CONFIG_TI_K3_AM65_CPSW_SWITCHDEV)) { devlink_params_unpublish(common->devlink); @@ -2482,7 +2483,6 @@ static void am65_cpsw_unregister_devlink(struct am65_cpsw_common *common) ARRAY_SIZE(am65_cpsw_devlink_params)); } - am65_cpsw_unregister_devlink_ports(common); devlink_unregister(common->devlink); devlink_free(common->devlink); } -- 2.30.2