From patchwork Thu Aug 17 12:01:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 135997 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp1267902vqi; Fri, 18 Aug 2023 02:22:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFuSJE1dMievy9KoDP4eWeRu6M97EuR54wttGjRb+DsuMihj0E096FRh59lIyw1rKNRVSEa X-Received: by 2002:a17:902:c411:b0:1bf:34fb:307d with SMTP id k17-20020a170902c41100b001bf34fb307dmr2221953plk.37.1692350575044; Fri, 18 Aug 2023 02:22:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692350575; cv=none; d=google.com; s=arc-20160816; b=RjUYbOmB3EPjndqmaSSaoQo6cLnVRNcVAYxMuI7F+tRiheumFeSeZqQa1g84KO+SsG WAFIqHeGyRUWYTG+5uSWLt81ZcoOFk3SqBTsJvPUUGitlZBy9mjTWrLF9DVAadgA0oe/ omP4pBsXkpJBn1jfDkVGuAelEWwy+dBNaxShUy4bKJDDzBsQjdIJay6cMyjPJ6fm0qS/ ujXotYCyIvOqbOtivCX+bhlHP68dKsG69F2IL1Zv1esl7lfNThgcYvXywtUmpk9O5yDV VemcUjpYV7pEYCoNhgghLn2WLCP5SbqWGhOW8X1Rh7w/FHR9ldBQ9ofmn/raaVlcF+TG elsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:to:from:date; bh=SeryiRbYKJ2WZYtVkRUX0Kn5X9MRqiXewa99UPs1Pes=; fh=i/7cOp2DJoIXgi+xV4hkrmwH0CgJAA/SrrKLB7fk6wY=; b=GHGY31mpempB+tBGq8CmqQbbABYlbRZ/3RwWJZTm/BH/kjibGoRsPvW3lWisuIX0bY oiyeWEKO+iwKlJzZartM7pgDBn+K4PwbryKsOmA2zNbzDKIHZLaj/TmtcZHZrSFsVUBQ xzsRCFuSyqrkW77KXjjXEb1+RgOknfIIA3Fc+9wsQn3n9I70Kzrk03eHVYoby2I77ed+ voe4q9Nk9wj1Tn4xl5w3lkANKaI9VjQk7UrPttt8xBLeRGKjD2F1D6pYXenNeR29529E AYBLT7o0D6TOnPsbf1YXYkqTNQ5YGf6IiOzsUvFxyQiRgD3DI3qeTjCR/Pa+PDoVdtuT FQlQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id im23-20020a170902bb1700b001bc723dfea0si1117564plb.33.2023.08.18.02.22.38; Fri, 18 Aug 2023 02:22:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350551AbjHQMCd (ORCPT + 99 others); Thu, 17 Aug 2023 08:02:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350469AbjHQMCD (ORCPT ); Thu, 17 Aug 2023 08:02:03 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0F862136; Thu, 17 Aug 2023 05:01:48 -0700 (PDT) Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1qWbh3-0001ko-02; Thu, 17 Aug 2023 12:01:38 +0000 Date: Thu, 17 Aug 2023 13:01:11 +0100 From: Daniel Golle To: Felix Fietkau , John Crispin , Sean Wang , Mark Lee , Lorenzo Bianconi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Matthias Brugger , AngeloGioacchino Del Regno , Sujuan Chen , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH net] net: ethernet: mtk_eth_soc: fix NULL pointer on hw reset Message-ID: <6863f378a2a077701c60cea6ae654212e919d624.1692273610.git.daniel@makrotopia.org> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774558196246698780 X-GMAIL-MSGID: 1774558196246698780 When a hardware reset is triggered on devices not initializing WED the calls to mtk_wed_fe_reset and mtk_wed_fe_reset_complete dereference a pointer on uninitialized stack memory. Initialize the hw_list will 0s and break out of both functions in case a hw_list entry is 0. Fixes: 08a764a7c51b ("net: ethernet: mtk_wed: add reset/reset_complete callbacks") Signed-off-by: Daniel Golle --- drivers/net/ethernet/mediatek/mtk_wed.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/mediatek/mtk_wed.c b/drivers/net/ethernet/mediatek/mtk_wed.c index 00aeee0d5e45f..d14f5137379b9 100644 --- a/drivers/net/ethernet/mediatek/mtk_wed.c +++ b/drivers/net/ethernet/mediatek/mtk_wed.c @@ -41,7 +41,7 @@ #define MTK_WED_RRO_QUE_CNT 8192 #define MTK_WED_MIOD_ENTRY_CNT 128 -static struct mtk_wed_hw *hw_list[2]; +static struct mtk_wed_hw *hw_list[2] = {}; static DEFINE_MUTEX(hw_lock); struct mtk_wed_flow_block_priv { @@ -222,9 +222,13 @@ void mtk_wed_fe_reset(void) for (i = 0; i < ARRAY_SIZE(hw_list); i++) { struct mtk_wed_hw *hw = hw_list[i]; - struct mtk_wed_device *dev = hw->wed_dev; + struct mtk_wed_device *dev; int err; + if (!hw) + break; + + dev = hw->wed_dev; if (!dev || !dev->wlan.reset) continue; @@ -245,8 +249,12 @@ void mtk_wed_fe_reset_complete(void) for (i = 0; i < ARRAY_SIZE(hw_list); i++) { struct mtk_wed_hw *hw = hw_list[i]; - struct mtk_wed_device *dev = hw->wed_dev; + struct mtk_wed_device *dev; + + if (!hw) + break; + dev = hw->wed_dev; if (!dev || !dev->wlan.reset_complete) continue;