Skip to contentSkip to conversation

pull-request: can 2021-03-16

PATCH In review Marc Kleine-Budde 4 participants 16 messages Mar 16, 2021 – Mar 18, 2021

Subsystems (5)
lore
Share & tools
lore

Marc Kleine-Budde

author maintainer
#0 lore raw

Hello Jakub, hello David,

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

The first patch is by Martin Willi and fixes the deletion of network name spaces with physical CAN interfaces in them.

The next two patches are by me an fix the ISOTP protocol, to ensure that unused flags in classical CAN frames are properly initialized to zero.

Stephane Grosjean contributes a patch for the pcan_usb_fd driver, which add MODULE_SUPPORTED_DEVICE lines for two supported devices.

Angelo Dureghello's patch for the flexcan driver fixes a potential div by zero, if the bitrate is not set during driver probe.

Jimmy Assarsson's patch for the kvaser_pciefd disables bus load reporting in the device, if it was previously enabled by the vendor's out of tree drier. A patch for the kvaser_usb adds support for a new device, by adding the appropriate USB product ID.

Tong Zhang contributes two patches for the c_can driver. First a use-after-free in the c_can_pci driver is fixed, in the second patch the runtime PM for the c_can_pci is fixed by moving the runtime PM enable/disable from the core driver to the platform driver.

The last two patches are by Torin Cooper-Bennun for the m_can driver. First a extraneous msg loss warning is removed then he fixes the RX-path, which might be blocked by errors.

regards,
Marc

---

The following changes since commit 13832ae2755395b2585500c85b64f5109a44227e:

mptcp: fix ADD_ADDR HMAC in case port is specified (2021-03-15 16:43:01 -0700)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can.git tags/linux-can-fixes-for-5.12-20210316

for you to fetch changes up to e98d9ee64ee2cc9b1d1a8e26610ec4d0392ebe50:

can: m_can: m_can_rx_peripheral(): fix RX being blocked by errors (2021-03-16 08:41:27 +0100)

----------------------------------------------------------------
linux-can-fixes-for-5.12-20210316

----------------------------------------------------------------
Angelo Dureghello (1):
can: flexcan: flexcan_chip_freeze(): fix chip freeze for missing bitrate

Jimmy Assarsson (2):
can: kvaser_pciefd: Always disable bus load reporting
can: kvaser_usb: Add support for USBcan Pro 4xHS

Marc Kleine-Budde (2):
can: isotp: isotp_setsockopt(): only allow to set low level TX flags for CAN-FD
can: isotp: TX-path: ensure that CAN frame flags are initialized

Martin Willi (1):
can: dev: Move device back to init netns on owning netns delete

Stephane Grosjean (1):
can: peak_usb: add forgotten supported devices

Tong Zhang (2):
can: c_can_pci: c_can_pci_remove(): fix use-after-free
can: c_can: move runtime PM enable/disable to c_can_platform

Torin Cooper-Bennun (2):
can: m_can: m_can_do_rx_poll(): fix extraneous msg loss warning
can: m_can: m_can_rx_peripheral(): fix RX being blocked by errors

 drivers/net/can/c_can/c_can.c                    | 24 +-----------------------
 drivers/net/can/c_can/c_can_pci.c                |  3 ++-
 drivers/net/can/c_can/c_can_platform.c           |  6 +++++-
 drivers/net/can/dev/netlink.c                    |  1 +
 drivers/net/can/flexcan.c                        |  8 +++++++-
 drivers/net/can/kvaser_pciefd.c                  |  4 ++++
 drivers/net/can/m_can/m_can.c                    |  5 +----
 drivers/net/can/usb/Kconfig                      |  1 +
 drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c |  4 +++-
 drivers/net/can/usb/peak_usb/pcan_usb_fd.c       |  2 ++
 include/net/rtnetlink.h                          |  2 ++
 net/can/isotp.c                                  | 12 +++++-------
 net/core/dev.c                                   |  2 +-
 13 files changed, 35 insertions(+), 39 deletions(-)
author maintainer
#1 lore raw

PATCH 1/11 can: dev: Move device back to init netns on owning netns delete

From: Martin Willi <[email protected]>

When a non-initial netns is destroyed, the usual policy is to delete all virtual network interfaces contained, but move physical interfaces back to the initial netns. This keeps the physical interface visible on the system.

CAN devices are somewhat special, as they define rtnl_link_ops even if they are physical devices. If a CAN interface is moved into a non-initial netns, destroying that netns lets the interface vanish instead of moving it back to the initial netns. default_device_exit() skips CAN interfaces due to having rtnl_link_ops set. Reproducer:

ip netns add foo
ip link set can0 netns foo
ip netns delete foo

WARNING: CPU: 1 PID: 84 at net/core/dev.c:11030 ops_exit_list+0x38/0x60
CPU: 1 PID: 84 Comm: kworker/u4:2 Not tainted 5.10.19 #1
Workqueue: netns cleanup_net
[<c010e700>] (unwind_backtrace) from [<c010a1d8>] (show_stack+0x10/0x14)
[<c010a1d8>] (show_stack) from [<c086dc10>] (dump_stack+0x94/0xa8)
[<c086dc10>] (dump_stack) from [<c086b938>] (__warn+0xb8/0x114)
[<c086b938>] (__warn) from [<c086ba10>] (warn_slowpath_fmt+0x7c/0xac)
[<c086ba10>] (warn_slowpath_fmt) from [<c0629f20>] (ops_exit_list+0x38/0x60)
[<c0629f20>] (ops_exit_list) from [<c062a5c4>] (cleanup_net+0x230/0x380)
[<c062a5c4>] (cleanup_net) from [<c0142c20>] (process_one_work+0x1d8/0x438)
[<c0142c20>] (process_one_work) from [<c0142ee4>] (worker_thread+0x64/0x5a8)
[<c0142ee4>] (worker_thread) from [<c0148a98>] (kthread+0x148/0x14c)
[<c0148a98>] (kthread) from [<c0100148>] (ret_from_fork+0x14/0x2c)

To properly restore physical CAN devices to the initial netns on owning netns exit, introduce a flag on rtnl_link_ops that can be set by drivers. For CAN devices setting this flag, default_device_exit() considers them non-virtual, applying the usual namespace move.

The issue was introduced in the commit mentioned below, as at that time CAN devices did not have a dellink() operation.

Fixes e008b5fc8dc7 ("net: Simplfy default_device_exit and improve batching.")
---
 drivers/net/can/dev/netlink.c | 1 +
 include/net/rtnetlink.h       | 2 ++
 net/core/dev.c                | 2 +-
 3 files changed, 4 insertions(+), 1 deletion(-)
drivers/net/can/dev/netlink.c +1 -0
index 867f6be31230..f5d79e6e5483 100644
@@ -355,6 +355,7 @@ static void can_dellink(struct net_device *dev, struct list_head *head)
 
 struct rtnl_link_ops can_link_ops __read_mostly = {
 	.kind		= "can",
+	.netns_refund	= true,
 	.maxtype	= IFLA_CAN_MAX,
 	.policy		= can_policy,
 	.setup		= can_setup,
include/net/rtnetlink.h +2 -0
index e2091bb2b3a8..4da61c950e93 100644
@@ -33,6 +33,7 @@ static inline int rtnl_msg_family(const struct nlmsghdr *nlh)
  *
  *	@list: Used internally
  *	@kind: Identifier
+ *	@netns_refund: Physical device, move to init_net on netns exit
  *	@maxtype: Highest device specific netlink attribute number
  *	@policy: Netlink policy for device specific attribute validation
  *	@validate: Optional validation function for netlink/changelink parameters
@@ -64,6 +65,7 @@ struct rtnl_link_ops {
 	size_t			priv_size;
 	void			(*setup)(struct net_device *dev);
 
+	bool			netns_refund;
 	unsigned int		maxtype;
 	const struct nla_policy	*policy;
 	int			(*validate)(struct nlattr *tb[],
net/core/dev.c +1 -1
index 6c5967e80132..a142a207fc1d 100644
@@ -11346,7 +11346,7 @@ static void __net_exit default_device_exit(struct net *net)
 			continue;
 
 		/* Leave virtual devices for the generic cleanup */
-		if (dev->rtnl_link_ops)
+		if (dev->rtnl_link_ops && !dev->rtnl_link_ops->netns_refund)
 			continue;
 
 		/* Push remaining network devices to init_net */

base-commit: 13832ae2755395b2585500c85b64f5109a44227e

Signature · 1 line
2.30.1
maintainer Reviewed-by on v1 1/11
#2 lore raw

Re: [net 01/11] can: dev: Move device back to init netns on owning netns delete

Quoted 1 line · On Tue, 16 Mar 2021 09:20:54 +0100 Marc Kleine-Budde wrote:

+ * @netns_refund: Physical device, move to init_net on netns exit

I feel like we could do better with the name, and the kdoc (not sure what constitutes a physical device these days)... but I have no better suggestion right now :)

author maintainer
#3 lore raw

PATCH 2/11 can: isotp: isotp_setsockopt(): only allow to set low level TX flags for CAN-FD

In reply to Marc Kleine-Budde

CAN-FD frames have struct canfd_frame::flags, while classic CAN frames don't.

This patch refuses to set TX flags (struct can_isotp_ll_options::tx_flags) on non CAN-FD isotp sockets.

Fixes e057dd3fc20f ("can: add ISO 15765-2:2016 transport protocol")
Cc Oliver Hartkopp <[email protected]>
---
 net/can/isotp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/can/isotp.c +2 -1
index 3ef7f78e553b..e32d446c121e 100644
@@ -1228,7 +1228,8 @@ static int isotp_setsockopt(struct socket *sock, int level, int optname,
 			if (ll.mtu != CAN_MTU && ll.mtu != CANFD_MTU)
 				return -EINVAL;
 
-			if (ll.mtu == CAN_MTU && ll.tx_dl > CAN_MAX_DLEN)
+			if (ll.mtu == CAN_MTU &&
+			    (ll.tx_dl > CAN_MAX_DLEN || ll.tx_flags != 0))
 				return -EINVAL;
 
 			memcpy(&so->ll, &ll, sizeof(ll));
Signature · 1 line
2.30.1
author maintainer
#4 lore raw

PATCH 3/11 can: isotp: TX-path: ensure that CAN frame flags are initialized

In reply to Marc Kleine-Budde

The previous patch ensures that the TX flags (struct can_isotp_ll_options::tx_flags) are 0 for classic CAN frames or a user configured value for CAN-FD frames.

This patch sets the CAN frames flags unconditionally to the ISO-TP TX flags, so that they are initialized to a proper value. Otherwise when running "candump -x" on a classical CAN ISO-TP stream shows wrongly set "B" and "E" flags.

| $ candump any,0:0,#FFFFFFFF -extA
| [...]
| can0  TX B E  713   [8]  2B 0A 0B 0C 0D 0E 0F 00
| can0  TX B E  713   [8]  2C 01 02 03 04 05 06 07
| can0  TX B E  713   [8]  2D 08 09 0A 0B 0C 0D 0E
| can0  TX B E  713   [8]  2E 0F 00 01 02 03 04 05
Fixes e057dd3fc20f ("can: add ISO 15765-2:2016 transport protocol")
Cc Oliver Hartkopp <[email protected]>
---
 net/can/isotp.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
net/can/isotp.c +3 -6
index e32d446c121e..430976485d95 100644
@@ -215,8 +215,7 @@ static int isotp_send_fc(struct sock *sk, int ae, u8 flowstatus)
 	if (ae)
 		ncf->data[0] = so->opt.ext_address;
 
-	if (so->ll.mtu == CANFD_MTU)
-		ncf->flags = so->ll.tx_flags;
+	ncf->flags = so->ll.tx_flags;
 
 	can_send_ret = can_send(nskb, 1);
 	if (can_send_ret)
@@ -790,8 +789,7 @@ static enum hrtimer_restart isotp_tx_timer_handler(struct hrtimer *hrtimer)
 		so->tx.sn %= 16;
 		so->tx.bs++;
 
-		if (so->ll.mtu == CANFD_MTU)
-			cf->flags = so->ll.tx_flags;
+		cf->flags = so->ll.tx_flags;
 
 		skb->dev = dev;
 		can_skb_set_owner(skb, sk);
@@ -939,8 +937,7 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
 	}
 
 	/* send the first or only CAN frame */
-	if (so->ll.mtu == CANFD_MTU)
-		cf->flags = so->ll.tx_flags;
+	cf->flags = so->ll.tx_flags;
 
 	skb->dev = dev;
 	skb->sk = sk;
Signature · 1 line
2.30.1
maintainer
#5 lore raw

Re: [net 03/11] can: isotp: TX-path: ensure that CAN frame flags are initialized

Hello Marc,

I obviously missed these patches - but they are fine. Thanks!

After checking your patch I was going after this missing initialization and detected that the outgoing CAN frame skbs from isotp.c were not properly zero initialized - so I sent a patch for it some minutes ago:

https://lore.kernel.org/linux-can/[email protected]/T/#u

In fact I had

Quoted 2 lines

CONFIG_INIT_ON_ALLOC_DEFAULT_ON=y
CONFIG_INIT_ON_FREE_DEFAULT_ON=y

in my local kernel config therefore I was not able to see it on my own :-/

Best,
Oliver

Quoted 59 lines · Marc Kleine-Budde

The previous patch ensures that the TX flags (struct can_isotp_ll_options::tx_flags) are 0 for classic CAN frames or a user configured value for CAN-FD frames.

This patch sets the CAN frames flags unconditionally to the ISO-TP TX flags, so that they are initialized to a proper value. Otherwise when running "candump -x" on a classical CAN ISO-TP stream shows wrongly set "B" and "E" flags.

| $ candump any,0:0,#FFFFFFFF -extA
| [...]
| can0  TX B E  713   [8]  2B 0A 0B 0C 0D 0E 0F 00
| can0  TX B E  713   [8]  2C 01 02 03 04 05 06 07
| can0  TX B E  713   [8]  2D 08 09 0A 0B 0C 0D 0E
| can0  TX B E  713   [8]  2E 0F 00 01 02 03 04 05
Fixes e057dd3fc20f ("can: add ISO 15765-2:2016 transport protocol")
Cc Oliver Hartkopp <[email protected]>
---
  net/can/isotp.c | 9 +++------
  1 file changed, 3 insertions(+), 6 deletions(-)
net/can/isotp.c +3 -6
index e32d446c121e..430976485d95 100644
@@ -215,8 +215,7 @@ static int isotp_send_fc(struct sock *sk, int ae, u8 flowstatus)
  	if (ae)
  		ncf->data[0] = so->opt.ext_address;
 
-	if (so->ll.mtu == CANFD_MTU)
-		ncf->flags = so->ll.tx_flags;
+	ncf->flags = so->ll.tx_flags;
 
  	can_send_ret = can_send(nskb, 1);
  	if (can_send_ret)
@@ -790,8 +789,7 @@ static enum hrtimer_restart isotp_tx_timer_handler(struct hrtimer *hrtimer)
  		so->tx.sn %= 16;
  		so->tx.bs++;
 
-		if (so->ll.mtu == CANFD_MTU)
-			cf->flags = so->ll.tx_flags;
+		cf->flags = so->ll.tx_flags;
 
  		skb->dev = dev;
  		can_skb_set_owner(skb, sk);
@@ -939,8 +937,7 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
  	}
 
  	/* send the first or only CAN frame */
-	if (so->ll.mtu == CANFD_MTU)
-		cf->flags = so->ll.tx_flags;
+	cf->flags = so->ll.tx_flags;
 
  	skb->dev = dev;
  	skb->sk = sk;
author maintainer
#6 lore raw

PATCH 4/11 can: peak_usb: add forgotten supported devices

In reply to Marc Kleine-Budde

From: Stephane Grosjean <[email protected]>

Since the peak_usb driver also supports the CAN-USB interfaces "PCAN-USB X6" and "PCAN-Chip USB" from PEAK-System GmbH, this patch adds their names to the list of explicitly supported devices.

Fixes ea8b65b596d7 ("can: usb: Add support of PCAN-Chip USB stamp module")
Fixes f00b534ded60 ("can: peak: Add support for PCAN-USB X6 USB interface")
---
 drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/can/usb/peak_usb/pcan_usb_fd.c +2 -0
index f347ecc79aef..f1d018218c93 100644
@@ -18,6 +18,8 @@
 
 MODULE_SUPPORTED_DEVICE("PEAK-System PCAN-USB FD adapter");
 MODULE_SUPPORTED_DEVICE("PEAK-System PCAN-USB Pro FD adapter");
+MODULE_SUPPORTED_DEVICE("PEAK-System PCAN-Chip USB");
+MODULE_SUPPORTED_DEVICE("PEAK-System PCAN-USB X6 adapter");
 
 #define PCAN_USBPROFD_CHANNEL_COUNT	2
 #define PCAN_USBFD_CHANNEL_COUNT	1
Signature · 1 line
2.30.1
author maintainer
#7 lore raw

PATCH 5/11 can: flexcan: flexcan_chip_freeze(): fix chip freeze for missing bitrate

In reply to Marc Kleine-Budde

From: Angelo Dureghello <[email protected]>

For cases when flexcan is built-in, bitrate is still not set at registering. So flexcan_chip_freeze() generates:

[    1.860000] *** ZERO DIVIDE ***   FORMAT=4
[    1.860000] Current process id is 1
[    1.860000] BAD KERNEL TRAP: 00000000
[    1.860000] PC: [<402e70c8>] flexcan_chip_freeze+0x1a/0xa8

To allow chip freeze, using an hardcoded timeout when bitrate is still not set.

Fixes ec15e27cc890 ("can: flexcan: enable RX FIFO after FRZ/HALT valid")
[mkl: use if instead of ? operator]
---
 drivers/net/can/flexcan.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/net/can/flexcan.c +7 -1
index 134c05757a3b..57f3635ad8d7 100644
@@ -697,9 +697,15 @@ static int flexcan_chip_disable(struct flexcan_priv *priv)
 static int flexcan_chip_freeze(struct flexcan_priv *priv)
 {
 	struct flexcan_regs __iomem *regs = priv->regs;
-	unsigned int timeout = 1000 * 1000 * 10 / priv->can.bittiming.bitrate;
+	unsigned int timeout;
+	u32 bitrate = priv->can.bittiming.bitrate;
 	u32 reg;
 
+	if (bitrate)
+		timeout = 1000 * 1000 * 10 / bitrate;
+	else
+		timeout = FLEXCAN_TIMEOUT_US / 10;
+
 	reg = priv->read(&regs->mcr);
 	reg |= FLEXCAN_MCR_FRZ | FLEXCAN_MCR_HALT;
 	priv->write(reg, &regs->mcr);
Signature · 1 line
2.30.1
#8 lore raw

Re: [net 05/11] can: flexcan: flexcan_chip_freeze(): fix chip freeze for missing bitrate

Hi all,

Quoted 33 lines · Marc Kleine-Budde

From: Angelo Dureghello <[email protected]>

For cases when flexcan is built-in, bitrate is still not set at registering. So flexcan_chip_freeze() generates:

[    1.860000] *** ZERO DIVIDE ***   FORMAT=4
[    1.860000] Current process id is 1
[    1.860000] BAD KERNEL TRAP: 00000000
[    1.860000] PC: [<402e70c8>] flexcan_chip_freeze+0x1a/0xa8

To allow chip freeze, using an hardcoded timeout when bitrate is still not set.

Fixes ec15e27cc890 ("can: flexcan: enable RX FIFO after FRZ/HALT valid")
[mkl: use if instead of ? operator]
---
 drivers/net/can/flexcan.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/net/can/flexcan.c +2 -1
index 134c05757a3b..57f3635ad8d7 100644
@@ -697,9 +697,15 @@ static int flexcan_chip_disable(struct flexcan_priv *priv)
 static int flexcan_chip_freeze(struct flexcan_priv *priv)
 {
 	struct flexcan_regs __iomem *regs = priv->regs;
-	unsigned int timeout = 1000 * 1000 * 10 / priv->can.bittiming.bitrate;
+	unsigned int timeout;
+	u32 bitrate = priv->can.bittiming.bitrate;

drivers/net/can/flexcan.c static int flexcan_chip_disable(struct flexcan_priv *priv) · line 711

Quoted 10 lines
drivers/net/can/flexcan.c +5 -0
 	u32 reg;
 
+	if (bitrate)
+		timeout = 1000 * 1000 * 10 / bitrate;
+	else
+		timeout = FLEXCAN_TIMEOUT_US / 10;
+
 	reg = priv->read(&regs->mcr);
 	reg |= FLEXCAN_MCR_FRZ | FLEXCAN_MCR_HALT;
 	priv->write(reg, &regs->mcr);

?

Just curious, what's the issue with my "?" ?

Regards,
--
Angelo Dureghello

author maintainer
#9 lore raw

Re: [net 05/11] can: flexcan: flexcan_chip_freeze(): fix chip freeze for missing bitrate

Quoted 49 lines · Angelo Dureghello

Hi all,

Quoted 33 lines · Marc Kleine-Budde

From: Angelo Dureghello <[email protected]>

For cases when flexcan is built-in, bitrate is still not set at registering. So flexcan_chip_freeze() generates:

[    1.860000] *** ZERO DIVIDE ***   FORMAT=4
[    1.860000] Current process id is 1
[    1.860000] BAD KERNEL TRAP: 00000000
[    1.860000] PC: [<402e70c8>] flexcan_chip_freeze+0x1a/0xa8

To allow chip freeze, using an hardcoded timeout when bitrate is still not set.

Fixes ec15e27cc890 ("can: flexcan: enable RX FIFO after FRZ/HALT valid")
[mkl: use if instead of ? operator]
---
 drivers/net/can/flexcan.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/net/can/flexcan.c +2 -1
index 134c05757a3b..57f3635ad8d7 100644
@@ -697,9 +697,15 @@ static int flexcan_chip_disable(struct flexcan_priv *priv)
 static int flexcan_chip_freeze(struct flexcan_priv *priv)
 {
 	struct flexcan_regs __iomem *regs = priv->regs;
-	unsigned int timeout = 1000 * 1000 * 10 / priv->can.bittiming.bitrate;
+	unsigned int timeout;
+	u32 bitrate = priv->can.bittiming.bitrate;

drivers/net/can/flexcan.c static int flexcan_chip_disable(struct flexcan_priv *priv) · line 711

Quoted 10 lines
drivers/net/can/flexcan.c +5 -0
 	u32 reg;
 
+	if (bitrate)
+		timeout = 1000 * 1000 * 10 / bitrate;
+	else
+		timeout = FLEXCAN_TIMEOUT_US / 10;
+
 	reg = priv->read(&regs->mcr);
 	reg |= FLEXCAN_MCR_FRZ | FLEXCAN_MCR_HALT;
 	priv->write(reg, &regs->mcr);

?

Quoted 1 line

Just curious, what's the issue with my "?" ?

Personal preference and readability.

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
#10 lore raw

PATCH 6/11 can: kvaser_pciefd: Always disable bus load reporting

In reply to Marc Kleine-Budde

From: Jimmy Assarsson <[email protected]>

Under certain circumstances, when switching from Kvaser's linuxcan driver (kvpciefd) to the SocketCAN driver (kvaser_pciefd), the bus load reporting is not disabled.
This is flooding the kernel log with prints like:

[3485.574677] kvaser_pciefd 0000:02:00.0: Received unexpected packet type 0x00000009

Always put the controller in the expected state, instead of assuming that bus load reporting is inactive.

Note: If bus load reporting is enabled when the driver is loaded, you will
still get a number of bus load packages (and printouts), before it is disabled.

Fixes 26ad340e582d ("can: kvaser_pciefd: Add driver for Kvaser PCIEcan devices")
---
 drivers/net/can/kvaser_pciefd.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/can/kvaser_pciefd.c +4 -0
index 37e05010ca91..74d9899fc904 100644
@@ -57,6 +57,7 @@ MODULE_DESCRIPTION("CAN driver for Kvaser CAN/PCIe devices");
 #define KVASER_PCIEFD_KCAN_STAT_REG 0x418
 #define KVASER_PCIEFD_KCAN_MODE_REG 0x41c
 #define KVASER_PCIEFD_KCAN_BTRN_REG 0x420
+#define KVASER_PCIEFD_KCAN_BUS_LOAD_REG 0x424
 #define KVASER_PCIEFD_KCAN_BTRD_REG 0x428
 #define KVASER_PCIEFD_KCAN_PWM_REG 0x430
 /* Loopback control register */
@@ -949,6 +950,9 @@ static int kvaser_pciefd_setup_can_ctrls(struct kvaser_pciefd *pcie)
 		timer_setup(&can->bec_poll_timer, kvaser_pciefd_bec_poll_timer,
 			    0);
 
+		/* Disable Bus load reporting */
+		iowrite32(0, can->reg_base + KVASER_PCIEFD_KCAN_BUS_LOAD_REG);
+
 		tx_npackets = ioread32(can->reg_base +
 				       KVASER_PCIEFD_KCAN_TX_NPACKETS_REG);
 		if (((tx_npackets >> KVASER_PCIEFD_KCAN_TX_NPACKETS_MAX_SHIFT) &
Signature · 1 line
2.30.1
author maintainer
#11 lore raw

PATCH 7/11 can: kvaser_usb: Add support for USBcan Pro 4xHS

In reply to Marc Kleine-Budde

From: Jimmy Assarsson <[email protected]>

Add support for Kvaser USBcan Pro 4xHS.

---
 drivers/net/can/usb/Kconfig                      | 1 +
 drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/net/can/usb/Kconfig +1 -0
index c1e5d5b570b6..538f4d9adb91 100644
@@ -73,6 +73,7 @@ config CAN_KVASER_USB
 	    - Kvaser Memorator Pro 5xHS
 	    - Kvaser USBcan Light 4xHS
 	    - Kvaser USBcan Pro 2xHS v2
+	    - Kvaser USBcan Pro 4xHS
 	    - Kvaser USBcan Pro 5xHS
 	    - Kvaser U100
 	    - Kvaser U100P
drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c +3 -1
index 2b7efd296758..4e97da8434ab 100644
@@ -86,8 +86,9 @@
 #define USB_U100_PRODUCT_ID			273
 #define USB_U100P_PRODUCT_ID			274
 #define USB_U100S_PRODUCT_ID			275
+#define USB_USBCAN_PRO_4HS_PRODUCT_ID		276
 #define USB_HYDRA_PRODUCT_ID_END \
-	USB_U100S_PRODUCT_ID
+	USB_USBCAN_PRO_4HS_PRODUCT_ID
 
 static inline bool kvaser_is_leaf(const struct usb_device_id *id)
 {
@@ -193,6 +194,7 @@ static const struct usb_device_id kvaser_usb_table[] = {
 	{ USB_DEVICE(KVASER_VENDOR_ID, USB_U100_PRODUCT_ID) },
 	{ USB_DEVICE(KVASER_VENDOR_ID, USB_U100P_PRODUCT_ID) },
 	{ USB_DEVICE(KVASER_VENDOR_ID, USB_U100S_PRODUCT_ID) },
+	{ USB_DEVICE(KVASER_VENDOR_ID, USB_USBCAN_PRO_4HS_PRODUCT_ID) },
 	{ }
 };
 MODULE_DEVICE_TABLE(usb, kvaser_usb_table);
Signature · 1 line
2.30.1
author maintainer
#12 lore raw

PATCH 8/11 can: c_can_pci: c_can_pci_remove(): fix use-after-free

In reply to Marc Kleine-Budde

From: Tong Zhang <[email protected]>

There is a UAF in c_can_pci_remove(). dev is released by free_c_can_dev() and is used by pci_iounmap(pdev, priv->base) later. To fix this issue, save the mmio address before releasing dev.

Fixes 5b92da0443c2 ("c_can_pci: generic module for C_CAN/D_CAN on PCI")
---
 drivers/net/can/c_can/c_can_pci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/can/c_can/c_can_pci.c +2 -1
index 406b4847e5dc..7efb60b50876 100644
@@ -239,12 +239,13 @@ static void c_can_pci_remove(struct pci_dev *pdev)
 {
 	struct net_device *dev = pci_get_drvdata(pdev);
 	struct c_can_priv *priv = netdev_priv(dev);
+	void __iomem *addr = priv->base;
 
 	unregister_c_can_dev(dev);
 
 	free_c_can_dev(dev);
 
-	pci_iounmap(pdev, priv->base);
+	pci_iounmap(pdev, addr);
 	pci_disable_msi(pdev);
 	pci_clear_master(pdev);
 	pci_release_regions(pdev);
Signature · 1 line
2.30.1
author maintainer
#13 lore raw

PATCH 9/11 can: c_can: move runtime PM enable/disable to c_can_platform

In reply to Marc Kleine-Budde

From: Tong Zhang <[email protected]>

Currently doing modprobe c_can_pci will make the kernel complain:

Unbalanced pm_runtime_enable!

this is caused by pm_runtime_enable() called before pm is initialized.

This fix is similar to 227619c3ff7c, move those pm_enable/disable code to c_can_platform.

Fixes 4cdd34b26826 ("can: c_can: Add runtime PM support to Bosch C_CAN/D_CAN controller")
---
 drivers/net/can/c_can/c_can.c          | 24 +-----------------------
 drivers/net/can/c_can/c_can_platform.c |  6 +++++-
 2 files changed, 6 insertions(+), 24 deletions(-)
drivers/net/can/c_can/c_can.c +1 -23
index ef474bae47a1..6958830cb983 100644
@@ -212,18 +212,6 @@ static const struct can_bittiming_const c_can_bittiming_const = {
 	.brp_inc = 1,
 };
 
-static inline void c_can_pm_runtime_enable(const struct c_can_priv *priv)
-{
-	if (priv->device)
-		pm_runtime_enable(priv->device);
-}
-
-static inline void c_can_pm_runtime_disable(const struct c_can_priv *priv)
-{
-	if (priv->device)
-		pm_runtime_disable(priv->device);
-}
-
 static inline void c_can_pm_runtime_get_sync(const struct c_can_priv *priv)
 {
 	if (priv->device)
@@ -1335,7 +1323,6 @@ static const struct net_device_ops c_can_netdev_ops = {
 
 int register_c_can_dev(struct net_device *dev)
 {
-	struct c_can_priv *priv = netdev_priv(dev);
 	int err;
 
 	/* Deactivate pins to prevent DRA7 DCAN IP from being
@@ -1345,28 +1332,19 @@ int register_c_can_dev(struct net_device *dev)
 	 */
 	pinctrl_pm_select_sleep_state(dev->dev.parent);
 
-	c_can_pm_runtime_enable(priv);
-
 	dev->flags |= IFF_ECHO;	/* we support local echo */
 	dev->netdev_ops = &c_can_netdev_ops;
 
 	err = register_candev(dev);
-	if (err)
-		c_can_pm_runtime_disable(priv);
-	else
+	if (!err)
 		devm_can_led_init(dev);
-
 	return err;
 }
 EXPORT_SYMBOL_GPL(register_c_can_dev);
 
 void unregister_c_can_dev(struct net_device *dev)
 {
-	struct c_can_priv *priv = netdev_priv(dev);
-
 	unregister_candev(dev);
-
-	c_can_pm_runtime_disable(priv);
 }
 EXPORT_SYMBOL_GPL(unregister_c_can_dev);
 
drivers/net/can/c_can/c_can_platform.c +5 -1
index 05f425ceb53a..47b251b1607c 100644
@@ -29,6 +29,7 @@
 #include <linux/list.h>
 #include <linux/io.h>
 #include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
 #include <linux/clk.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
@@ -386,6 +387,7 @@ static int c_can_plat_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, dev);
 	SET_NETDEV_DEV(dev, &pdev->dev);
 
+	pm_runtime_enable(priv->device);
 	ret = register_c_can_dev(dev);
 	if (ret) {
 		dev_err(&pdev->dev, "registering %s failed (err=%d)\n",
@@ -398,6 +400,7 @@ static int c_can_plat_probe(struct platform_device *pdev)
 	return 0;
 
 exit_free_device:
+	pm_runtime_disable(priv->device);
 	free_c_can_dev(dev);
 exit:
 	dev_err(&pdev->dev, "probe failed\n");
@@ -408,9 +411,10 @@ static int c_can_plat_probe(struct platform_device *pdev)
 static int c_can_plat_remove(struct platform_device *pdev)
 {
 	struct net_device *dev = platform_get_drvdata(pdev);
+	struct c_can_priv *priv = netdev_priv(dev);
 
 	unregister_c_can_dev(dev);
-
+	pm_runtime_disable(priv->device);
 	free_c_can_dev(dev);
 
 	return 0;
Signature · 1 line
2.30.1
author maintainer
#14 lore raw

PATCH 10/11 can: m_can: m_can_do_rx_poll(): fix extraneous msg loss warning

In reply to Marc Kleine-Budde

From: Torin Cooper-Bennun <[email protected]>

Message loss from RX FIFO 0 is already handled in m_can_handle_lost_msg(), with netdev output included.

Removing this warning also improves driver performance under heavy load, where m_can_do_rx_poll() may be called many times before this interrupt is cleared, causing this message to be output many times (thanks Mariusz Madej for this report).

Fixes e0d1f4816f2a ("can: m_can: add Bosch M_CAN controller support")
---
 drivers/net/can/m_can/m_can.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/net/can/m_can/m_can.c +0 -3
index 3752520a7d4b..d783c46cac16 100644
@@ -501,9 +501,6 @@ static int m_can_do_rx_poll(struct net_device *dev, int quota)
 	}
 
 	while ((rxfs & RXFS_FFL_MASK) && (quota > 0)) {
-		if (rxfs & RXFS_RFL)
-			netdev_warn(dev, "Rx FIFO 0 Message Lost\n");
-
 		m_can_read_fifo(dev, rxfs);
 
 		quota--;
Signature · 1 line
2.30.1
author maintainer
#15 lore raw

PATCH 11/11 can: m_can: m_can_rx_peripheral(): fix RX being blocked by errors

In reply to Marc Kleine-Budde

From: Torin Cooper-Bennun <[email protected]>

For M_CAN peripherals, m_can_rx_handler() was called with quota = 1, which caused any error handling to block RX from taking place until the next time the IRQ handler is called. This had been observed to cause RX to be blocked indefinitely in some cases.

This is fixed by calling m_can_rx_handler with a sensibly high quota.

Fixes f524f829b75a ("can: m_can: Create a m_can platform framework")
---
 drivers/net/can/m_can/m_can.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/m_can/m_can.c +1 -1
index d783c46cac16..0c8d36bc668c 100644
@@ -873,7 +873,7 @@ static int m_can_rx_peripheral(struct net_device *dev)
 {
 	struct m_can_classdev *cdev = netdev_priv(dev);
 
-	m_can_rx_handler(dev, 1);
+	m_can_rx_handler(dev, M_CAN_NAPI_WEIGHT);
 
 	m_can_enable_all_interrupts(cdev);
 
Signature · 1 line
2.30.1