Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2353062pxb; Mon, 20 Sep 2021 19:50:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJbSRrn5ukbU2/UrtkyO0vkQeysr0uuLNdZ7cDi/ybSK9mzFTkGob7aDnyluEffL0T4WXF X-Received: by 2002:a02:5d45:: with SMTP id w66mr21846500jaa.82.1632192653157; Mon, 20 Sep 2021 19:50:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192653; cv=none; d=google.com; s=arc-20160816; b=hf2h5k47P9dTAJiSMsZ9zJDJ5uq7Pt5XhNQZdEUOGjKYFub5M1rp2ZVRqjmsI9t6W2 eRLBrIkwqDodh3LaFsVq1Pfb3LTgZ3TWD4UWzWUNGxDJmd0weUNJU3CQJYPf2YAUkLB4 vrjtitbRosMZREPYgT1VWhp5le9dJ8O2aXCuhFu+fsSjihpnxvJg2FRh+q+Hm97TNE6y tUQPufKeFyPvkFFbTMBwlU6tu6DjZUQtW9TU5+alfd6ir5hcTsOE903fSTJGKKdzHiS9 Wh6oG7ffFstXZLhWIsDf9G8Pjq2znNMlfSdaUvQMFbo46AXoQ1wihAZZ0FBa90CBwyz0 SPpw== 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=pFOAajA2a7URDrVY/NXUtE9LoADrgK6PsBxwfLkzJko=; b=JBkEhMlGD/ulde4nhZUgUSAxyOGNMoZV3Z/MX4YQMzdwUyzhKaLqHieKMQ+CBwbHyi OZ8JG+WDbhF3O2K6HKUcj+H8aLBz2mAO7aI1sh/Qgp7Ok+dCGQbGBIaaL8szowmGbT4d anCyj05hwAt0WnD+rZN/L0A0DhagU6vZ+chUAwDznuBd83hvFLo7F5cVwTCrSf9tBg0Y GbeHgWoY4CRqtvLdyqcUr9Rzy65IsFpE2UOMAxsAj1JKiJEbon+JMQ5CGdaZ0+AKusQa KXoVCUzTKBk4lThlFidwmMWW4GBFP9UXnOD6KfuLQQwXPdeOVuYHAis/1SjZhW4BY0NC gBvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VdUMEdl4; 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 r8si460362iob.24.2021.09.20.19.50.42; Mon, 20 Sep 2021 19:50:53 -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=VdUMEdl4; 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 S1383813AbhITSqD (ORCPT + 99 others); Mon, 20 Sep 2021 14:46:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:56460 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382801AbhITSmY (ORCPT ); Mon, 20 Sep 2021 14:42:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8CC2C61501; Mon, 20 Sep 2021 17:31:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632159116; bh=Di7UY+cfXsOr+OyDEehos6xzazNzv8QpkITODh5AWd0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VdUMEdl4pC1Bq0r4Bk58yHtx7buVqiRQXhBdt8JDbMPxvMIKpeUUYi/L+SXaayJtZ AJFUebWV7c6ExsDS9CR4RWRjahU/qyK5OVh5pHqqC3VkkGJC7PsVNAqRCZZJ0xZ6Ju VZ3zq1y4ngWl2LZFtbFTp02fI48XKSAMQvSvMfYY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ansuel Smith , "David S. Miller" , Sasha Levin Subject: [PATCH 5.14 083/168] net: dsa: qca8k: fix kernel panic with legacy mdio mapping Date: Mon, 20 Sep 2021 18:43:41 +0200 Message-Id: <20210920163924.366027280@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163921.633181900@linuxfoundation.org> References: <20210920163921.633181900@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: Ansuel Smith [ Upstream commit ce062a0adbfe933b1932235fdfd874c4c91d1bb0 ] When the mdio legacy mapping is used the mii_bus priv registered by DSA refer to the dsa switch struct instead of the qca8k_priv struct and causes a kernel panic. Create dedicated function when the internal dedicated mdio driver is used to properly handle the 2 different implementation. Fixes: 759bafb8a322 ("net: dsa: qca8k: add support for internal phy and internal mdio") Signed-off-by: Ansuel Smith Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/dsa/qca8k.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/drivers/net/dsa/qca8k.c b/drivers/net/dsa/qca8k.c index 1f63f50f73f1..bda5a9bf4f52 100644 --- a/drivers/net/dsa/qca8k.c +++ b/drivers/net/dsa/qca8k.c @@ -643,10 +643,8 @@ qca8k_mdio_busy_wait(struct mii_bus *bus, u32 reg, u32 mask) } static int -qca8k_mdio_write(struct mii_bus *salve_bus, int phy, int regnum, u16 data) +qca8k_mdio_write(struct mii_bus *bus, int phy, int regnum, u16 data) { - struct qca8k_priv *priv = salve_bus->priv; - struct mii_bus *bus = priv->bus; u16 r1, r2, page; u32 val; int ret; @@ -682,10 +680,8 @@ exit: } static int -qca8k_mdio_read(struct mii_bus *salve_bus, int phy, int regnum) +qca8k_mdio_read(struct mii_bus *bus, int phy, int regnum) { - struct qca8k_priv *priv = salve_bus->priv; - struct mii_bus *bus = priv->bus; u16 r1, r2, page; u32 val; int ret; @@ -726,6 +722,24 @@ exit: return ret; } +static int +qca8k_internal_mdio_write(struct mii_bus *slave_bus, int phy, int regnum, u16 data) +{ + struct qca8k_priv *priv = slave_bus->priv; + struct mii_bus *bus = priv->bus; + + return qca8k_mdio_write(bus, phy, regnum, data); +} + +static int +qca8k_internal_mdio_read(struct mii_bus *slave_bus, int phy, int regnum) +{ + struct qca8k_priv *priv = slave_bus->priv; + struct mii_bus *bus = priv->bus; + + return qca8k_mdio_read(bus, phy, regnum); +} + static int qca8k_phy_write(struct dsa_switch *ds, int port, int regnum, u16 data) { @@ -775,8 +789,8 @@ qca8k_mdio_register(struct qca8k_priv *priv, struct device_node *mdio) bus->priv = (void *)priv; bus->name = "qca8k slave mii"; - bus->read = qca8k_mdio_read; - bus->write = qca8k_mdio_write; + bus->read = qca8k_internal_mdio_read; + bus->write = qca8k_internal_mdio_write; snprintf(bus->id, MII_BUS_ID_SIZE, "qca8k-%d", ds->index); -- 2.30.2