Skip to content

Commit 9f3c3b4

Browse files
committed
Merge tag 'linux-can-fixes-for-5.13-20210506' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can
Marc Kleine-Budde says: ==================== pull-request: can 2021-05-06 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. * tag 'linux-can-fixes-for-5.13-20210506' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can: can: m_can: m_can_tx_work_queue(): fix tx_skb race condition can: mcp251x: fix resume from sleep before interface was brought up can: mcp251xfd: mcp251xfd_probe(): add missing can_rx_offload_del() in error path can: mcp251xfd: mcp251xfd_probe(): fix an error pointer dereference in probe ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 8621436 + e04b2cf commit 9f3c3b4

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

drivers/net/can/m_can/m_can.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,8 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev)
15621562
int i;
15631563
int putidx;
15641564

1565+
cdev->tx_skb = NULL;
1566+
15651567
/* Generate ID field for TX buffer Element */
15661568
/* Common to all supported M_CAN versions */
15671569
if (cf->can_id & CAN_EFF_FLAG) {
@@ -1678,7 +1680,6 @@ static void m_can_tx_work_queue(struct work_struct *ws)
16781680
tx_work);
16791681

16801682
m_can_tx_handler(cdev);
1681-
cdev->tx_skb = NULL;
16821683
}
16831684

16841685
static netdev_tx_t m_can_start_xmit(struct sk_buff *skb,

drivers/net/can/spi/mcp251x.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -956,8 +956,6 @@ static int mcp251x_stop(struct net_device *net)
956956

957957
priv->force_quit = 1;
958958
free_irq(spi->irq, priv);
959-
destroy_workqueue(priv->wq);
960-
priv->wq = NULL;
961959

962960
mutex_lock(&priv->mcp_lock);
963961

@@ -1224,24 +1222,15 @@ static int mcp251x_open(struct net_device *net)
12241222
goto out_close;
12251223
}
12261224

1227-
priv->wq = alloc_workqueue("mcp251x_wq", WQ_FREEZABLE | WQ_MEM_RECLAIM,
1228-
0);
1229-
if (!priv->wq) {
1230-
ret = -ENOMEM;
1231-
goto out_clean;
1232-
}
1233-
INIT_WORK(&priv->tx_work, mcp251x_tx_work_handler);
1234-
INIT_WORK(&priv->restart_work, mcp251x_restart_work_handler);
1235-
12361225
ret = mcp251x_hw_wake(spi);
12371226
if (ret)
1238-
goto out_free_wq;
1227+
goto out_free_irq;
12391228
ret = mcp251x_setup(net, spi);
12401229
if (ret)
1241-
goto out_free_wq;
1230+
goto out_free_irq;
12421231
ret = mcp251x_set_normal_mode(spi);
12431232
if (ret)
1244-
goto out_free_wq;
1233+
goto out_free_irq;
12451234

12461235
can_led_event(net, CAN_LED_EVENT_OPEN);
12471236

@@ -1250,9 +1239,7 @@ static int mcp251x_open(struct net_device *net)
12501239

12511240
return 0;
12521241

1253-
out_free_wq:
1254-
destroy_workqueue(priv->wq);
1255-
out_clean:
1242+
out_free_irq:
12561243
free_irq(spi->irq, priv);
12571244
mcp251x_hw_sleep(spi);
12581245
out_close:
@@ -1373,6 +1360,15 @@ static int mcp251x_can_probe(struct spi_device *spi)
13731360
if (ret)
13741361
goto out_clk;
13751362

1363+
priv->wq = alloc_workqueue("mcp251x_wq", WQ_FREEZABLE | WQ_MEM_RECLAIM,
1364+
0);
1365+
if (!priv->wq) {
1366+
ret = -ENOMEM;
1367+
goto out_clk;
1368+
}
1369+
INIT_WORK(&priv->tx_work, mcp251x_tx_work_handler);
1370+
INIT_WORK(&priv->restart_work, mcp251x_restart_work_handler);
1371+
13761372
priv->spi = spi;
13771373
mutex_init(&priv->mcp_lock);
13781374

@@ -1417,6 +1413,8 @@ static int mcp251x_can_probe(struct spi_device *spi)
14171413
return 0;
14181414

14191415
error_probe:
1416+
destroy_workqueue(priv->wq);
1417+
priv->wq = NULL;
14201418
mcp251x_power_enable(priv->power, 0);
14211419

14221420
out_clk:
@@ -1438,6 +1436,9 @@ static int mcp251x_can_remove(struct spi_device *spi)
14381436

14391437
mcp251x_power_enable(priv->power, 0);
14401438

1439+
destroy_workqueue(priv->wq);
1440+
priv->wq = NULL;
1441+
14411442
clk_disable_unprepare(priv->clk);
14421443

14431444
free_candev(net);

drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2885,8 +2885,8 @@ static int mcp251xfd_probe(struct spi_device *spi)
28852885

28862886
clk = devm_clk_get(&spi->dev, NULL);
28872887
if (IS_ERR(clk))
2888-
dev_err_probe(&spi->dev, PTR_ERR(clk),
2889-
"Failed to get Oscillator (clock)!\n");
2888+
return dev_err_probe(&spi->dev, PTR_ERR(clk),
2889+
"Failed to get Oscillator (clock)!\n");
28902890
freq = clk_get_rate(clk);
28912891

28922892
/* Sanity check */
@@ -2986,10 +2986,12 @@ static int mcp251xfd_probe(struct spi_device *spi)
29862986

29872987
err = mcp251xfd_register(priv);
29882988
if (err)
2989-
goto out_free_candev;
2989+
goto out_can_rx_offload_del;
29902990

29912991
return 0;
29922992

2993+
out_can_rx_offload_del:
2994+
can_rx_offload_del(&priv->offload);
29932995
out_free_candev:
29942996
spi->max_speed_hz = priv->spi_max_speed_hz_orig;
29952997

0 commit comments

Comments
 (0)