Skip to contentSkip to conversation

pull-request: can 2020-11-15

PATCH In review Marc Kleine-Budde 3 participants 21 messages Nov 15, 2020 – Nov 17, 2020

Subsystems (6)
lore
Share & tools
lore

Marc Kleine-Budde

author maintainer
#0 lore raw

Hello Jakub, hello David,

here's a pull request for net/master consisting of 15 patches for net/master, with the fixes tags corrected.

Anant Thazhemadam contributed two patches for the AF_CAN that prevent potential access of uninitialized member in can_rcv() and canfd_rcv().

The next patch is by Alejandro Concepcion Rodriguez and changes can_restart() to use the correct function to push a skb into the networking stack from process context.

Zhang Qilong's patch fixes a memory leak in the error path of the ti_hecc's probe function.

A patch by me fixes mcba_usb_start_xmit() function in the mcba_usb driver, to first fill the skb and then pass it to can_put_echo_skb().

Colin Ian King's patch fixes a potential integer overflow on shift in the peak_usb driver.

The next two patches target the flexcan driver, a patch by me adds the missing "req_bit" to the stop mode property comment (which was broken during net-next for v5.10). Zhang Qilong's patch fixes the failure handling of pm_runtime_get_sync().

The next seven patches target the m_can driver including the tcan4x5x spi driver glue code. Enric Balletbo i Serra's patch for the tcan4x5x Kconfig fix the REGMAP_SPI dependency handling. A patch by me for the tcan4x5x driver's probe() function adds missing error handling to for devm_regmap_init(), and in tcan4x5x_can_remove() the order of deregistration is fixed. Wu Bo's patch for the m_can driver fixes the state change handling in m_can_handle_state_change(). Two patches by Dan Murphy first introduce m_can_class_free_dev() and then make use of it to fix the freeing of the can device. A patch by Faiz Abbas add a missing shutdown of the CAN controller in the m_can_stop() function.

regards,
Marc

---

The following changes since commit ceb736e1d45c253f5e86b185ca9b497cdd43063f:

ipv6: Fix error path to cancel the meseage (2020-11-13 18:20:00 -0800)

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.10-20201115

for you to fetch changes up to a584e9bc1b7e88f24f8504886eafbe6c73d8a97c:

can: m_can: m_can_stop(): set device to software init mode before closing (2020-11-15 18:33:45 +0100)

----------------------------------------------------------------
linux-can-fixes-for-5.10-20201115

----------------------------------------------------------------
Alejandro Concepcion Rodriguez (1):
can: dev: can_restart(): post buffer from the right context

Anant Thazhemadam (2):
can: af_can: prevent potential access of uninitialized member in can_rcv()
can: af_can: prevent potential access of uninitialized member in canfd_rcv()

Colin Ian King (1):
can: peak_usb: fix potential integer overflow on shift of a int

Dan Murphy (2):
can: m_can: m_can_class_free_dev(): introduce new function
can: m_can: Fix freeing of can device from peripherials

Enric Balletbo i Serra (1):
can: tcan4x5x: replace depends on REGMAP_SPI with depends on SPI

Faiz Abbas (1):
can: m_can: m_can_stop(): set device to software init mode before closing

Marc Kleine-Budde (4):
can: mcba_usb: mcba_usb_start_xmit(): first fill skb, then pass to can_put_echo_skb()
can: flexcan: flexcan_setup_stop_mode(): add missing "req_bit" to stop mode property comment
can: tcan4x5x: tcan4x5x_can_probe(): add missing error checking for devm_regmap_init()
can: tcan4x5x: tcan4x5x_can_remove(): fix order of deregistration

Wu Bo (1):
can: m_can: m_can_handle_state_change(): fix state change

Zhang Qilong (2):
can: ti_hecc: Fix memleak in ti_hecc_probe
can: flexcan: fix failure handling of pm_runtime_get_sync()

 drivers/net/can/dev.c                        |  2 +-
 drivers/net/can/flexcan.c                    | 10 +++++---
 drivers/net/can/m_can/Kconfig                |  3 ++-
 drivers/net/can/m_can/m_can.c                | 16 ++++++++----
 drivers/net/can/m_can/m_can.h                |  1 +
 drivers/net/can/m_can/m_can_platform.c       | 23 +++++++++++------
 drivers/net/can/m_can/tcan4x5x.c             | 32 ++++++++++++++++-------
 drivers/net/can/ti_hecc.c                    | 13 ++++++----
 drivers/net/can/usb/mcba_usb.c               |  4 +--
 drivers/net/can/usb/peak_usb/pcan_usb_core.c |  4 +--
 net/can/af_can.c                             | 38 ++++++++++++++++++++--------
 11 files changed, 100 insertions(+), 46 deletions(-)
author maintainer
#1 lore raw

PATCH 1/15 can: af_can: prevent potential access of uninitialized member in can_rcv()

From: Anant Thazhemadam <[email protected]>

In can_rcv(), cfd->len is uninitialized when skb->len = 0, and this uninitialized cfd->len is accessed nonetheless by pr_warn_once().

Fix this uninitialized variable access by checking cfd->len's validity condition (cfd->len > CAN_MAX_DLEN) separately after the skb->len's condition is checked, and appropriately modify the log messages that are generated as well.
In case either of the required conditions fail, the skb is freed and NET_RX_DROP is returned, same as before.

Fixes 8cb68751c115 ("can: af_can: can_rcv(): replace WARN_ONCE by pr_warn_once")
Reported-by [email protected]
---
 net/can/af_can.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
net/can/af_can.c +14 -5
index 6373ab9c5507..e8d4e3ef5322 100644
@@ -677,16 +677,25 @@ static int can_rcv(struct sk_buff *skb, struct net_device *dev,
 {
 	struct canfd_frame *cfd = (struct canfd_frame *)skb->data;
 
-	if (unlikely(dev->type != ARPHRD_CAN || skb->len != CAN_MTU ||
-		     cfd->len > CAN_MAX_DLEN)) {
-		pr_warn_once("PF_CAN: dropped non conform CAN skbuf: dev type %d, len %d, datalen %d\n",
+	if (unlikely(dev->type != ARPHRD_CAN || skb->len != CAN_MTU)) {
+		pr_warn_once("PF_CAN: dropped non conform CAN skbuff: dev type %d, len %d\n",
+			     dev->type, skb->len);
+		goto free_skb;
+	}
+
+	/* This check is made separately since cfd->len would be uninitialized if skb->len = 0. */
+	if (unlikely(cfd->len > CAN_MAX_DLEN)) {
+		pr_warn_once("PF_CAN: dropped non conform CAN skbuff: dev type %d, len %d, datalen %d\n",
 			     dev->type, skb->len, cfd->len);
-		kfree_skb(skb);
-		return NET_RX_DROP;
+		goto free_skb;
 	}
 
 	can_receive(skb, dev);
 	return NET_RX_SUCCESS;
+
+free_skb:
+	kfree_skb(skb);
+	return NET_RX_DROP;
 }
 
 static int canfd_rcv(struct sk_buff *skb, struct net_device *dev,

base-commit: ceb736e1d45c253f5e86b185ca9b497cdd43063f

Signature · 1 line
2.29.2
author maintainer
#2 lore raw

PATCH 2/15 can: af_can: prevent potential access of uninitialized member in canfd_rcv()

In reply to Marc Kleine-Budde

From: Anant Thazhemadam <[email protected]>

In canfd_rcv(), cfd->len is uninitialized when skb->len = 0, and this uninitialized cfd->len is accessed nonetheless by pr_warn_once().

Fix this uninitialized variable access by checking cfd->len's validity condition (cfd->len > CANFD_MAX_DLEN) separately after the skb->len's condition is checked, and appropriately modify the log messages that are generated as well.
In case either of the required conditions fail, the skb is freed and NET_RX_DROP is returned, same as before.

Fixes d4689846881d ("can: af_can: canfd_rcv(): replace WARN_ONCE by pr_warn_once")
Reported-by [email protected]
---
 net/can/af_can.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
net/can/af_can.c +14 -5
index e8d4e3ef5322..5d124c155904 100644
@@ -703,16 +703,25 @@ static int canfd_rcv(struct sk_buff *skb, struct net_device *dev,
 {
 	struct canfd_frame *cfd = (struct canfd_frame *)skb->data;
 
-	if (unlikely(dev->type != ARPHRD_CAN || skb->len != CANFD_MTU ||
-		     cfd->len > CANFD_MAX_DLEN)) {
-		pr_warn_once("PF_CAN: dropped non conform CAN FD skbuf: dev type %d, len %d, datalen %d\n",
+	if (unlikely(dev->type != ARPHRD_CAN || skb->len != CANFD_MTU)) {
+		pr_warn_once("PF_CAN: dropped non conform CAN FD skbuff: dev type %d, len %d\n",
+			     dev->type, skb->len);
+		goto free_skb;
+	}
+
+	/* This check is made separately since cfd->len would be uninitialized if skb->len = 0. */
+	if (unlikely(cfd->len > CANFD_MAX_DLEN)) {
+		pr_warn_once("PF_CAN: dropped non conform CAN FD skbuff: dev type %d, len %d, datalen %d\n",
 			     dev->type, skb->len, cfd->len);
-		kfree_skb(skb);
-		return NET_RX_DROP;
+		goto free_skb;
 	}
 
 	can_receive(skb, dev);
 	return NET_RX_SUCCESS;
+
+free_skb:
+	kfree_skb(skb);
+	return NET_RX_DROP;
 }
 
 /* af_can protocol functions */
Signature · 1 line
2.29.2
author maintainer
#3 lore raw

PATCH 3/15 can: dev: can_restart(): post buffer from the right context

In reply to Marc Kleine-Budde

From: Alejandro Concepcion Rodriguez <[email protected]>

netif_rx() is meant to be called from interrupt contexts. can_restart() may be called by can_restart_work(), which is called from a worqueue, so it may run in process context. Use netif_rx_ni() instead.

Fixes 39549eef3587 ("can: CAN Network device driver and Netlink interface")
[mkl: use netif_rx_ni() instead of netif_rx_any_context()]
---
 drivers/net/can/dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/dev.c +1 -1
index 6dee4f8f2024..81e39d7507d8 100644
@@ -592,7 +592,7 @@ static void can_restart(struct net_device *dev)
 
 	cf->can_id |= CAN_ERR_RESTARTED;
 
-	netif_rx(skb);
+	netif_rx_ni(skb);
 
 	stats->rx_packets++;
 	stats->rx_bytes += cf->can_dlc;
Signature · 1 line
2.29.2
author maintainer
#4 lore raw

PATCH 4/15 can: ti_hecc: Fix memleak in ti_hecc_probe

In reply to Marc Kleine-Budde

From: Zhang Qilong <[email protected]>

In the error handling, we should goto the probe_exit_candev to free ndev to prevent memory leak.

Fixes dabf54dd1c63 ("can: ti_hecc: Convert TI HECC driver to DT only driver")
---
 drivers/net/can/ti_hecc.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/net/can/ti_hecc.c +8 -5
index 9913f5458279..2c22f40e12bd 100644
@@ -881,7 +881,8 @@ static int ti_hecc_probe(struct platform_device *pdev)
 	priv->base = devm_platform_ioremap_resource_byname(pdev, "hecc");
 	if (IS_ERR(priv->base)) {
 		dev_err(&pdev->dev, "hecc ioremap failed\n");
-		return PTR_ERR(priv->base);
+		err = PTR_ERR(priv->base);
+		goto probe_exit_candev;
 	}
 
 	/* handle hecc-ram memory */
@@ -889,20 +890,22 @@ static int ti_hecc_probe(struct platform_device *pdev)
 							       "hecc-ram");
 	if (IS_ERR(priv->hecc_ram)) {
 		dev_err(&pdev->dev, "hecc-ram ioremap failed\n");
-		return PTR_ERR(priv->hecc_ram);
+		err = PTR_ERR(priv->hecc_ram);
+		goto probe_exit_candev;
 	}
 
 	/* handle mbx memory */
 	priv->mbx = devm_platform_ioremap_resource_byname(pdev, "mbx");
 	if (IS_ERR(priv->mbx)) {
 		dev_err(&pdev->dev, "mbx ioremap failed\n");
-		return PTR_ERR(priv->mbx);
+		err = PTR_ERR(priv->mbx);
+		goto probe_exit_candev;
 	}
 
 	irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
 	if (!irq) {
 		dev_err(&pdev->dev, "No irq resource\n");
-		goto probe_exit;
+		goto probe_exit_candev;
 	}
 
 	priv->ndev = ndev;
@@ -966,7 +969,7 @@ static int ti_hecc_probe(struct platform_device *pdev)
 	clk_put(priv->clk);
 probe_exit_candev:
 	free_candev(ndev);
-probe_exit:
+
 	return err;
 }
 
Signature · 1 line
2.29.2
author maintainer
#5 lore raw

PATCH 5/15 can: mcba_usb: mcba_usb_start_xmit(): first fill skb, then pass to can_put_echo_skb()

In reply to Marc Kleine-Budde

The driver has to first fill the skb with data and then handle it to can_put_echo_skb(). This patch moves the can_put_echo_skb() down, right before sending the skb out via USB.

Fixes 51f3baad7de9 ("can: mcba_usb: Add support for Microchip CAN BUS Analyzer")
Cc Remigiusz Kołłątaj <[email protected]>
---
 drivers/net/can/usb/mcba_usb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/can/usb/mcba_usb.c +2 -2
index 5857b37dcd96..e97f2e0da6b0 100644
@@ -326,8 +326,6 @@ static netdev_tx_t mcba_usb_start_xmit(struct sk_buff *skb,
 	if (!ctx)
 		return NETDEV_TX_BUSY;
 
-	can_put_echo_skb(skb, priv->netdev, ctx->ndx);
-
 	if (cf->can_id & CAN_EFF_FLAG) {
 		/* SIDH    | SIDL                 | EIDH   | EIDL
 		 * 28 - 21 | 20 19 18 x x x 17 16 | 15 - 8 | 7 - 0
@@ -357,6 +355,8 @@ static netdev_tx_t mcba_usb_start_xmit(struct sk_buff *skb,
 	if (cf->can_id & CAN_RTR_FLAG)
 		usb_msg.dlc |= MCBA_DLC_RTR_MASK;
 
+	can_put_echo_skb(skb, priv->netdev, ctx->ndx);
+
 	err = mcba_usb_xmit(priv, (struct mcba_usb_msg *)&usb_msg, ctx);
 	if (err)
 		goto xmit_failed;
Signature · 1 line
2.29.2
author maintainer
#6 lore raw

PATCH 6/15 can: peak_usb: fix potential integer overflow on shift of a int

In reply to Marc Kleine-Budde

From: Colin Ian King <[email protected]>

The left shift of int 32 bit integer constant 1 is evaluated using 32 bit arithmetic and then assigned to a signed 64 bit variable. In the case where time_ref->adapter->ts_used_bits is 32 or more this can lead to an oveflow. Avoid this by shifting using the BIT_ULL macro instead.

Fixes bb4785551f64 ("can: usb: PEAK-System Technik USB adapters driver core")
---
 drivers/net/can/usb/peak_usb/pcan_usb_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/can/usb/peak_usb/pcan_usb_core.c +2 -2
index c2764799f9ef..204ccb27d6d9 100644
@@ -156,7 +156,7 @@ void peak_usb_get_ts_time(struct peak_time_ref *time_ref, u32 ts, ktime_t *time)
 		if (time_ref->ts_dev_1 < time_ref->ts_dev_2) {
 			/* case when event time (tsw) wraps */
 			if (ts < time_ref->ts_dev_1)
-				delta_ts = 1 << time_ref->adapter->ts_used_bits;
+				delta_ts = BIT_ULL(time_ref->adapter->ts_used_bits);
 
 		/* Otherwise, sync time counter (ts_dev_2) has wrapped:
 		 * handle case when event time (tsn) hasn't.
@@ -168,7 +168,7 @@ void peak_usb_get_ts_time(struct peak_time_ref *time_ref, u32 ts, ktime_t *time)
 		 *              tsn            ts
 		 */
 		} else if (time_ref->ts_dev_1 < ts) {
-			delta_ts = -(1 << time_ref->adapter->ts_used_bits);
+			delta_ts = -BIT_ULL(time_ref->adapter->ts_used_bits);
 		}
 
 		/* add delay between last sync and event timestamps */
Signature · 1 line
2.29.2
author maintainer
#7 lore raw

PATCH 7/15 can: flexcan: flexcan_setup_stop_mode(): add missing "req_bit" to stop mode property comment

In reply to Marc Kleine-Budde

In the patch

d9b081e3fc4b ("can: flexcan: remove ack_grp and ack_bit handling from driver")

the unused ack_grp and ack_bit were removed from the driver. However in the comment, the "req_bit" was accidentally removed, too.

This patch adds back the "req_bit" bit.

Fixes d9b081e3fc4b ("can: flexcan: remove ack_grp and ack_bit handling from driver")
---
 drivers/net/can/flexcan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/flexcan.c +1 -1
index 881799bd9c5e..4e8fdb6064bd 100644
@@ -1852,7 +1852,7 @@ static int flexcan_setup_stop_mode(struct platform_device *pdev)
 		return -EINVAL;
 
 	/* stop mode property format is:
-	 * <&gpr req_gpr>.
+	 * <&gpr req_gpr req_bit>.
 	 */
 	ret = of_property_read_u32_array(np, "fsl,stop-mode", out_val,
 					 ARRAY_SIZE(out_val));
Signature · 1 line
2.29.2
author maintainer
#8 lore raw

PATCH 8/15 can: flexcan: fix failure handling of pm_runtime_get_sync()

In reply to Marc Kleine-Budde

From: Zhang Qilong <[email protected]>

pm_runtime_get_sync() will increment pm usage at first and it will resume the device later. If runtime of the device has error or device is in inaccessible state(or other error state), resume operation will fail. If we do not call put operation to decrease the reference, it will result in reference leak in the two functions flexcan_get_berr_counter() and flexcan_open().

Moreover, this device cannot enter the idle state and always stay busy or other non-idle state later. So we should fix it through adding pm_runtime_put_noidle().

Fixes ca10989632d88 ("can: flexcan: implement can Runtime PM")
---
 drivers/net/can/flexcan.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/can/flexcan.c +6 -2
index 4e8fdb6064bd..d6a9cf0e9b60 100644
@@ -728,8 +728,10 @@ static int flexcan_get_berr_counter(const struct net_device *dev,
 	int err;
 
 	err = pm_runtime_get_sync(priv->dev);
-	if (err < 0)
+	if (err < 0) {
+		pm_runtime_put_noidle(priv->dev);
 		return err;
+	}
 
 	err = __flexcan_get_berr_counter(dev, bec);
 
@@ -1654,8 +1656,10 @@ static int flexcan_open(struct net_device *dev)
 	}
 
 	err = pm_runtime_get_sync(priv->dev);
-	if (err < 0)
+	if (err < 0) {
+		pm_runtime_put_noidle(priv->dev);
 		return err;
+	}
 
 	err = open_candev(dev);
 	if (err)
Signature · 1 line
2.29.2
author maintainer
#9 lore raw

PATCH 9/15 can: tcan4x5x: replace depends on REGMAP_SPI with depends on SPI

In reply to Marc Kleine-Budde

From: Enric Balletbo i Serra <[email protected]>

regmap is a library function that gets selected by drivers that need it. No driver modules should depend on it. Instead depends on SPI and select REGMAP_SPI. Depending on REGMAP_SPI makes this driver only build if another driver already selected REGMAP_SPI, as the symbol can't be selected through the menu kernel configuration.

Fixes 5443c226ba91 ("can: tcan4x5x: Add tcan4x5x driver to the kernel")
---
 drivers/net/can/m_can/Kconfig | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/can/m_can/Kconfig +2 -1
index 48be627c85c2..5f9f8192dd0b 100644
@@ -16,7 +16,8 @@ config CAN_M_CAN_PLATFORM
 
 config CAN_M_CAN_TCAN4X5X
 	depends on CAN_M_CAN
-	depends on REGMAP_SPI
+	depends on SPI
+	select REGMAP_SPI
 	tristate "TCAN4X5X M_CAN device"
 	help
 	  Say Y here if you want support for Texas Instruments TCAN4x5x
Signature · 1 line
2.29.2
author maintainer
#10 lore raw

PATCH 10/15 can: tcan4x5x: tcan4x5x_can_probe(): add missing error checking for devm_regmap_init()

In reply to Marc Kleine-Budde

This patch adds the missing error checking when initializing the regmap interface fails.

Fixes 5443c226ba91 ("can: tcan4x5x: Add tcan4x5x driver to the kernel")
Cc Dan Murphy <[email protected]>
---
 drivers/net/can/m_can/tcan4x5x.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/can/m_can/tcan4x5x.c +4 -0
index eacd428e07e9..f058bd9104e9 100644
@@ -487,6 +487,10 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
 
 	priv->regmap = devm_regmap_init(&spi->dev, &tcan4x5x_bus,
 					&spi->dev, &tcan4x5x_regmap);
+	if (IS_ERR(priv->regmap)) {
+		ret = PTR_ERR(priv->regmap);
+		goto out_clk;
+	}
 
 	ret = tcan4x5x_power_enable(priv->power, 1);
 	if (ret)
Signature · 1 line
2.29.2
Reviewed-by on v1 10/15
#11 lore raw

Re: [net 10/15] can: tcan4x5x: tcan4x5x_can_probe(): add missing error checking for devm_regmap_init()

Marc

Quoted 16 lines · Marc Kleine-Budde

This patch adds the missing error checking when initializing the regmap interface fails.

Fixes 5443c226ba91 ("can: tcan4x5x: Add tcan4x5x driver to the kernel")
Cc Dan Murphy <[email protected]>
---
  drivers/net/can/m_can/tcan4x5x.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/net/can/m_can/tcan4x5x.c +0 -0
index eacd428e07e9..f058bd9104e9 100644

drivers/net/can/m_can/tcan4x5x.c static int tcan4x5x_can_probe(struct spi_device *spi) · line 496

Quoted 10 lines
drivers/net/can/m_can/tcan4x5x.c +4 -0
@@ -487,6 +487,10 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
 
  	priv->regmap = devm_regmap_init(&spi->dev, &tcan4x5x_bus,
  					&spi->dev, &tcan4x5x_regmap);
+	if (IS_ERR(priv->regmap)) {
+		ret = PTR_ERR(priv->regmap);
+		goto out_clk;
+	}
 
  	ret = tcan4x5x_power_enable(priv->power, 1);
  	if (ret)
author maintainer
#12 lore raw

PATCH 11/15 can: tcan4x5x: tcan4x5x_can_remove(): fix order of deregistration

In reply to Marc Kleine-Budde

Change the order in tcan4x5x_can_remove() to be the exact inverse of tcan4x5x_can_probe(). First m_can_class_unregister(), then power down the device.

Fixes 5443c226ba91 ("can: tcan4x5x: Add tcan4x5x driver to the kernel")
Cc Dan Murphy <[email protected]>
---
 drivers/net/can/m_can/tcan4x5x.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/can/m_can/tcan4x5x.c +2 -2
index f058bd9104e9..4fdb7121403a 100644
@@ -527,10 +527,10 @@ static int tcan4x5x_can_remove(struct spi_device *spi)
 {
 	struct tcan4x5x_priv *priv = spi_get_drvdata(spi);
 
-	tcan4x5x_power_enable(priv->power, 0);
-
 	m_can_class_unregister(priv->mcan_dev);
 
+	tcan4x5x_power_enable(priv->power, 0);
+
 	return 0;
 }
 
Signature · 1 line
2.29.2
Reviewed-by on v1 11/15
#13 lore raw

Re: [net 11/15] can: tcan4x5x: tcan4x5x_can_remove(): fix order of deregistration

Marc

Quoted 19 lines · Marc Kleine-Budde

Change the order in tcan4x5x_can_remove() to be the exact inverse of tcan4x5x_can_probe(). First m_can_class_unregister(), then power down the device.

Fixes 5443c226ba91 ("can: tcan4x5x: Add tcan4x5x driver to the kernel")
Cc Dan Murphy <[email protected]>
---
  drivers/net/can/m_can/tcan4x5x.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/can/m_can/tcan4x5x.c +0 -0
index f058bd9104e9..4fdb7121403a 100644
@@ -527,10 +527,10 @@ static int tcan4x5x_can_remove(struct spi_device *spi)
  {
  	struct tcan4x5x_priv *priv = spi_get_drvdata(spi);

drivers/net/can/m_can/tcan4x5x.c static int tcan4x5x_can_remove(struct spi_device *spi) · line 536

Quoted 10 lines
drivers/net/can/m_can/tcan4x5x.c +2 -2
 
-	tcan4x5x_power_enable(priv->power, 0);
-
  	m_can_class_unregister(priv->mcan_dev);
 
+	tcan4x5x_power_enable(priv->power, 0);
+
  	return 0;
  }
 
author maintainer
#14 lore raw

Re: [net 11/15] can: tcan4x5x: tcan4x5x_can_remove(): fix order of deregistration

Quoted 1 line · Dan Murphy

Thanks. The patches are already mainline.

regards,
Marc

Signature · 4 lines
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |
author maintainer
#15 lore raw

PATCH 12/15 can: m_can: m_can_handle_state_change(): fix state change

In reply to Marc Kleine-Budde

From: Wu Bo <[email protected]>

m_can_handle_state_change() is called with the new_state as an argument.

In the switch statements for CAN_STATE_ERROR_ACTIVE, the comment and the following code indicate that a CAN_STATE_ERROR_WARNING is handled.

This patch fixes this problem by changing the case to CAN_STATE_ERROR_WARNING.

Cc Dan Murphy <[email protected]>
Fixes e0d1f4816f2a ("can: m_can: add Bosch M_CAN controller support")
---
 drivers/net/can/m_can/m_can.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/can/m_can/m_can.c +2 -2
index 02c5795b7393..63887e23d89c 100644
@@ -665,7 +665,7 @@ static int m_can_handle_state_change(struct net_device *dev,
 	unsigned int ecr;
 
 	switch (new_state) {
-	case CAN_STATE_ERROR_ACTIVE:
+	case CAN_STATE_ERROR_WARNING:
 		/* error warning state */
 		cdev->can.can_stats.error_warning++;
 		cdev->can.state = CAN_STATE_ERROR_WARNING;
@@ -694,7 +694,7 @@ static int m_can_handle_state_change(struct net_device *dev,
 	__m_can_get_berr_counter(dev, &bec);
 
 	switch (new_state) {
-	case CAN_STATE_ERROR_ACTIVE:
+	case CAN_STATE_ERROR_WARNING:
 		/* error warning state */
 		cf->can_id |= CAN_ERR_CRTL;
 		cf->data[1] = (bec.txerr > bec.rxerr) ?
Signature · 1 line
2.29.2
Reviewed-by on v1 12/15
#16 lore raw

Re: [net 12/15] can: m_can: m_can_handle_state_change(): fix state change

Marc

Quoted 32 lines · Marc Kleine-Budde

From: Wu Bo <[email protected]>

m_can_handle_state_change() is called with the new_state as an argument.

In the switch statements for CAN_STATE_ERROR_ACTIVE, the comment and the following code indicate that a CAN_STATE_ERROR_WARNING is handled.

This patch fixes this problem by changing the case to CAN_STATE_ERROR_WARNING.

Cc Dan Murphy <[email protected]>
Fixes e0d1f4816f2a ("can: m_can: add Bosch M_CAN controller support")
---
  drivers/net/can/m_can/m_can.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/can/m_can/m_can.c +1 -1
index 02c5795b7393..63887e23d89c 100644
@@ -665,7 +665,7 @@ static int m_can_handle_state_change(struct net_device *dev,
  	unsigned int ecr;
 
  	switch (new_state) {
-	case CAN_STATE_ERROR_ACTIVE:
+	case CAN_STATE_ERROR_WARNING:
  		/* error warning state */
  		cdev->can.can_stats.error_warning++;
  		cdev->can.state = CAN_STATE_ERROR_WARNING;

drivers/net/can/m_can/m_can.c static int m_can_handle_state_change(struct net_device *dev, · line 700

Quoted 8 lines
drivers/net/can/m_can/m_can.c +1 -1
@@ -694,7 +694,7 @@ static int m_can_handle_state_change(struct net_device *dev,
  	__m_can_get_berr_counter(dev, &bec);
 
  	switch (new_state) {
-	case CAN_STATE_ERROR_ACTIVE:
+	case CAN_STATE_ERROR_WARNING:
  		/* error warning state */
  		cf->can_id |= CAN_ERR_CRTL;
  		cf->data[1] = (bec.txerr > bec.rxerr) ?
author maintainer
#17 lore raw

PATCH 13/15 can: m_can: m_can_class_free_dev(): introduce new function

In reply to Marc Kleine-Budde

From: Dan Murphy <[email protected]>

This patch creates a common function that peripherials can call to free the netdev device when failures occur.

Fixes f524f829b75a ("can: m_can: Create a m_can platform framework")
---
 drivers/net/can/m_can/m_can.c | 6 ++++++
 drivers/net/can/m_can/m_can.h | 1 +
 2 files changed, 7 insertions(+)
drivers/net/can/m_can/m_can.c +6 -0
index 63887e23d89c..f2c87b76e569 100644
@@ -1812,6 +1812,12 @@ struct m_can_classdev *m_can_class_allocate_dev(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(m_can_class_allocate_dev);
 
+void m_can_class_free_dev(struct net_device *net)
+{
+	free_candev(net);
+}
+EXPORT_SYMBOL_GPL(m_can_class_free_dev);
+
 int m_can_class_register(struct m_can_classdev *m_can_dev)
 {
 	int ret;
drivers/net/can/m_can/m_can.h +1 -0
index 49f42b50627a..b2699a7c9997 100644
@@ -99,6 +99,7 @@ struct m_can_classdev {
 };
 
 struct m_can_classdev *m_can_class_allocate_dev(struct device *dev);
+void m_can_class_free_dev(struct net_device *net);
 int m_can_class_register(struct m_can_classdev *cdev);
 void m_can_class_unregister(struct m_can_classdev *cdev);
 int m_can_class_get_clocks(struct m_can_classdev *cdev);
Signature · 1 line
2.29.2
author maintainer
#18 lore raw

PATCH 14/15 can: m_can: Fix freeing of can device from peripherials

In reply to Marc Kleine-Budde

From: Dan Murphy <[email protected]>

Fix leaking netdev device from peripherial devices. The call to allocate the netdev device is made from and managed by the peripherial.

Fixes f524f829b75a ("can: m_can: Create a m_can platform framework")
---
 drivers/net/can/m_can/m_can.c          |  3 ---
 drivers/net/can/m_can/m_can_platform.c | 23 +++++++++++++++--------
 drivers/net/can/m_can/tcan4x5x.c       | 26 ++++++++++++++++++--------
 3 files changed, 33 insertions(+), 19 deletions(-)
drivers/net/can/m_can/m_can.c +0 -3
index f2c87b76e569..645101d19989 100644
@@ -1856,7 +1856,6 @@ int m_can_class_register(struct m_can_classdev *m_can_dev)
 	if (ret) {
 		if (m_can_dev->pm_clock_support)
 			pm_runtime_disable(m_can_dev->dev);
-		free_candev(m_can_dev->net);
 	}
 
 	return ret;
@@ -1914,8 +1913,6 @@ void m_can_class_unregister(struct m_can_classdev *m_can_dev)
 	unregister_candev(m_can_dev->net);
 
 	m_can_clk_stop(m_can_dev);
-
-	free_candev(m_can_dev->net);
 }
 EXPORT_SYMBOL_GPL(m_can_class_unregister);
 
drivers/net/can/m_can/m_can_platform.c +15 -8
index e6d0cb9ee02f..161cb9be018c 100644
@@ -67,32 +67,36 @@ static int m_can_plat_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
-	if (!priv)
-		return -ENOMEM;
+	if (!priv) {
+		ret = -ENOMEM;
+		goto probe_fail;
+	}
 
 	mcan_class->device_data = priv;
 
-	m_can_class_get_clocks(mcan_class);
+	ret = m_can_class_get_clocks(mcan_class);
+	if (ret)
+		goto probe_fail;
 
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "m_can");
 	addr = devm_ioremap_resource(&pdev->dev, res);
 	irq = platform_get_irq_byname(pdev, "int0");
 	if (IS_ERR(addr) || irq < 0) {
 		ret = -EINVAL;
-		goto failed_ret;
+		goto probe_fail;
 	}
 
 	/* message ram could be shared */
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "message_ram");
 	if (!res) {
 		ret = -ENODEV;
-		goto failed_ret;
+		goto probe_fail;
 	}
 
 	mram_addr = devm_ioremap(&pdev->dev, res->start, resource_size(res));
 	if (!mram_addr) {
 		ret = -ENOMEM;
-		goto failed_ret;
+		goto probe_fail;
 	}
 
 	priv->base = addr;
@@ -111,9 +115,10 @@ static int m_can_plat_probe(struct platform_device *pdev)
 
 	m_can_init_ram(mcan_class);
 
-	ret = m_can_class_register(mcan_class);
+	return m_can_class_register(mcan_class);
 
-failed_ret:
+probe_fail:
+	m_can_class_free_dev(mcan_class->net);
 	return ret;
 }
 
@@ -134,6 +139,8 @@ static int m_can_plat_remove(struct platform_device *pdev)
 
 	m_can_class_unregister(mcan_class);
 
+	m_can_class_free_dev(mcan_class->net);
+
 	platform_set_drvdata(pdev, NULL);
 
 	return 0;
drivers/net/can/m_can/tcan4x5x.c +18 -8
index 4fdb7121403a..e5d7d85e0b6d 100644
@@ -440,14 +440,18 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
 		return -ENOMEM;
 
 	priv = devm_kzalloc(&spi->dev, sizeof(*priv), GFP_KERNEL);
-	if (!priv)
-		return -ENOMEM;
+	if (!priv) {
+		ret = -ENOMEM;
+		goto out_m_can_class_free_dev;
+	}
 
 	priv->power = devm_regulator_get_optional(&spi->dev, "vsup");
-	if (PTR_ERR(priv->power) == -EPROBE_DEFER)
-		return -EPROBE_DEFER;
-	else
+	if (PTR_ERR(priv->power) == -EPROBE_DEFER) {
+		ret = -EPROBE_DEFER;
+		goto out_m_can_class_free_dev;
+	} else {
 		priv->power = NULL;
+	}
 
 	mcan_class->device_data = priv;
 
@@ -460,8 +464,10 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
 	}
 
 	/* Sanity check */
-	if (freq < 20000000 || freq > TCAN4X5X_EXT_CLK_DEF)
-		return -ERANGE;
+	if (freq < 20000000 || freq > TCAN4X5X_EXT_CLK_DEF) {
+		ret = -ERANGE;
+		goto out_m_can_class_free_dev;
+	}
 
 	priv->reg_offset = TCAN4X5X_MCAN_OFFSET;
 	priv->mram_start = TCAN4X5X_MRAM_START;
@@ -518,8 +524,10 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
 		clk_disable_unprepare(mcan_class->cclk);
 		clk_disable_unprepare(mcan_class->hclk);
 	}
-
+ out_m_can_class_free_dev:
+	m_can_class_free_dev(mcan_class->net);
 	dev_err(&spi->dev, "Probe failed, err=%d\n", ret);
+
 	return ret;
 }
 
@@ -531,6 +539,8 @@ static int tcan4x5x_can_remove(struct spi_device *spi)
 
 	tcan4x5x_power_enable(priv->power, 0);
 
+	m_can_class_free_dev(priv->mcan_dev->net);
+
 	return 0;
 }
 
Signature · 1 line
2.29.2
author maintainer
#19 lore raw

PATCH 15/15 can: m_can: m_can_stop(): set device to software init mode before closing

In reply to Marc Kleine-Budde

From: Faiz Abbas <[email protected]>

There might be some requests pending in the buffer when the interface close sequence occurs. In some devices, these pending requests might lead to the module not shutting down properly when m_can_clk_stop() is called.

Therefore, move the device to init state before potentially powering it down.

Fixes e0d1f4816f2a ("can: m_can: add Bosch M_CAN controller support")
---
 drivers/net/can/m_can/m_can.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/can/m_can/m_can.c +3 -0
index 645101d19989..e7264043f79a 100644
@@ -1414,6 +1414,9 @@ static void m_can_stop(struct net_device *dev)
 	/* disable all interrupts */
 	m_can_disable_all_interrupts(cdev);
 
+	/* Set init mode to disengage from the network */
+	m_can_config_endisable(cdev, true);
+
 	/* set the state as STOPPED */
 	cdev->can.state = CAN_STATE_STOPPED;
 }
Signature · 1 line
2.29.2
maintainer
#20 lore raw
In reply to Marc Kleine-Budde
Quoted 21 lines · On Sun, 15 Nov 2020 18:41:16 +0100 Marc Kleine-Budde wrote:

Anant Thazhemadam contributed two patches for the AF_CAN that prevent potential access of uninitialized member in can_rcv() and canfd_rcv().

The next patch is by Alejandro Concepcion Rodriguez and changes can_restart() to use the correct function to push a skb into the networking stack from process context.

Zhang Qilong's patch fixes a memory leak in the error path of the ti_hecc's probe function.

A patch by me fixes mcba_usb_start_xmit() function in the mcba_usb driver, to first fill the skb and then pass it to can_put_echo_skb().

Colin Ian King's patch fixes a potential integer overflow on shift in the peak_usb driver.

The next two patches target the flexcan driver, a patch by me adds the missing "req_bit" to the stop mode property comment (which was broken during net-next for v5.10). Zhang Qilong's patch fixes the failure handling of pm_runtime_get_sync().

Quoted 10 lines

The next seven patches target the m_can driver including the tcan4x5x spi driver glue code. Enric Balletbo i Serra's patch for the tcan4x5x Kconfig fix the REGMAP_SPI dependency handling. A patch by me for the tcan4x5x driver's probe() function adds missing error handling to for devm_regmap_init(), and in tcan4x5x_can_remove() the order of deregistration is fixed. Wu Bo's patch for the m_can driver fixes the state change handling in m_can_handle_state_change(). Two patches by Dan Murphy first introduce m_can_class_free_dev() and then make use of it to fix the freeing of the can device. A patch by Faiz Abbas add a missing shutdown of the CAN controller in the m_can_stop() function.

Pulled, thanks!