linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* pull-request: can 2020-11-14
@ 2020-11-14 17:33 Marc Kleine-Budde
  2020-11-14 17:33 ` [net 01/15] can: af_can: prevent potential access of uninitialized member in can_rcv() Marc Kleine-Budde
                   ` (15 more replies)
  0 siblings, 16 replies; 22+ messages in thread
From: Marc Kleine-Budde @ 2020-11-14 17:33 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel

Hello Jakub, hello David,

here's a pull request for net/master consisting of 15 patches for net/master.

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-20201114

for you to fetch changes up to 9a7e716d475eb29213117d2e501b841050c4b511:

  can: m_can: m_can_stop(): set device to software init mode before closing (2020-11-14 18:21:51 +0100)

----------------------------------------------------------------
linux-can-fixes-for-5.10-20201114

----------------------------------------------------------------
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(-)


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [net 01/15] can: af_can: prevent potential access of uninitialized member in can_rcv()
  2020-11-14 17:33 pull-request: can 2020-11-14 Marc Kleine-Budde
@ 2020-11-14 17:33 ` Marc Kleine-Budde
  2020-11-14 17:33 ` [net 02/15] can: af_can: prevent potential access of uninitialized member in canfd_rcv() Marc Kleine-Budde
                   ` (14 subsequent siblings)
  15 siblings, 0 replies; 22+ messages in thread
From: Marc Kleine-Budde @ 2020-11-14 17:33 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Anant Thazhemadam,
	syzbot+9bcb0c9409066696d3aa, Marc Kleine-Budde

From: Anant Thazhemadam <anant.thazhemadam@gmail.com>

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: syzbot+9bcb0c9409066696d3aa@syzkaller.appspotmail.com
Tested-by: Anant Thazhemadam <anant.thazhemadam@gmail.com>
Signed-off-by: Anant Thazhemadam <anant.thazhemadam@gmail.com>
Link: https://lore.kernel.org/r/20201103213906.24219-2-anant.thazhemadam@gmail.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 net/can/af_can.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/net/can/af_can.c b/net/can/af_can.c
index 6373ab9c5507..e8d4e3ef5322 100644
--- a/net/can/af_can.c
+++ b/net/can/af_can.c
@@ -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
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [net 02/15] can: af_can: prevent potential access of uninitialized member in canfd_rcv()
  2020-11-14 17:33 pull-request: can 2020-11-14 Marc Kleine-Budde
  2020-11-14 17:33 ` [net 01/15] can: af_can: prevent potential access of uninitialized member in can_rcv() Marc Kleine-Budde
@ 2020-11-14 17:33 ` Marc Kleine-Budde
  2020-11-14 17:33 ` [net 03/15] can: dev: can_restart(): post buffer from the right context Marc Kleine-Budde
                   ` (13 subsequent siblings)
  15 siblings, 0 replies; 22+ messages in thread
From: Marc Kleine-Budde @ 2020-11-14 17:33 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Anant Thazhemadam,
	syzbot+9bcb0c9409066696d3aa, Marc Kleine-Budde

From: Anant Thazhemadam <anant.thazhemadam@gmail.com>

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: syzbot+9bcb0c9409066696d3aa@syzkaller.appspotmail.com
Tested-by: Anant Thazhemadam <anant.thazhemadam@gmail.com>
Signed-off-by: Anant Thazhemadam <anant.thazhemadam@gmail.com>
Link: https://lore.kernel.org/r/20201103213906.24219-3-anant.thazhemadam@gmail.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 net/can/af_can.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/net/can/af_can.c b/net/can/af_can.c
index e8d4e3ef5322..5d124c155904 100644
--- a/net/can/af_can.c
+++ b/net/can/af_can.c
@@ -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 */
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [net 03/15] can: dev: can_restart(): post buffer from the right context
  2020-11-14 17:33 pull-request: can 2020-11-14 Marc Kleine-Budde
  2020-11-14 17:33 ` [net 01/15] can: af_can: prevent potential access of uninitialized member in can_rcv() Marc Kleine-Budde
  2020-11-14 17:33 ` [net 02/15] can: af_can: prevent potential access of uninitialized member in canfd_rcv() Marc Kleine-Budde
@ 2020-11-14 17:33 ` Marc Kleine-Budde
  2020-11-14 17:33 ` [net 04/15] can: ti_hecc: Fix memleak in ti_hecc_probe Marc Kleine-Budde
                   ` (12 subsequent siblings)
  15 siblings, 0 replies; 22+ messages in thread
From: Marc Kleine-Budde @ 2020-11-14 17:33 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Alejandro Concepcion Rodriguez,
	Loris Fauster, Marc Kleine-Budde

From: Alejandro Concepcion Rodriguez <alejandro@acoro.eu>

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")
Co-developed-by: Loris Fauster <loris.fauster@ttcontrol.com>
Signed-off-by: Loris Fauster <loris.fauster@ttcontrol.com>
Signed-off-by: Alejandro Concepcion Rodriguez <alejandro@acoro.eu>
Link: https://lore.kernel.org/r/4e84162b-fb31-3a73-fa9a-9438b4bd5234@acoro.eu
[mkl: use netif_rx_ni() instead of netif_rx_any_context()]
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index 6dee4f8f2024..81e39d7507d8 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -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;
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [net 04/15] can: ti_hecc: Fix memleak in ti_hecc_probe
  2020-11-14 17:33 pull-request: can 2020-11-14 Marc Kleine-Budde
                   ` (2 preceding siblings ...)
  2020-11-14 17:33 ` [net 03/15] can: dev: can_restart(): post buffer from the right context Marc Kleine-Budde
@ 2020-11-14 17:33 ` Marc Kleine-Budde
  2020-11-14 17:33 ` [net 05/15] can: mcba_usb: mcba_usb_start_xmit(): first fill skb, then pass to can_put_echo_skb() Marc Kleine-Budde
                   ` (11 subsequent siblings)
  15 siblings, 0 replies; 22+ messages in thread
From: Marc Kleine-Budde @ 2020-11-14 17:33 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel, Zhang Qilong, Marc Kleine-Budde

From: Zhang Qilong <zhangqilong3@huawei.com>

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")
Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
Link: https://lore.kernel.org/r/20201114111708.3465543-1-zhangqilong3@huawei.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/ti_hecc.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/net/can/ti_hecc.c b/drivers/net/can/ti_hecc.c
index 9913f5458279..2c22f40e12bd 100644
--- a/drivers/net/can/ti_hecc.c
+++ b/drivers/net/can/ti_hecc.c
@@ -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;
 }
 
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [net 05/15] can: mcba_usb: mcba_usb_start_xmit(): first fill skb, then pass to can_put_echo_skb()
  2020-11-14 17:33 pull-request: can 2020-11-14 Marc Kleine-Budde
                   ` (3 preceding siblings ...)
  2020-11-14 17:33 ` [net 04/15] can: ti_hecc: Fix memleak in ti_hecc_probe Marc Kleine-Budde
@ 2020-11-14 17:33 ` Marc Kleine-Budde
  2020-11-14 17:33 ` [net 06/15] can: peak_usb: fix potential integer overflow on shift of a int Marc Kleine-Budde
                   ` (10 subsequent siblings)
  15 siblings, 0 replies; 22+ messages in thread
From: Marc Kleine-Budde @ 2020-11-14 17:33 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Marc Kleine-Budde,
	Remigiusz Kołłątaj

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 <remigiusz.kollataj@mobica.com>
Link: https://lore.kernel.org/r/20201111221204.1639007-1-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/mcba_usb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/usb/mcba_usb.c b/drivers/net/can/usb/mcba_usb.c
index 5857b37dcd96..e97f2e0da6b0 100644
--- a/drivers/net/can/usb/mcba_usb.c
+++ b/drivers/net/can/usb/mcba_usb.c
@@ -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;
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [net 06/15] can: peak_usb: fix potential integer overflow on shift of a int
  2020-11-14 17:33 pull-request: can 2020-11-14 Marc Kleine-Budde
                   ` (4 preceding siblings ...)
  2020-11-14 17:33 ` [net 05/15] can: mcba_usb: mcba_usb_start_xmit(): first fill skb, then pass to can_put_echo_skb() Marc Kleine-Budde
@ 2020-11-14 17:33 ` Marc Kleine-Budde
  2020-11-14 17:33 ` [net 07/15] can: flexcan: flexcan_setup_stop_mode(): add missing "req_bit" to stop mode property comment Marc Kleine-Budde
                   ` (9 subsequent siblings)
  15 siblings, 0 replies; 22+ messages in thread
From: Marc Kleine-Budde @ 2020-11-14 17:33 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel, Colin Ian King, Marc Kleine-Budde

From: Colin Ian King <colin.king@canonical.com>

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")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Link: https://lore.kernel.org/r/20201105112427.40688-1-colin.king@canonical.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/peak_usb/pcan_usb_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
index c2764799f9ef..204ccb27d6d9 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
@@ -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 */
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [net 07/15] can: flexcan: flexcan_setup_stop_mode(): add missing "req_bit" to stop mode property comment
  2020-11-14 17:33 pull-request: can 2020-11-14 Marc Kleine-Budde
                   ` (5 preceding siblings ...)
  2020-11-14 17:33 ` [net 06/15] can: peak_usb: fix potential integer overflow on shift of a int Marc Kleine-Budde
@ 2020-11-14 17:33 ` Marc Kleine-Budde
  2020-11-14 17:33 ` [net 08/15] can: flexcan: fix failure handling of pm_runtime_get_sync() Marc Kleine-Budde
                   ` (8 subsequent siblings)
  15 siblings, 0 replies; 22+ messages in thread
From: Marc Kleine-Budde @ 2020-11-14 17:33 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel, Marc Kleine-Budde, Joakim Zhang

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")
Reported-by: Joakim Zhang <qiangqing.zhang@nxp.com>
Link: http://lore.kernel.org/r/20201014114810.2911135-1-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/flexcan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index 881799bd9c5e..4e8fdb6064bd 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -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));
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [net 08/15] can: flexcan: fix failure handling of pm_runtime_get_sync()
  2020-11-14 17:33 pull-request: can 2020-11-14 Marc Kleine-Budde
                   ` (6 preceding siblings ...)
  2020-11-14 17:33 ` [net 07/15] can: flexcan: flexcan_setup_stop_mode(): add missing "req_bit" to stop mode property comment Marc Kleine-Budde
@ 2020-11-14 17:33 ` Marc Kleine-Budde
  2020-11-14 17:33 ` [net 09/15] can: tcan4x5x: replace depends on REGMAP_SPI with depends on SPI Marc Kleine-Budde
                   ` (7 subsequent siblings)
  15 siblings, 0 replies; 22+ messages in thread
From: Marc Kleine-Budde @ 2020-11-14 17:33 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel, Zhang Qilong, Marc Kleine-Budde

From: Zhang Qilong <zhangqilong3@huawei.com>

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")
Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
Link: https://lore.kernel.org/r/20201108083000.2599705-1-zhangqilong3@huawei.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/flexcan.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index 4e8fdb6064bd..d6a9cf0e9b60 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -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)
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [net 09/15] can: tcan4x5x: replace depends on REGMAP_SPI with depends on SPI
  2020-11-14 17:33 pull-request: can 2020-11-14 Marc Kleine-Budde
                   ` (7 preceding siblings ...)
  2020-11-14 17:33 ` [net 08/15] can: flexcan: fix failure handling of pm_runtime_get_sync() Marc Kleine-Budde
@ 2020-11-14 17:33 ` Marc Kleine-Budde
  2020-11-14 17:33 ` [net 10/15] can: tcan4x5x: tcan4x5x_can_probe(): add missing error checking for devm_regmap_init() Marc Kleine-Budde
                   ` (6 subsequent siblings)
  15 siblings, 0 replies; 22+ messages in thread
From: Marc Kleine-Budde @ 2020-11-14 17:33 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Enric Balletbo i Serra,
	Dan Murphy, Marc Kleine-Budde

From: Enric Balletbo i Serra <enric.balletbo@collabora.com>

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.

Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Link: http://lore.kernel.org/r/20200413141013.506613-1-enric.balletbo@collabora.com
Reviewed-by: Dan Murphy <dmurphy@ti.com>
Fixes: 5443c226ba91 ("can: tcan4x5x: Add tcan4x5x driver to the kernel")
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/m_can/Kconfig | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/m_can/Kconfig b/drivers/net/can/m_can/Kconfig
index 48be627c85c2..5f9f8192dd0b 100644
--- a/drivers/net/can/m_can/Kconfig
+++ b/drivers/net/can/m_can/Kconfig
@@ -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
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [net 10/15] can: tcan4x5x: tcan4x5x_can_probe(): add missing error checking for devm_regmap_init()
  2020-11-14 17:33 pull-request: can 2020-11-14 Marc Kleine-Budde
                   ` (8 preceding siblings ...)
  2020-11-14 17:33 ` [net 09/15] can: tcan4x5x: replace depends on REGMAP_SPI with depends on SPI Marc Kleine-Budde
@ 2020-11-14 17:33 ` Marc Kleine-Budde
  2020-11-14 17:33 ` [net 11/15] can: tcan4x5x: tcan4x5x_can_remove(): fix order of deregistration Marc Kleine-Budde
                   ` (5 subsequent siblings)
  15 siblings, 0 replies; 22+ messages in thread
From: Marc Kleine-Budde @ 2020-11-14 17:33 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel, Marc Kleine-Budde, Dan Murphy

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 <dmurphy@ti.com>
Link: http://lore.kernel.org/r/20201019154233.1262589-7-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/m_can/tcan4x5x.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/can/m_can/tcan4x5x.c b/drivers/net/can/m_can/tcan4x5x.c
index eacd428e07e9..f058bd9104e9 100644
--- a/drivers/net/can/m_can/tcan4x5x.c
+++ b/drivers/net/can/m_can/tcan4x5x.c
@@ -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)
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [net 11/15] can: tcan4x5x: tcan4x5x_can_remove(): fix order of deregistration
  2020-11-14 17:33 pull-request: can 2020-11-14 Marc Kleine-Budde
                   ` (9 preceding siblings ...)
  2020-11-14 17:33 ` [net 10/15] can: tcan4x5x: tcan4x5x_can_probe(): add missing error checking for devm_regmap_init() Marc Kleine-Budde
@ 2020-11-14 17:33 ` Marc Kleine-Budde
  2020-11-14 17:33 ` [net 12/15] can: m_can: m_can_handle_state_change(): fix state change Marc Kleine-Budde
                   ` (4 subsequent siblings)
  15 siblings, 0 replies; 22+ messages in thread
From: Marc Kleine-Budde @ 2020-11-14 17:33 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel, Marc Kleine-Budde, Dan Murphy

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 <dmurphy@ti.com>
Link: http://lore.kernel.org/r/20201019154233.1262589-10-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/m_can/tcan4x5x.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/m_can/tcan4x5x.c b/drivers/net/can/m_can/tcan4x5x.c
index f058bd9104e9..4fdb7121403a 100644
--- a/drivers/net/can/m_can/tcan4x5x.c
+++ b/drivers/net/can/m_can/tcan4x5x.c
@@ -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;
 }
 
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [net 12/15] can: m_can: m_can_handle_state_change(): fix state change
  2020-11-14 17:33 pull-request: can 2020-11-14 Marc Kleine-Budde
                   ` (10 preceding siblings ...)
  2020-11-14 17:33 ` [net 11/15] can: tcan4x5x: tcan4x5x_can_remove(): fix order of deregistration Marc Kleine-Budde
@ 2020-11-14 17:33 ` Marc Kleine-Budde
  2020-11-14 17:33 ` [net 13/15] can: m_can: m_can_class_free_dev(): introduce new function Marc Kleine-Budde
                   ` (3 subsequent siblings)
  15 siblings, 0 replies; 22+ messages in thread
From: Marc Kleine-Budde @ 2020-11-14 17:33 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Wu Bo, Dan Murphy, Marc Kleine-Budde

From: Wu Bo <wubo.oduw@gmail.com>

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.

Signed-off-by: Wu Bo <wubo.oduw@gmail.com>
Link: http://lore.kernel.org/r/20200129022330.21248-2-wubo.oduw@gmail.com
Cc: Dan Murphy <dmurphy@ti.com>
Fixes: e0d1f4816f2a ("can: m_can: add Bosch M_CAN controller support")
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/m_can/m_can.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 02c5795b7393..63887e23d89c 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -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) ?
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [net 13/15] can: m_can: m_can_class_free_dev(): introduce new function
  2020-11-14 17:33 pull-request: can 2020-11-14 Marc Kleine-Budde
                   ` (11 preceding siblings ...)
  2020-11-14 17:33 ` [net 12/15] can: m_can: m_can_handle_state_change(): fix state change Marc Kleine-Budde
@ 2020-11-14 17:33 ` Marc Kleine-Budde
  2020-11-14 17:33 ` [net 14/15] can: m_can: Fix freeing of can device from peripherials Marc Kleine-Budde
                   ` (2 subsequent siblings)
  15 siblings, 0 replies; 22+ messages in thread
From: Marc Kleine-Budde @ 2020-11-14 17:33 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel, Dan Murphy, Marc Kleine-Budde

From: Dan Murphy <dmurphy@ti.com>

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

Fixes: d42f4e1d06d9 ("can: m_can: Create a m_can platform framework")
Reported-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Dan Murphy <dmurphy@ti.com>
Link: http://lore.kernel.org/r/20200227183829.21854-2-dmurphy@ti.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/m_can/m_can.c | 6 ++++++
 drivers/net/can/m_can/m_can.h | 1 +
 2 files changed, 7 insertions(+)

diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 63887e23d89c..f2c87b76e569 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -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;
diff --git a/drivers/net/can/m_can/m_can.h b/drivers/net/can/m_can/m_can.h
index 49f42b50627a..b2699a7c9997 100644
--- a/drivers/net/can/m_can/m_can.h
+++ b/drivers/net/can/m_can/m_can.h
@@ -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);
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [net 14/15] can: m_can: Fix freeing of can device from peripherials
  2020-11-14 17:33 pull-request: can 2020-11-14 Marc Kleine-Budde
                   ` (12 preceding siblings ...)
  2020-11-14 17:33 ` [net 13/15] can: m_can: m_can_class_free_dev(): introduce new function Marc Kleine-Budde
@ 2020-11-14 17:33 ` Marc Kleine-Budde
  2020-11-14 17:33 ` [net 15/15] can: m_can: m_can_stop(): set device to software init mode before closing Marc Kleine-Budde
  2020-11-15  1:35 ` pull-request: can 2020-11-14 Jakub Kicinski
  15 siblings, 0 replies; 22+ messages in thread
From: Marc Kleine-Budde @ 2020-11-14 17:33 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel, Dan Murphy, Marc Kleine-Budde

From: Dan Murphy <dmurphy@ti.com>

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

Fixes: d42f4e1d06d9 ("can: m_can: Create a m_can platform framework")
Reported-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Dan Murphy <dmurphy@ti.com>
Link: http://lore.kernel.org/r/20200227183829.21854-2-dmurphy@ti.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 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(-)

diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index f2c87b76e569..645101d19989 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -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);
 
diff --git a/drivers/net/can/m_can/m_can_platform.c b/drivers/net/can/m_can/m_can_platform.c
index e6d0cb9ee02f..161cb9be018c 100644
--- a/drivers/net/can/m_can/m_can_platform.c
+++ b/drivers/net/can/m_can/m_can_platform.c
@@ -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;
diff --git a/drivers/net/can/m_can/tcan4x5x.c b/drivers/net/can/m_can/tcan4x5x.c
index 4fdb7121403a..e5d7d85e0b6d 100644
--- a/drivers/net/can/m_can/tcan4x5x.c
+++ b/drivers/net/can/m_can/tcan4x5x.c
@@ -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;
 }
 
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [net 15/15] can: m_can: m_can_stop(): set device to software init mode before closing
  2020-11-14 17:33 pull-request: can 2020-11-14 Marc Kleine-Budde
                   ` (13 preceding siblings ...)
  2020-11-14 17:33 ` [net 14/15] can: m_can: Fix freeing of can device from peripherials Marc Kleine-Budde
@ 2020-11-14 17:33 ` Marc Kleine-Budde
  2020-11-15  1:35 ` pull-request: can 2020-11-14 Jakub Kicinski
  15 siblings, 0 replies; 22+ messages in thread
From: Marc Kleine-Budde @ 2020-11-14 17:33 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Faiz Abbas, Dan Murphy,
	Marc Kleine-Budde

From: Faiz Abbas <faiz_abbas@ti.com>

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")
Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Acked-by: Dan Murphy <dmurphy@ti.com>
Link: https://lore.kernel.org/r/20200825055442.16994-1-faiz_abbas@ti.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/m_can/m_can.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 645101d19989..e7264043f79a 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -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;
 }
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: pull-request: can 2020-11-14
  2020-11-14 17:33 pull-request: can 2020-11-14 Marc Kleine-Budde
                   ` (14 preceding siblings ...)
  2020-11-14 17:33 ` [net 15/15] can: m_can: m_can_stop(): set device to software init mode before closing Marc Kleine-Budde
@ 2020-11-15  1:35 ` Jakub Kicinski
  2020-11-15  1:39   ` Jakub Kicinski
  15 siblings, 1 reply; 22+ messages in thread
From: Jakub Kicinski @ 2020-11-15  1:35 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: netdev, davem, linux-can, kernel

On Sat, 14 Nov 2020 18:33:44 +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().
> 
> 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.

Two invalid fixes tags here, do you want to respin or should I pull?

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: pull-request: can 2020-11-14
  2020-11-15  1:35 ` pull-request: can 2020-11-14 Jakub Kicinski
@ 2020-11-15  1:39   ` Jakub Kicinski
  2020-11-15 16:58     ` Marc Kleine-Budde
  0 siblings, 1 reply; 22+ messages in thread
From: Jakub Kicinski @ 2020-11-15  1:39 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: netdev, davem, linux-can, kernel

On Sat, 14 Nov 2020 17:35:01 -0800 Jakub Kicinski wrote:
> Two invalid fixes tags here, do you want to respin or should I pull?

Just realized you probably have these objects in your tree so it'd be
useful if I told you which ones ;)

Commit: be719591ede2 ("can: m_can: Fix freeing of can device from peripherials")
	Fixes tag: Fixes: d42f4e1d06d9 ("can: m_can: Create a m_can platform framework")
	Has these problem(s):
		- Target SHA1 does not exist
Commit: aff1dea235ee ("can: m_can: m_can_class_free_dev(): introduce new function")
	Fixes tag: Fixes: d42f4e1d06d9 ("can: m_can: Create a m_can platform framework")
	Has these problem(s):
		- Target SHA1 does not exist

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: pull-request: can 2020-11-14
  2020-11-15  1:39   ` Jakub Kicinski
@ 2020-11-15 16:58     ` Marc Kleine-Budde
  2020-11-15 18:00       ` Marc Kleine-Budde
  2020-11-16 15:33       ` Jakub Kicinski
  0 siblings, 2 replies; 22+ messages in thread
From: Marc Kleine-Budde @ 2020-11-15 16:58 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: netdev, davem, linux-can, kernel


[-- Attachment #1.1: Type: text/plain, Size: 1263 bytes --]

On 11/15/20 2:39 AM, Jakub Kicinski wrote:
> On Sat, 14 Nov 2020 17:35:01 -0800 Jakub Kicinski wrote:
>> Two invalid fixes tags here, do you want to respin or should I pull?

Let me respin this. It'll have the new date tag of today (15th).

> Just realized you probably have these objects in your tree so it'd be
> useful if I told you which ones ;)

I haven't checked the fixes tags, they were added by the submitter of the patch.
How do you test for the fixes? Is that script avaiable somewhere?

> Commit: be719591ede2 ("can: m_can: Fix freeing of can device from peripherials")
> 	Fixes tag: Fixes: d42f4e1d06d9 ("can: m_can: Create a m_can platform framework")
> 	Has these problem(s):
> 		- Target SHA1 does not exist
> Commit: aff1dea235ee ("can: m_can: m_can_class_free_dev(): introduce new function")
> 	Fixes tag: Fixes: d42f4e1d06d9 ("can: m_can: Create a m_can platform framework")
> 	Has these problem(s):
> 		- Target SHA1 does not exist

regards,
Marc

-- 
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 |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: pull-request: can 2020-11-14
  2020-11-15 16:58     ` Marc Kleine-Budde
@ 2020-11-15 18:00       ` Marc Kleine-Budde
  2020-11-16 15:33       ` Jakub Kicinski
  1 sibling, 0 replies; 22+ messages in thread
From: Marc Kleine-Budde @ 2020-11-15 18:00 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: netdev, davem, kernel, linux-can


[-- Attachment #1.1: Type: text/plain, Size: 733 bytes --]

On 11/15/20 5:58 PM, Marc Kleine-Budde wrote:
> On 11/15/20 2:39 AM, Jakub Kicinski wrote:
>> On Sat, 14 Nov 2020 17:35:01 -0800 Jakub Kicinski wrote:
>>> Two invalid fixes tags here, do you want to respin or should I pull?
> 
> Let me respin this. It'll have the new date tag of today (15th).

It's linux-can-fixes-for-5.10-20201115, for the pull request see:

https://lore.kernel.org/r/20201115174131.2089251-1-mkl@pengutronix.de

regards,
Marc

-- 
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 |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: pull-request: can 2020-11-14
  2020-11-15 16:58     ` Marc Kleine-Budde
  2020-11-15 18:00       ` Marc Kleine-Budde
@ 2020-11-16 15:33       ` Jakub Kicinski
  1 sibling, 0 replies; 22+ messages in thread
From: Jakub Kicinski @ 2020-11-16 15:33 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: netdev, davem, linux-can, kernel

On Sun, 15 Nov 2020 17:58:27 +0100 Marc Kleine-Budde wrote:
> On 11/15/20 2:39 AM, Jakub Kicinski wrote:
> > On Sat, 14 Nov 2020 17:35:01 -0800 Jakub Kicinski wrote:  
> >> Two invalid fixes tags here, do you want to respin or should I pull?  
> 
> Let me respin this. It'll have the new date tag of today (15th).
> 
> > Just realized you probably have these objects in your tree so it'd be
> > useful if I told you which ones ;)  
> 
> I haven't checked the fixes tags, they were added by the submitter of the patch.
> How do you test for the fixes? Is that script avaiable somewhere?

I stole this script from Stephen Rothwell & Greg:

https://github.com/gregkh/gregkh-linux/blob/master/work/verify_fixes.sh
https://github.com/kuba-moo/nipa/blob/master/tests/patch/verify_fixes/verify_fixes.sh

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [net 06/15] can: peak_usb: fix potential integer overflow on shift of a int
  2020-11-15 17:41 pull-request: can 2020-11-15 Marc Kleine-Budde
@ 2020-11-15 17:41 ` Marc Kleine-Budde
  0 siblings, 0 replies; 22+ messages in thread
From: Marc Kleine-Budde @ 2020-11-15 17:41 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel, Colin Ian King, Marc Kleine-Budde

From: Colin Ian King <colin.king@canonical.com>

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")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Link: https://lore.kernel.org/r/20201105112427.40688-1-colin.king@canonical.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/peak_usb/pcan_usb_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
index c2764799f9ef..204ccb27d6d9 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
@@ -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 */
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2020-11-16 15:33 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-14 17:33 pull-request: can 2020-11-14 Marc Kleine-Budde
2020-11-14 17:33 ` [net 01/15] can: af_can: prevent potential access of uninitialized member in can_rcv() Marc Kleine-Budde
2020-11-14 17:33 ` [net 02/15] can: af_can: prevent potential access of uninitialized member in canfd_rcv() Marc Kleine-Budde
2020-11-14 17:33 ` [net 03/15] can: dev: can_restart(): post buffer from the right context Marc Kleine-Budde
2020-11-14 17:33 ` [net 04/15] can: ti_hecc: Fix memleak in ti_hecc_probe Marc Kleine-Budde
2020-11-14 17:33 ` [net 05/15] can: mcba_usb: mcba_usb_start_xmit(): first fill skb, then pass to can_put_echo_skb() Marc Kleine-Budde
2020-11-14 17:33 ` [net 06/15] can: peak_usb: fix potential integer overflow on shift of a int Marc Kleine-Budde
2020-11-14 17:33 ` [net 07/15] can: flexcan: flexcan_setup_stop_mode(): add missing "req_bit" to stop mode property comment Marc Kleine-Budde
2020-11-14 17:33 ` [net 08/15] can: flexcan: fix failure handling of pm_runtime_get_sync() Marc Kleine-Budde
2020-11-14 17:33 ` [net 09/15] can: tcan4x5x: replace depends on REGMAP_SPI with depends on SPI Marc Kleine-Budde
2020-11-14 17:33 ` [net 10/15] can: tcan4x5x: tcan4x5x_can_probe(): add missing error checking for devm_regmap_init() Marc Kleine-Budde
2020-11-14 17:33 ` [net 11/15] can: tcan4x5x: tcan4x5x_can_remove(): fix order of deregistration Marc Kleine-Budde
2020-11-14 17:33 ` [net 12/15] can: m_can: m_can_handle_state_change(): fix state change Marc Kleine-Budde
2020-11-14 17:33 ` [net 13/15] can: m_can: m_can_class_free_dev(): introduce new function Marc Kleine-Budde
2020-11-14 17:33 ` [net 14/15] can: m_can: Fix freeing of can device from peripherials Marc Kleine-Budde
2020-11-14 17:33 ` [net 15/15] can: m_can: m_can_stop(): set device to software init mode before closing Marc Kleine-Budde
2020-11-15  1:35 ` pull-request: can 2020-11-14 Jakub Kicinski
2020-11-15  1:39   ` Jakub Kicinski
2020-11-15 16:58     ` Marc Kleine-Budde
2020-11-15 18:00       ` Marc Kleine-Budde
2020-11-16 15:33       ` Jakub Kicinski
2020-11-15 17:41 pull-request: can 2020-11-15 Marc Kleine-Budde
2020-11-15 17:41 ` [net 06/15] can: peak_usb: fix potential integer overflow on shift of a int Marc Kleine-Budde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).