All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Claudiu Manoil <claudiu.manoil@nxp.com>,
	Vladimir Oltean <vladimir.oltean@nxp.com>,
	"David S . Miller" <davem@davemloft.net>,
	Sasha Levin <sashal@kernel.org>,
	netdev@vger.kernel.org
Subject: [PATCH AUTOSEL 5.6 28/47] felix: Fix initialization of ioremap resources
Date: Thu, 28 May 2020 07:55:41 -0400	[thread overview]
Message-ID: <20200528115600.1405808-28-sashal@kernel.org> (raw)
In-Reply-To: <20200528115600.1405808-1-sashal@kernel.org>

From: Claudiu Manoil <claudiu.manoil@nxp.com>

[ Upstream commit b4024c9e5c57902155d3b5e7de482e245f492bff ]

The caller of devm_ioremap_resource(), either accidentally
or by wrong assumption, is writing back derived resource data
to global static resource initialization tables that should
have been constant.  Meaning that after it computes the final
physical start address it saves the address for no reason
in the static tables.  This doesn't affect the first driver
probing after reboot, but it breaks consecutive driver reloads
(i.e. driver unbind & bind) because the initialization tables
no longer have the correct initial values.  So the next probe()
will map the device registers to wrong physical addresses,
causing ARM SError async exceptions.
This patch fixes all of the above.

Fixes: 56051948773e ("net: dsa: ocelot: add driver for Felix switch family")
Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Tested-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/net/dsa/ocelot/felix.c         | 23 +++++++++++------------
 drivers/net/dsa/ocelot/felix.h         |  6 +++---
 drivers/net/dsa/ocelot/felix_vsc9959.c | 22 ++++++++++------------
 3 files changed, 24 insertions(+), 27 deletions(-)

diff --git a/drivers/net/dsa/ocelot/felix.c b/drivers/net/dsa/ocelot/felix.c
index a7780c06fa65..b74580e87be8 100644
--- a/drivers/net/dsa/ocelot/felix.c
+++ b/drivers/net/dsa/ocelot/felix.c
@@ -385,6 +385,7 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports)
 	struct ocelot *ocelot = &felix->ocelot;
 	phy_interface_t *port_phy_modes;
 	resource_size_t switch_base;
+	struct resource res;
 	int port, i, err;
 
 	ocelot->num_phys_ports = num_phys_ports;
@@ -416,17 +417,16 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports)
 
 	for (i = 0; i < TARGET_MAX; i++) {
 		struct regmap *target;
-		struct resource *res;
 
 		if (!felix->info->target_io_res[i].name)
 			continue;
 
-		res = &felix->info->target_io_res[i];
-		res->flags = IORESOURCE_MEM;
-		res->start += switch_base;
-		res->end += switch_base;
+		memcpy(&res, &felix->info->target_io_res[i], sizeof(res));
+		res.flags = IORESOURCE_MEM;
+		res.start += switch_base;
+		res.end += switch_base;
 
-		target = ocelot_regmap_init(ocelot, res);
+		target = ocelot_regmap_init(ocelot, &res);
 		if (IS_ERR(target)) {
 			dev_err(ocelot->dev,
 				"Failed to map device memory space\n");
@@ -447,7 +447,6 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports)
 	for (port = 0; port < num_phys_ports; port++) {
 		struct ocelot_port *ocelot_port;
 		void __iomem *port_regs;
-		struct resource *res;
 
 		ocelot_port = devm_kzalloc(ocelot->dev,
 					   sizeof(struct ocelot_port),
@@ -459,12 +458,12 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports)
 			return -ENOMEM;
 		}
 
-		res = &felix->info->port_io_res[port];
-		res->flags = IORESOURCE_MEM;
-		res->start += switch_base;
-		res->end += switch_base;
+		memcpy(&res, &felix->info->port_io_res[port], sizeof(res));
+		res.flags = IORESOURCE_MEM;
+		res.start += switch_base;
+		res.end += switch_base;
 
-		port_regs = devm_ioremap_resource(ocelot->dev, res);
+		port_regs = devm_ioremap_resource(ocelot->dev, &res);
 		if (IS_ERR(port_regs)) {
 			dev_err(ocelot->dev,
 				"failed to map registers for port %d\n", port);
diff --git a/drivers/net/dsa/ocelot/felix.h b/drivers/net/dsa/ocelot/felix.h
index 8771d40324f1..2c024cc901d4 100644
--- a/drivers/net/dsa/ocelot/felix.h
+++ b/drivers/net/dsa/ocelot/felix.h
@@ -8,9 +8,9 @@
 
 /* Platform-specific information */
 struct felix_info {
-	struct resource			*target_io_res;
-	struct resource			*port_io_res;
-	struct resource			*imdio_res;
+	const struct resource		*target_io_res;
+	const struct resource		*port_io_res;
+	const struct resource		*imdio_res;
 	const struct reg_field		*regfields;
 	const u32 *const		*map;
 	const struct ocelot_ops		*ops;
diff --git a/drivers/net/dsa/ocelot/felix_vsc9959.c b/drivers/net/dsa/ocelot/felix_vsc9959.c
index edc1a67c002b..50074da3a1a0 100644
--- a/drivers/net/dsa/ocelot/felix_vsc9959.c
+++ b/drivers/net/dsa/ocelot/felix_vsc9959.c
@@ -328,10 +328,8 @@ static const u32 *vsc9959_regmap[] = {
 	[GCB]	= vsc9959_gcb_regmap,
 };
 
-/* Addresses are relative to the PCI device's base address and
- * will be fixed up at ioremap time.
- */
-static struct resource vsc9959_target_io_res[] = {
+/* Addresses are relative to the PCI device's base address */
+static const struct resource vsc9959_target_io_res[] = {
 	[ANA] = {
 		.start	= 0x0280000,
 		.end	= 0x028ffff,
@@ -374,7 +372,7 @@ static struct resource vsc9959_target_io_res[] = {
 	},
 };
 
-static struct resource vsc9959_port_io_res[] = {
+static const struct resource vsc9959_port_io_res[] = {
 	{
 		.start	= 0x0100000,
 		.end	= 0x010ffff,
@@ -410,7 +408,7 @@ static struct resource vsc9959_port_io_res[] = {
 /* Port MAC 0 Internal MDIO bus through which the SerDes acting as an
  * SGMII/QSGMII MAC PCS can be found.
  */
-static struct resource vsc9959_imdio_res = {
+static const struct resource vsc9959_imdio_res = {
 	.start		= 0x8030,
 	.end		= 0x8040,
 	.name		= "imdio",
@@ -984,7 +982,7 @@ static int vsc9959_mdio_bus_alloc(struct ocelot *ocelot)
 	struct device *dev = ocelot->dev;
 	resource_size_t imdio_base;
 	void __iomem *imdio_regs;
-	struct resource *res;
+	struct resource res;
 	struct enetc_hw *hw;
 	struct mii_bus *bus;
 	int port;
@@ -1001,12 +999,12 @@ static int vsc9959_mdio_bus_alloc(struct ocelot *ocelot)
 	imdio_base = pci_resource_start(felix->pdev,
 					felix->info->imdio_pci_bar);
 
-	res = felix->info->imdio_res;
-	res->flags = IORESOURCE_MEM;
-	res->start += imdio_base;
-	res->end += imdio_base;
+	memcpy(&res, felix->info->imdio_res, sizeof(res));
+	res.flags = IORESOURCE_MEM;
+	res.start += imdio_base;
+	res.end += imdio_base;
 
-	imdio_regs = devm_ioremap_resource(dev, res);
+	imdio_regs = devm_ioremap_resource(dev, &res);
 	if (IS_ERR(imdio_regs)) {
 		dev_err(dev, "failed to map internal MDIO registers\n");
 		return PTR_ERR(imdio_regs);
-- 
2.25.1


  parent reply	other threads:[~2020-05-28 11:57 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-28 11:55 [PATCH AUTOSEL 5.6 01/47] ARC: Fix ICCM & DCCM runtime size checks Sasha Levin
2020-05-28 11:55 ` Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 02/47] ARC: [plat-eznps]: Restrict to CONFIG_ISA_ARCOMPACT Sasha Levin
2020-05-28 11:55   ` Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 03/47] efi/libstub: Avoid returning uninitialized data from setup_graphics() Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 04/47] evm: Fix RCU list related warnings Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 05/47] scsi: pm: Balance pm_only counter of request queue during system resume Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 06/47] efi/earlycon: Fix early printk for wider fonts Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 07/47] x86/hyperv: Properly suspend/resume reenlightenment notifications Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 08/47] dmaengine: ti: k3-udma: Fix TR mode flags for slave_sg and memcpy Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 09/47] i2c: altera: Fix race between xfer_msg and isr thread Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 10/47] io_uring: initialize ctx->sqo_wait earlier Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 11/47] io_uring: don't prepare DRAIN reqs twice Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 12/47] io_uring: fix FORCE_ASYNC req preparation Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 13/47] net: phy: propagate an error back to the callers of phy_sfp_probe Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 14/47] net sched: fix reporting the first-time use timestamp Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 15/47] x86/mmiotrace: Use cpumask_available() for cpumask_var_t variables Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 16/47] net: bmac: Fix read of MAC address from ROM Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 17/47] r8152: support additional Microsoft Surface Ethernet Adapter variant Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 18/47] drm/edid: Add Oculus Rift S to non-desktop list Sasha Levin
2020-05-28 11:55   ` Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 19/47] s390/mm: fix set_huge_pte_at() for empty ptes Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 20/47] io_uring: reset -EBUSY error when io sq thread is waken up Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 21/47] drm/amd/display: DP training to set properly SCRAMBLING_DISABLE Sasha Levin
2020-05-28 11:55   ` Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 22/47] riscv: Fix print_vm_layout build error if NOMMU Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 23/47] wireguard: selftests: use newer iproute2 for gcc-10 Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 24/47] wireguard: queueing: preserve flow hash across packet scrubbing Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 25/47] null_blk: return error for invalid zone size Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 26/47] net: ethernet: ti: fix some return value check of cpsw_ale_create() Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 27/47] net: sgi: ioc3-eth: Fix return value check in ioc3eth_probe() Sasha Levin
2020-05-28 11:55 ` Sasha Levin [this message]
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 29/47] net: mvpp2: fix RX hashing for non-10G ports Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 30/47] net/ethernet/freescale: rework quiesce/activate for ucc_geth Sasha Levin
2020-05-28 11:55   ` Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 31/47] net: ethernet: stmmac: Enable interface clocks on probe for IPQ806x Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 32/47] mlxsw: spectrum: Fix use-after-free of split/unsplit/type_set in case reload fails Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 33/47] selftests: mlxsw: qos_mc_aware: Specify arping timeout as an integer Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 34/47] r8169: fix OCP access on RTL8117 Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 35/47] net: mscc: ocelot: fix address ageing time (again) Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 36/47] net: sun: fix missing release regions in cas_init_one() Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 37/47] net/mlx5: Add command entry handling completion Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 38/47] net/mlx5: Fix a race when moving command interface to events mode Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 39/47] net/mlx5e: Fix inner tirs handling Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 40/47] net/mlx5: Fix memory leak in mlx5_events_init Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 41/47] net/mlx5: Fix cleaning unmanaged flow tables Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 42/47] net/mlx5e: Update netdev txq on completions during closure Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 43/47] net/mlx5: Fix error flow in case of function_setup failure Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 44/47] net: Fix return value about devm_platform_ioremap_resource() Sasha Levin
2020-05-28 11:55   ` Sasha Levin
2020-05-28 11:55   ` Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 45/47] net: ethernet: ti: cpsw: fix ASSERT_RTNL() warning during suspend Sasha Levin
2020-05-28 11:55 ` [PATCH AUTOSEL 5.6 46/47] net/mlx4_core: fix a memory leak bug Sasha Levin
2020-05-28 11:56 ` [PATCH AUTOSEL 5.6 47/47] net: smsc911x: Fix runtime PM imbalance on error Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200528115600.1405808-28-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=claudiu.manoil@nxp.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=vladimir.oltean@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.