Skip to contentSkip to conversation

pull-request: can 2021-05-06

PATCH New Marc Kleine-Budde 2 participants 6 messages May 6, 2021

Subsystems (5)
lore
Share & tools
lore

Marc Kleine-Budde

author maintainer
#0 lore raw

Hello Jakub, hello David,

this is a pull request of 4 patches for net/master.

The first two patches target the mcp251xfd driver. Dan Carpenter's patch fixes a NULL pointer dereference in the probe function's error path. A patch by me adds the missing can_rx_offload_del() in error path of the probe function.

Frieder Schrempf contributes a patch for the mcp251x driver, the patch fixes the resume from sleep before interface was brought up.

The last patch is by me and fixes a race condition in the TX path of the m_can driver for peripheral (SPI) based m_can cores.

regards,
Marc

---

The following changes since commit 8621436671f3a4bba5db57482e1ee604708bf1eb:

smc: disallow TCP_ULP in smc_setsockopt() (2021-05-05 12:52:45 -0700)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can.git tags/linux-can-fixes-for-5.13-20210506

for you to fetch changes up to e04b2cfe61072c7966e1a5fb73dd1feb30c206ed:

can: m_can: m_can_tx_work_queue(): fix tx_skb race condition (2021-05-06 09:24:07 +0200)

----------------------------------------------------------------
linux-can-fixes-for-5.13-20210506

----------------------------------------------------------------
Dan Carpenter (1):
can: mcp251xfd: mcp251xfd_probe(): fix an error pointer dereference in probe

Frieder Schrempf (1):
can: mcp251x: fix resume from sleep before interface was brought up

Marc Kleine-Budde (2):
can: mcp251xfd: mcp251xfd_probe(): add missing can_rx_offload_del() in error path
can: m_can: m_can_tx_work_queue(): fix tx_skb race condition

 drivers/net/can/m_can/m_can.c                  |  3 ++-
 drivers/net/can/spi/mcp251x.c                  | 35 +++++++++++++-------------
 drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c |  8 +++---
 3 files changed, 25 insertions(+), 21 deletions(-)
author maintainer
#1 lore raw

PATCH 1/4 can: mcp251xfd: mcp251xfd_probe(): fix an error pointer dereference in probe

From: Dan Carpenter <[email protected]>

When we converted this code to use dev_err_probe() we accidentally removed a return. It means that if devm_clk_get() it will lead to an Oops when we call clk_get_rate() on the next line.

Fixes cf8ee6de2543 ("can: mcp251xfd: mcp251xfd_probe(): use dev_err_probe() to simplify error handling")
---
 drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +2 -2
index 970dc570e7a5..f122976e90da 100644
@@ -2885,8 +2885,8 @@ static int mcp251xfd_probe(struct spi_device *spi)
 
 	clk = devm_clk_get(&spi->dev, NULL);
 	if (IS_ERR(clk))
-		dev_err_probe(&spi->dev, PTR_ERR(clk),
-			      "Failed to get Oscillator (clock)!\n");
+		return dev_err_probe(&spi->dev, PTR_ERR(clk),
+				     "Failed to get Oscillator (clock)!\n");
 	freq = clk_get_rate(clk);
 
 	/* Sanity check */

base-commit: 8621436671f3a4bba5db57482e1ee604708bf1eb

Signature · 1 line
2.30.2
author maintainer
#2 lore raw

PATCH 2/4 can: mcp251xfd: mcp251xfd_probe(): add missing can_rx_offload_del() in error path

In reply to Marc Kleine-Budde

This patch adds the missing can_rx_offload_del(), that must be called if mcp251xfd_register() fails.

Fixes 55e5b97f003e ("can: mcp25xxfd: add driver for Microchip MCP25xxFD SPI CAN")
---
 drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +3 -1
index f122976e90da..e0ae00e34c7b 100644
@@ -2986,10 +2986,12 @@ static int mcp251xfd_probe(struct spi_device *spi)
 
 	err = mcp251xfd_register(priv);
 	if (err)
-		goto out_free_candev;
+		goto out_can_rx_offload_del;
 
 	return 0;
 
+ out_can_rx_offload_del:
+	can_rx_offload_del(&priv->offload);
  out_free_candev:
 	spi->max_speed_hz = priv->spi_max_speed_hz_orig;
 
Signature · 1 line
2.30.2
author maintainer
#3 lore raw

PATCH 3/4 can: mcp251x: fix resume from sleep before interface was brought up

In reply to Marc Kleine-Budde

From: Frieder Schrempf <[email protected]>

Since 8ce8c0abcba3 the driver queues work via priv->restart_work when resuming after suspend, even when the interface was not previously enabled. This causes a null dereference error as the workqueue is only allocated and initialized in mcp251x_open().

To fix this we move the workqueue init to mcp251x_can_probe() as there is no reason to do it later and repeat it whenever mcp251x_open() is called.

Fixes 8ce8c0abcba3 ("can: mcp251x: only reset hardware as required")
[mkl: fix error handling in mcp251x_stop()]
---
 drivers/net/can/spi/mcp251x.c | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)
drivers/net/can/spi/mcp251x.c +18 -17
index 492f1bcb0516..173c6614086f 100644
@@ -956,8 +956,6 @@ static int mcp251x_stop(struct net_device *net)
 
 	priv->force_quit = 1;
 	free_irq(spi->irq, priv);
-	destroy_workqueue(priv->wq);
-	priv->wq = NULL;
 
 	mutex_lock(&priv->mcp_lock);
 
@@ -1224,24 +1222,15 @@ static int mcp251x_open(struct net_device *net)
 		goto out_close;
 	}
 
-	priv->wq = alloc_workqueue("mcp251x_wq", WQ_FREEZABLE | WQ_MEM_RECLAIM,
-				   0);
-	if (!priv->wq) {
-		ret = -ENOMEM;
-		goto out_clean;
-	}
-	INIT_WORK(&priv->tx_work, mcp251x_tx_work_handler);
-	INIT_WORK(&priv->restart_work, mcp251x_restart_work_handler);
-
 	ret = mcp251x_hw_wake(spi);
 	if (ret)
-		goto out_free_wq;
+		goto out_free_irq;
 	ret = mcp251x_setup(net, spi);
 	if (ret)
-		goto out_free_wq;
+		goto out_free_irq;
 	ret = mcp251x_set_normal_mode(spi);
 	if (ret)
-		goto out_free_wq;
+		goto out_free_irq;
 
 	can_led_event(net, CAN_LED_EVENT_OPEN);
 
@@ -1250,9 +1239,7 @@ static int mcp251x_open(struct net_device *net)
 
 	return 0;
 
-out_free_wq:
-	destroy_workqueue(priv->wq);
-out_clean:
+out_free_irq:
 	free_irq(spi->irq, priv);
 	mcp251x_hw_sleep(spi);
 out_close:
@@ -1373,6 +1360,15 @@ static int mcp251x_can_probe(struct spi_device *spi)
 	if (ret)
 		goto out_clk;
 
+	priv->wq = alloc_workqueue("mcp251x_wq", WQ_FREEZABLE | WQ_MEM_RECLAIM,
+				   0);
+	if (!priv->wq) {
+		ret = -ENOMEM;
+		goto out_clk;
+	}
+	INIT_WORK(&priv->tx_work, mcp251x_tx_work_handler);
+	INIT_WORK(&priv->restart_work, mcp251x_restart_work_handler);
+
 	priv->spi = spi;
 	mutex_init(&priv->mcp_lock);
 
@@ -1417,6 +1413,8 @@ static int mcp251x_can_probe(struct spi_device *spi)
 	return 0;
 
 error_probe:
+	destroy_workqueue(priv->wq);
+	priv->wq = NULL;
 	mcp251x_power_enable(priv->power, 0);
 
 out_clk:
@@ -1438,6 +1436,9 @@ static int mcp251x_can_remove(struct spi_device *spi)
 
 	mcp251x_power_enable(priv->power, 0);
 
+	destroy_workqueue(priv->wq);
+	priv->wq = NULL;
+
 	clk_disable_unprepare(priv->clk);
 
 	free_candev(net);
Signature · 1 line
2.30.2
author maintainer
#4 lore raw

PATCH 4/4 can: m_can: m_can_tx_work_queue(): fix tx_skb race condition

In reply to Marc Kleine-Budde

The m_can_start_xmit() function checks if the cdev->tx_skb is NULL and returns with NETDEV_TX_BUSY in case tx_sbk is not NULL.

There is a race condition in the m_can_tx_work_queue(), where first the skb is send to the driver and then the case tx_sbk is set to NULL. A TX complete IRQ might come in between and wake the queue, which results in tx_skb not being cleared yet.

Fixes f524f829b75a ("can: m_can: Create a m_can platform framework")
---
 drivers/net/can/m_can/m_can.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/can/m_can/m_can.c +2 -1
index 34073cd077e4..3cf6de21d19c 100644
@@ -1562,6 +1562,8 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev)
 	int i;
 	int putidx;
 
+	cdev->tx_skb = NULL;
+
 	/* Generate ID field for TX buffer Element */
 	/* Common to all supported M_CAN versions */
 	if (cf->can_id & CAN_EFF_FLAG) {
@@ -1678,7 +1680,6 @@ static void m_can_tx_work_queue(struct work_struct *ws)
 						   tx_work);
 
 	m_can_tx_handler(cdev);
-	cdev->tx_skb = NULL;
 }
 
 static netdev_tx_t m_can_start_xmit(struct sk_buff *skb,
Signature · 1 line
2.30.2
#5 lore raw
In reply to Marc Kleine-Budde
This pull request was applied to netdev/net.git (refs/heads/master):

Hello:

This pull request was applied to netdev/net.git (refs/heads/master):

Quoted 10 lines · On Thu, 6 May 2021 09:40:11 +0200 you wrote:

Hello Jakub, hello David,

this is a pull request of 4 patches for net/master.

The first two patches target the mcp251xfd driver. Dan Carpenter's patch fixes a NULL pointer dereference in the probe function's error path. A patch by me adds the missing can_rx_offload_del() in error path of the probe function.

[...]

Here is the summary with links:
- pull-request: can 2021-05-06

    https://git.kernel.org/netdev/net/c/9f3c3b423567
  - [net,2/4] can: mcp251xfd: mcp251xfd_probe(): add missing can_rx_offload_del() in error path
    https://git.kernel.org/netdev/net/c/4376ea42db8b
  - [net,3/4] can: mcp251x: fix resume from sleep before interface was brought up
    https://git.kernel.org/netdev/net/c/03c427147b2d
  - [net,4/4] can: m_can: m_can_tx_work_queue(): fix tx_skb race condition
    https://git.kernel.org/netdev/net/c/e04b2cfe6107

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html