Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp3368573pxb; Tue, 19 Apr 2022 00:26:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDyVM1hcDSrzVDN/yuZ7t9iXswK+YFbqeaj+1kKotmDPynNqtbO+5Ij+0PZWdGk4ihyb+Y X-Received: by 2002:a63:e04a:0:b0:39f:ea06:e203 with SMTP id n10-20020a63e04a000000b0039fea06e203mr13337573pgj.146.1650353211763; Tue, 19 Apr 2022 00:26:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650353211; cv=none; d=google.com; s=arc-20160816; b=KPytGfK2B2lRSBCGNxu80L0MZOhC1tDxv3G2qqKT5UNt6omK90KIpefTXZl6VQKqDS H3thLfj3ECRKhWbeT0PZIAym6/PLK2uqSPWM5XMYfS9nOsk1kd++T2NAnLcmTskp53aM Rjw7nfBxr9toFveW5hjH8muQxxsYo5qZcTzSbwOB8FlPfgZIQxecRPzfl1SbLzOnpFNt hTddDZAigqSqJe9rBJz+y2BnZjlvKTcfHGje3d18fe/MuGnCL0K0Db8w9AAN1O1HncD7 6oNp/EKKt1Sj5tY/HcXIwwwy6sWnft8eVvG46DCqetlVDmSGa/3fY3f31IMPFsvPVf3G VrBw== 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=0bCaRyj/DVLMwuF7yoTRGCQ7zCWOmXFOQ1p+RHuYRWY=; b=Akx3XIrQQEGyJAhqWlhrJGm1Xkd3GPuMGIZvrwlcsIIh8fdkU0sw2+NMrxuxCDxOys yMj3m+aG0gxgfjg6fSKQvy8Guki1XaOKHVSq25CT395rYjaDz61tmAAr0D1pwCnXHV2H AdRJtsUlApPecCAYeBle1X6dxbAro+1vhMhmHCQCKEZNHBNaiKeTBE9wpw/21prR1Yvj ljHfWcAL7Oy3bJ80ibwFGBJKGo/lhf3vQYbs8uCPk9t7sIiqd1EoeVwuLT6iySFjIJ/A nE4mIWCR9o3yuRr0bzExGzCJ+WtGFWehPDja3hLbm5JrFu2AMOjnsYUdx3N1c9tnG8OA ar8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pw8kqoqF; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c7-20020a170903234700b001548c7c077fsi11648299plh.454.2022.04.19.00.26.37; Tue, 19 Apr 2022 00:26:51 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pw8kqoqF; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343616AbiDROE3 (ORCPT + 99 others); Mon, 18 Apr 2022 10:04:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243579AbiDRNqq (ORCPT ); Mon, 18 Apr 2022 09:46:46 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B43627148; Mon, 18 Apr 2022 06:00:50 -0700 (PDT) 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 D91BAB80E4B; Mon, 18 Apr 2022 13:00:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B648C385A7; Mon, 18 Apr 2022 13:00:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650286847; bh=UVZk+cqsD9flg0av6RCzbNuaqmHbDPKhOrg1VHCf1dY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pw8kqoqFae4ftWnHe997cpWmEamTIx7t4mLt+4/8+8HaccO04Av5Msz+uMb5l4c0P P1DhPmy3TVsn66t8jwhtgJDWbh5qwO5YiOD4ZsSrulRtmGy97jI5kf+kpyiz2msySy ga+X5wbIKVLEIFu2IB2i9CLKumBbliA+sYwOBVGA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dinh Nguyen , "David S. Miller" , Sasha Levin Subject: [PATCH 4.14 265/284] net: ethernet: stmmac: fix altr_tse_pcs function when using a fixed-link Date: Mon, 18 Apr 2022 14:14:06 +0200 Message-Id: <20220418121220.238931203@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121210.689577360@linuxfoundation.org> References: <20220418121210.689577360@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Dinh Nguyen [ Upstream commit a6aaa00324240967272b451bfa772547bd576ee6 ] When using a fixed-link, the altr_tse_pcs driver crashes due to null-pointer dereference as no phy_device is provided to tse_pcs_fix_mac_speed function. Fix this by adding a check for phy_dev before calling the tse_pcs_fix_mac_speed() function. Also clean up the tse_pcs_fix_mac_speed function a bit. There is no need to check for splitter_base and sgmii_adapter_base because the driver will fail if these 2 variables are not derived from the device tree. Fixes: fb3bbdb85989 ("net: ethernet: Add TSE PCS support to dwmac-socfpga") Signed-off-by: Dinh Nguyen Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/stmicro/stmmac/altr_tse_pcs.c | 8 -------- drivers/net/ethernet/stmicro/stmmac/altr_tse_pcs.h | 4 ++++ drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c | 13 +++++-------- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/altr_tse_pcs.c b/drivers/net/ethernet/stmicro/stmmac/altr_tse_pcs.c index 6a9c954492f2..6ca428a702f1 100644 --- a/drivers/net/ethernet/stmicro/stmmac/altr_tse_pcs.c +++ b/drivers/net/ethernet/stmicro/stmmac/altr_tse_pcs.c @@ -68,10 +68,6 @@ #define TSE_PCS_USE_SGMII_ENA BIT(0) #define TSE_PCS_IF_USE_SGMII 0x03 -#define SGMII_ADAPTER_CTRL_REG 0x00 -#define SGMII_ADAPTER_DISABLE 0x0001 -#define SGMII_ADAPTER_ENABLE 0x0000 - #define AUTONEGO_LINK_TIMER 20 static int tse_pcs_reset(void __iomem *base, struct tse_pcs *pcs) @@ -215,12 +211,8 @@ void tse_pcs_fix_mac_speed(struct tse_pcs *pcs, struct phy_device *phy_dev, unsigned int speed) { void __iomem *tse_pcs_base = pcs->tse_pcs_base; - void __iomem *sgmii_adapter_base = pcs->sgmii_adapter_base; u32 val; - writew(SGMII_ADAPTER_ENABLE, - sgmii_adapter_base + SGMII_ADAPTER_CTRL_REG); - pcs->autoneg = phy_dev->autoneg; if (phy_dev->autoneg == AUTONEG_ENABLE) { diff --git a/drivers/net/ethernet/stmicro/stmmac/altr_tse_pcs.h b/drivers/net/ethernet/stmicro/stmmac/altr_tse_pcs.h index 2f5882450b06..254199f2efdb 100644 --- a/drivers/net/ethernet/stmicro/stmmac/altr_tse_pcs.h +++ b/drivers/net/ethernet/stmicro/stmmac/altr_tse_pcs.h @@ -21,6 +21,10 @@ #include #include +#define SGMII_ADAPTER_CTRL_REG 0x00 +#define SGMII_ADAPTER_ENABLE 0x0000 +#define SGMII_ADAPTER_DISABLE 0x0001 + struct tse_pcs { struct device *dev; void __iomem *tse_pcs_base; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c index 33407df6bea6..32ead4a4b460 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c @@ -29,9 +29,6 @@ #include "altr_tse_pcs.h" -#define SGMII_ADAPTER_CTRL_REG 0x00 -#define SGMII_ADAPTER_DISABLE 0x0001 - #define SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_GMII_MII 0x0 #define SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RGMII 0x1 #define SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RMII 0x2 @@ -65,16 +62,14 @@ static void socfpga_dwmac_fix_mac_speed(void *priv, unsigned int speed) { struct socfpga_dwmac *dwmac = (struct socfpga_dwmac *)priv; void __iomem *splitter_base = dwmac->splitter_base; - void __iomem *tse_pcs_base = dwmac->pcs.tse_pcs_base; void __iomem *sgmii_adapter_base = dwmac->pcs.sgmii_adapter_base; struct device *dev = dwmac->dev; struct net_device *ndev = dev_get_drvdata(dev); struct phy_device *phy_dev = ndev->phydev; u32 val; - if ((tse_pcs_base) && (sgmii_adapter_base)) - writew(SGMII_ADAPTER_DISABLE, - sgmii_adapter_base + SGMII_ADAPTER_CTRL_REG); + writew(SGMII_ADAPTER_DISABLE, + sgmii_adapter_base + SGMII_ADAPTER_CTRL_REG); if (splitter_base) { val = readl(splitter_base + EMAC_SPLITTER_CTRL_REG); @@ -96,7 +91,9 @@ static void socfpga_dwmac_fix_mac_speed(void *priv, unsigned int speed) writel(val, splitter_base + EMAC_SPLITTER_CTRL_REG); } - if (tse_pcs_base && sgmii_adapter_base) + writew(SGMII_ADAPTER_ENABLE, + sgmii_adapter_base + SGMII_ADAPTER_CTRL_REG); + if (phy_dev) tse_pcs_fix_mac_speed(&dwmac->pcs, phy_dev, speed); } -- 2.35.1