From patchwork Wed Dec 7 14:04:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 13067205 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44A71C63705 for ; Wed, 7 Dec 2022 14:08:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230298AbiLGOIB (ORCPT ); Wed, 7 Dec 2022 09:08:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230198AbiLGOGH (ORCPT ); Wed, 7 Dec 2022 09:06:07 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B72A018B31 for ; Wed, 7 Dec 2022 06:05:40 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6DC15B81B90 for ; Wed, 7 Dec 2022 14:05:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA3ABC433C1; Wed, 7 Dec 2022 14:05:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670421938; bh=sRaak4KLeCok7dS29659RMJxhIRUiWs94IOmcA+/uIE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CqQ7bQNh5/D/kXndvbEeFCOeu36ZFkIWH3EF5Tj8kSR8+zqgDsz2RX004OgTgOZ7E 6n7yvTBECDl3wGu1SH28FQJEC1IlZXOSGHasY3hLSzHI1aSHPFScQuAuu6LUI7gEw4 KT/9Gm4WkxGAtTCMCm0TT/ZTDLft7UUJpZG79L+qX5i3HSUQLrpcaqmCA7cWPj1mt0 yM4ce/VtFomWtZg5oO/QDPo5p6vsinnHHGrAqYCia8AuHG4GQkdhST1O23em/tXiXg 1OU+mSv2ORwiV01Hj5N8zlppIPnLjG+pXYUi9CS+8SgBDuihtng30dakx1siWpwL5h iUqFVcdVmnGHQ== From: Lorenzo Bianconi To: netdev@vger.kernel.org Cc: nbd@nbd.name, john@phrozen.org, sean.wang@mediatek.com, Mark-MC.Lee@mediatek.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, matthias.bgg@gmail.com, linux-mediatek@lists.infradead.org, lorenzo.bianconi@redhat.com, leon@kernel.org, sujuan.chen@mediatek.com Subject: [PATCH v3 net-next 2/2] net: ethernet: mtk_wed: fix possible deadlock if mtk_wed_wo_init fails Date: Wed, 7 Dec 2022 15:04:55 +0100 Message-Id: X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Introduce __mtk_wed_detach() in order to avoid a deadlock in mtk_wed_attach routine if mtk_wed_wo_init fails since both mtk_wed_attach and mtk_wed_detach run holding hw_lock mutex. Fixes: 4c5de09eb0d0 ("net: ethernet: mtk_wed: add configure wed wo support") Signed-off-by: Lorenzo Bianconi Reviewed-by: Leon Romanovsky --- drivers/net/ethernet/mediatek/mtk_wed.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/mediatek/mtk_wed.c b/drivers/net/ethernet/mediatek/mtk_wed.c index 4ef23eadd69e..a6271449617f 100644 --- a/drivers/net/ethernet/mediatek/mtk_wed.c +++ b/drivers/net/ethernet/mediatek/mtk_wed.c @@ -577,12 +577,10 @@ mtk_wed_deinit(struct mtk_wed_device *dev) } static void -mtk_wed_detach(struct mtk_wed_device *dev) +__mtk_wed_detach(struct mtk_wed_device *dev) { struct mtk_wed_hw *hw = dev->hw; - mutex_lock(&hw_lock); - mtk_wed_deinit(dev); mtk_wdma_rx_reset(dev); @@ -615,6 +613,13 @@ mtk_wed_detach(struct mtk_wed_device *dev) module_put(THIS_MODULE); hw->wed_dev = NULL; +} + +static void +mtk_wed_detach(struct mtk_wed_device *dev) +{ + mutex_lock(&hw_lock); + __mtk_wed_detach(dev); mutex_unlock(&hw_lock); } @@ -1497,8 +1502,10 @@ mtk_wed_attach(struct mtk_wed_device *dev) ret = mtk_wed_wo_init(hw); } out: - if (ret) - mtk_wed_detach(dev); + if (ret) { + dev_err(dev->hw->dev, "failed to attach wed device\n"); + __mtk_wed_detach(dev); + } unlock: mutex_unlock(&hw_lock);