pull-request: can 2026-03-02
Subsystems (9)
Marc Kleine-Budde
maintainercover pull-request: can 2026-03-02
Hello netdev-team,
this is a pull request of 12 patches for net/main.
The first 2 patches are by Oliver Hartkopp. The first fixes the locking for CAN Broadcast Manager op runtime updates, the second fixes the packet statisctics for the CAN dummy driver.
Alban Bedel's patch fixes a potential problem in the error path of the mcp251x's ndo_open callback.
A patch by Ziyi Guo add USB endpoint type validation to the esd_usb driver.
The next 6 patches are by Greg Kroah-Hartman and fix URB data parsing for the ems_usb and ucan driver, fix URB anchoring in the etas_es58x, and in the f81604 driver fix URB data parsing, add URB error handling and fix URB anchoring.
A patch by me targets the gs_usb driver and fixes interoperability with the CANable-2.5 firmware by always configuring the bit rate before starting the device.
The last patch is by Frank Li and fixes a CHECK_DTBS warning for the nxp,sja1000 dt-binding.
regards,
Marc
---
The following changes since commit 9439a661c2e80485406ce2c90b107ca17858382d:
amd-xgbe: fix MAC_TCR_SS register width for 2.5G and 10M speeds (2026-02-28 14:22:34 -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-7.0-20260302
for you to fetch changes up to 7e1e6d6845329adb2da75110a061557e9c26d9b7:
dt-bindings: net: can: nxp,sja1000: add reference to mc-peripheral-props.yaml (2026-03-02 11:23:40 +0100)
----------------------------------------------------------------
linux-can-fixes-for-7.0-20260302
----------------------------------------------------------------
Alban Bedel (1):
can: mcp251x: fix deadlock in error path of mcp251x_open
Frank Li (1):
dt-bindings: net: can: nxp,sja1000: add reference to mc-peripheral-props.yaml
Greg Kroah-Hartman (6):
can: ems_usb: ems_usb_read_bulk_callback(): check the proper length of a message
can: ucan: Fix infinite loop from zero-length messages
can: usb: etas_es58x: correctly anchor the urb in the read bulk callback
can: usb: f81604: handle short interrupt urb messages properly
can: usb: f81604: handle bulk write errors properly
can: usb: f81604: correctly anchor the urb in the read bulk callback
Marc Kleine-Budde (2):
Merge patch series "can: usb: f81604: handle short interrupt urb messages properly"
can: gs_usb: gs_can_open(): always configure bitrates before starting device
Oliver Hartkopp (2):
can: bcm: fix locking for bcm_op runtime updates
can: dummy_can: dummy_can_init(): fix packet statistics
Ziyi Guo (1):
can: esd_usb: add endpoint type validation
.../devicetree/bindings/net/can/nxp,sja1000.yaml | 1 + drivers/net/can/dummy_can.c | 1 + drivers/net/can/spi/mcp251x.c | 15 +++++++- drivers/net/can/usb/ems_usb.c | 7 +++- drivers/net/can/usb/esd_usb.c | 30 ++++++++------- drivers/net/can/usb/etas_es58x/es58x_core.c | 8 +++- drivers/net/can/usb/f81604.c | 45 +++++++++++++++++++--- drivers/net/can/usb/gs_usb.c | 22 ++++++++--- drivers/net/can/usb/ucan.c | 2 +- net/can/bcm.c | 1 + 10 files changed, 104 insertions(+), 28 deletions(-)
Marc Kleine-Budde
maintainerPATCH 1/12 can: bcm: fix locking for bcm_op runtime updates
From: Oliver Hartkopp <[email protected]>
Commit c2aba69d0c36 ("can: bcm: add locking for bcm_op runtime updates") added a locking for some variables that can be modified at runtime when updating the sending bcm_op with a new TX_SETUP command in bcm_tx_setup().
Usually the RX_SETUP only handles and filters incoming traffic with one
exception: When the RX_RTR_FRAME flag is set a predefined CAN frame is sent when a specific RTR frame is received. Therefore the rx bcm_op uses bcm_can_tx() which uses the bcm_tx_lock that was only initialized in bcm_tx_setup(). Add the missing spin_lock_init() when allocating the bcm_op in bcm_rx_setup() to handle the RTR case properly.
--- net/can/bcm.c | 1 + 1 file changed, 1 insertion(+)
net/can/bcm.c +1 -0
@@ -1176,6 +1176,7 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,if (!op)return -ENOMEM ; +spin_lock_init (&op->bcm_tx_lock); op->can_id = msg_head->can_id; op->nframes = msg_head->nframes; op->cfsiz =CFSIZ (msg_head->flags);
base-commit: 9439a661c2e80485406ce2c90b107ca17858382d
Signature · 1 line
2.51.0
Re: [PATCH net 01/12] can: bcm: fix locking for bcm_op runtime updates
This series was applied to netdev/net.git (main) by Marc Kleine-Budde <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Marc Kleine-Budde <[email protected]>:
Quoted 6 lines · On Mon, 2 Mar 2026 16:16:07 +0100 you wrote:
From: Oliver Hartkopp <[email protected]>
Commit
c2aba69d0c36("can: bcm: add locking forbcm_opruntime updates") added a locking for some variables that can be modified at runtime when updating the sendingbcm_opwith a newTX_SETUPcommand inbcm_tx_setup().
Quoted 8 lines
Usually the
RX_SETUPonly handles and filters incoming traffic with one
exception: When theRX_RTR_FRAMEflag is set a predefined CAN frame is sent when a specific RTR frame is received. Therefore the rxbcm_opusesbcm_can_tx()which uses thebcm_tx_lockthat was only initialized inbcm_tx_setup(). Add the missingspin_lock_init()when allocating thebcm_opinbcm_rx_setup()to handle the RTR case properly.[...]
Here is the summary with links:
- [net,01/12] can: bcm: fix locking for bcm_op runtime updates
https://git.kernel.org/netdev/net/c/c35636e91e39 - [net,02/12] can: dummy_can: dummy_can_init(): fix packet statistics https://git.kernel.org/netdev/net/c/c77bfbdd6aac - [net,03/12] can: mcp251x: fix deadlock in error path of mcp251x_open https://git.kernel.org/netdev/net/c/ab3f894de216 - [net,04/12] can: esd_usb: add endpoint type validation https://git.kernel.org/netdev/net/c/968b098220e3 - [net,05/12] can: ems_usb: ems_usb_read_bulk_callback(): check the proper length of a message https://git.kernel.org/netdev/net/c/38a01c9700b0 - [net,06/12] can: ucan: Fix infinite loop from zero-length messages https://git.kernel.org/netdev/net/c/1e446fd0582a - [net,07/12] can: usb: etas_es58x: correctly anchor the urb in the read bulk callback https://git.kernel.org/netdev/net/c/5eaad4f76826 - [net,08/12] can: usb: f81604: handle short interrupt urb messages properly https://git.kernel.org/netdev/net/c/7299b1b39a25 - [net,09/12] can: usb: f81604: handle bulk write errors properly https://git.kernel.org/netdev/net/c/51f94780720f - [net,10/12] can: usb: f81604: correctly anchor the urb in the read bulk callback https://git.kernel.org/netdev/net/c/952caa5da10b - [net,11/12] can: gs_usb: gs_can_open(): always configure bitrates before starting device https://git.kernel.org/netdev/net/c/2df6162785f3 - [net,12/12] dt-bindings: net: can: nxp,sja1000: add reference to mc-peripheral-props.yaml https://git.kernel.org/netdev/net/c/7e1e6d684532
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Marc Kleine-Budde
maintainerPATCH 2/12 can: dummy_can: dummy_can_init(): fix packet statistics
In reply to Marc Kleine-BuddeFrom: Oliver Hartkopp <[email protected]>
The former implementation was only counting the tx_packets value but not the tx_bytes as the skb was dropped on driver layer.
Enable CAN echo support (IFF_ECHO) in dummy_can_init(), which activates the code for setting and retrieving the echo SKB and counts the tx_bytes correctly.
--- drivers/net/can/dummy_can.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/can/dummy_can.c +1 -0
@@ -241,6 +241,7 @@ static int __init dummy_can_init(void) dev->netdev_ops = &dummy_can_netdev_ops; dev->ethtool_ops = &dummy_can_ethtool_ops; + dev->flags |=IFF_ECHO ;/* enable echo handling */ priv =netdev_priv (dev); priv->can.bittiming_const = &dummy_can_bittiming_const; priv->can.bitrate_max =20 *MEGA /* BPS */ ;
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 3/12 can: mcp251x: fix deadlock in error path of mcp251x_open
In reply to Marc Kleine-BuddeFrom: Alban Bedel <[email protected]>
The mcp251x_open() function call free_irq() in its error path with the mpc_lock mutex held. But if an interrupt already occurred the interrupt handler will be waiting for the mpc_lock and free_irq() will deadlock waiting for the handler to finish.
This issue is similar to the one fixed in commit 7dd9c26bd6cf ("can:
mcp251x: fix deadlock if an interrupt occurs during mcp251x_open") but for the error path.
To solve this issue move the call to free_irq() after the lock is released. Setting priv->force_quit = 1 beforehand ensure that the IRQ handler will exit right away once it acquired the lock.
--- drivers/net/can/spi/mcp251x.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/net/can/spi/mcp251x.c +14 -1
@@ -1214,6 +1214,7 @@ static int mcp251x_open(struct net_device *net) {struct mcp251x_priv *priv =netdev_priv (net);struct spi_device *spi = priv->spi; +bool release_irq = false;unsigned long flags =0 ;int ret;
@@ -1257,12 +1258,24 @@ static int mcp251x_open(struct net_device *net)return 0 ; out_free_irq: -free_irq (spi->irq, priv); +/* The IRQ handler might be running, and if so it will be waiting +* for the lock. But free_irq() must wait for the handler to finish +* so calling it here would deadlock. +* +* Setting priv->force_quit will let the handler exit right away +* without any access to the hardware. This make it safe to call +* free_irq() after the lock is released. +*/ + priv->force_quit =1 ; + release_irq = true; +mcp251x_hw_sleep (spi); out_close:mcp251x_power_enable (priv->transceiver,0 );close_candev (net);mutex_unlock (&priv->mcp_lock); +if (release_irq) +free_irq (spi->irq, priv);return ret; }
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 4/12 can: esd_usb: add endpoint type validation
In reply to Marc Kleine-BuddeFrom: Ziyi Guo <[email protected]>
esd_usb_probe() constructs bulk pipes for two endpoints without verifying their transfer types:
- usb_rcvbulkpipe(dev->udev, 1) for RX (version reply, async RX data)
- usb_sndbulkpipe(dev->udev, 2) for TX (version query, CAN frames)
A malformed USB device can present these endpoints with transfer types that differ from what the driver assumes, triggering the WARNING in usb_submit_urb().
Use usb_find_common_endpoints() to discover and validate the first bulk IN and bulk OUT endpoints at probe time, before any allocation. Found pipes are saved to struct esd_usb and code uses them directly instead of making pipes in place.
Similar to
- commit 136bed0bfd3b ("can: mcba_usb: properly check endpoint type") which established the usb_find_common_endpoints() + stored pipes pattern for CAN USB drivers.
--- drivers/net/can/usb/esd_usb.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-)
drivers/net/can/usb/esd_usb.c +17 -13
@@ -272,6 +272,9 @@ struct esd_usb {struct usb_anchor rx_submitted; +unsigned int rx_pipe; +unsigned int tx_pipe; +int net_count;u32 version;int rxinitdone;
@@ -537,7 +540,7 @@ static void esd_usb_read_bulk_callback(struct urb *urb) } resubmit_urb: -usb_fill_bulk_urb (urb, dev->udev,usb_rcvbulkpipe (dev->udev,1 ), +usb_fill_bulk_urb (urb, dev->udev, dev->rx_pipe, urb->transfer_buffer,ESD_USB_RX_BUFFER_SIZE , esd_usb_read_bulk_callback, dev);
@@ -626,9 +629,7 @@ static int esd_usb_send_msg(struct esd_usb *dev, union esd_usb_msg *msg) {int actual_length; -return usb_bulk_msg (dev->udev, -usb_sndbulkpipe (dev->udev,2 ), - msg, +return usb_bulk_msg (dev->udev, dev->tx_pipe, msg, msg->hdr.len *sizeof (u32),/* convert to # of bytes */ &actual_length,1000 );
@@ -639,12 +640,8 @@ static int esd_usb_wait_msg(struct esd_usb *dev, {int actual_length; -return usb_bulk_msg (dev->udev, -usb_rcvbulkpipe (dev->udev,1 ), - msg, -sizeof (*msg), - &actual_length, -1000 ); +return usb_bulk_msg (dev->udev, dev->rx_pipe, msg, +sizeof (*msg), &actual_length,1000 ); }static int esd_usb_setup_rx_urbs (struct esd_usb *dev)
@@ -677,8 +674,7 @@ static int esd_usb_setup_rx_urbs(struct esd_usb *dev) urb->transfer_dma = buf_dma; -usb_fill_bulk_urb (urb, dev->udev, -usb_rcvbulkpipe (dev->udev,1 ), +usb_fill_bulk_urb (urb, dev->udev, dev->rx_pipe, buf,ESD_USB_RX_BUFFER_SIZE , esd_usb_read_bulk_callback, dev); urb->transfer_flags |=URB_NO_TRANSFER_DMA_MAP ;
@@ -903,7 +899,7 @@ static netdev_tx_t esd_usb_start_xmit(struct sk_buff *skb,/* hnd must not be 0 - MSB is stripped in txdone handling */ msg->tx.hnd =BIT (31 ) | i;/* returned in TX done message */ -usb_fill_bulk_urb (urb, dev->udev,usb_sndbulkpipe (dev->udev,2 ), buf, +usb_fill_bulk_urb (urb, dev->udev, dev->tx_pipe, buf, msg->hdr.len *sizeof (u32),/* convert to # of bytes */ esd_usb_write_bulk_callback, context);
@@ -1298,10 +1294,16 @@ static int esd_usb_probe_one_net(struct usb_interface *intf, int index)static int esd_usb_probe (struct usb_interface *intf,const struct usb_device_id *id) { +struct usb_endpoint_descriptor *ep_in, *ep_out;struct esd_usb *dev;union esd_usb_msg *msg;int i, err; + err =usb_find_common_endpoints (intf->cur_altsetting, &ep_in, &ep_out, +NULL ,NULL ); +if (err) +return err; + dev =kzalloc_obj (*dev);if (!dev) { err = -ENOMEM ;
@@ -1309,6 +1311,8 @@ static int esd_usb_probe(struct usb_interface *intf, } dev->udev =interface_to_usbdev (intf); + dev->rx_pipe =usb_rcvbulkpipe (dev->udev, ep_in->bEndpointAddress); + dev->tx_pipe =usb_sndbulkpipe (dev->udev, ep_out->bEndpointAddress);init_usb_anchor (&dev->rx_submitted);
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 5/12 can: ems_usb: ems_usb_read_bulk_callback(): check the proper length of a message
In reply to Marc Kleine-BuddeFrom: Greg Kroah-Hartman <[email protected]>
When looking at the data in a USB urb, the actual_length is the size of the buffer passed to the driver, not the transfer_buffer_length which is set by the driver as the max size of the buffer.
When parsing the messages in ems_usb_read_bulk_callback() properly check the size both at the beginning of parsing the message to make sure it is big enough for the expected structure, and at the end of the message to make sure we don't overflow past the end of the buffer for the next message.
--- drivers/net/can/usb/ems_usb.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/can/usb/ems_usb.c +6 -1
@@ -445,6 +445,11 @@ static void ems_usb_read_bulk_callback(struct urb *urb) start =CPC_HEADER_SIZE ;while (msg_count) { +if (start +CPC_MSG_HEADER_LEN > urb->actual_length) { +netdev_err (netdev,"format error\n" ); +break ; + } + msg = (struct ems_cpc_msg *)&ibuf[start];switch (msg->type) {
@@ -474,7 +479,7 @@ static void ems_usb_read_bulk_callback(struct urb *urb) start +=CPC_MSG_HEADER_LEN + msg->length; msg_count--; -if (start > urb->transfer_buffer_length) { +if (start > urb->actual_length) {netdev_err (netdev,"format error\n" );break ; }
Signature · 1 line
2.51.0
Paolo Abeni
maintainerRe: [PATCH net 05/12] can: ems_usb: ems_usb_read_bulk_callback(): check the proper length of a message
Quoted 41 lines · Marc Kleine-Budde
From: Greg Kroah-Hartman <[email protected]>
When looking at the data in a USB urb, the
actual_lengthis the size of the buffer passed to the driver, not thetransfer_buffer_lengthwhich is set by the driver as the max size of the buffer.When parsing the messages in
ems_usb_read_bulk_callback()properly check the size both at the beginning of parsing the message to make sure it is big enough for the expected structure, and at the end of the message to make sure we don't overflow past the end of the buffer for the next message.Cc Vincent Mailhol <[email protected]>Cc Marc Kleine-Budde <[email protected]>Assisted-by gkh_clanker_2000Signed-off-by Greg Kroah-Hartman <[email protected]>Fixes 702171adeed3 ("ems_usb: Added support for EMS CPC-USB/ARM7 CAN/USB interface")Signed-off-by Marc Kleine-Budde <[email protected]>--- drivers/net/can/usb/ems_usb.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)drivers/net/can/usb/ems_usb.c +5
-0@@ -445,6 +445,11 @@ static void ems_usb_read_bulk_callback(struct urb *urb) start =CPC_HEADER_SIZE ;while (msg_count) { +if (start +CPC_MSG_HEADER_LEN > urb->actual_length) { +netdev_err (netdev,"format error\n" ); +break ; + } + msg = (struct ems_cpc_msg *)&ibuf[start];switch (msg->type) {
drivers/net/can/usb/ems_usb.c static void ems_usb_read_bulk_callback(struct urb *urb) · line 485
Quoted 8 lines
drivers/net/can/usb/ems_usb.c +1
-1@@ -474,7 +479,7 @@ static void ems_usb_read_bulk_callback(struct urb *urb) start +=CPC_MSG_HEADER_LEN + msg->length; msg_count--; -if (start > urb->transfer_buffer_length) { +if (start > urb->actual_length) {netdev_err (netdev,"format error\n" );break ; }
AI noticed the following:
---
Does the check validate enough of the message? The code checks that the 11-byte header (CPC_MSG_HEADER_LEN) fits in the buffer, but ems_usb_rx_can_msg() and ems_usb_rx_err() both access fields in the msg->msg union payload starting at offset 11.
For example, ems_usb_rx_can_msg() reads:
- msg->msg.can_msg.id (4 bytes at offset 11)
- msg->msg.can_msg.length (1 byte at offset 15)
- msg->msg.can_msg.msg[i] (up to 8 bytes at offset 16)
Similarly, ems_usb_rx_err() reads:
- msg->msg.can_state (1 byte at offset 11)
- msg->msg.error.cc.regs.sja1000.{ecc,txerr,rxerr} (3 bytes at offset 11+)
A malicious USB device could send a packet where actual_length equals CPC_HEADER_SIZE + CPC_MSG_HEADER_LEN (15 bytes total), which would pass this check but provide zero payload bytes. The callees would then read beyond the received buffer before reaching the second check at the end of the loop.
Should the validation check that both the header and payload (msg->length bytes) fit within actual_length before calling the processing functions?
---
I guess this patch could need a follow-up? Not blocking the PR, as AFAICS worst case this patch still improves the current situation.
/P
Marc Kleine-Budde
maintainerRe: [PATCH net 05/12] can: ems_usb: ems_usb_read_bulk_callback(): check the proper length of a message
Quoted 22 lines · Paolo Abeni
AI noticed the following:
---
Does the check validate enough of the message? The code checks that the 11-byte header (CPC_MSG_HEADER_LEN) fits in the buffer, butems_usb_rx_can_msg()andems_usb_rx_err()both access fields in themsg->msgunion payload starting at offset 11.For example,
ems_usb_rx_can_msg()reads:
-msg->msg.can_msg.id(4 bytes at offset 11)
-msg->msg.can_msg.length(1 byte at offset 15)
- msg->msg.can_msg.msg[i] (up to 8 bytes at offset 16)Similarly,
ems_usb_rx_err()reads:
-msg->msg.can_state(1 byte at offset 11)
- msg->msg.error.cc.regs.sja1000.{ecc,txerr,rxerr} (3 bytes at offset 11+)A malicious USB device could send a packet where
actual_lengthequalsCPC_HEADER_SIZE+CPC_MSG_HEADER_LEN(15 bytes total), which would pass this check but provide zero payload bytes. The callees would then read beyond the received buffer before reaching the second check at the end of the loop.
Quoted 6 lines
Should the validation check that both the header and payload (
msg->lengthbytes) fit withinactual_lengthbefore calling the processing functions?
---
I guess this patch could need a follow-up? Not blocking the PR, as AFAICS worst case this patch still improves the current situation.
Yes, Greg said he'll look into this
| https://lore.kernel.org/all/2026030253-lather-pulse-3bb5@gregkh/
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung Nürnberg | Phone: +49-5121-206917-129 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
Marc Kleine-Budde
maintainerPATCH 6/12 can: ucan: Fix infinite loop from zero-length messages
In reply to Marc Kleine-BuddeFrom: Greg Kroah-Hartman <[email protected]>
If a broken ucan device gets a message with the message length field set to 0, then the driver will loop for forever in ucan_read_bulk_callback(), hanging the system. If the length is 0, just skip the message and go on to the next one.
This has been fixed in the kvaser_usb driver in the past in commit 0c73772cd2b8 ("can: kvaser_usb: leaf: Fix potential infinite loop in command parsers"), so there must be some broken devices out there like this somewhere.
--- drivers/net/can/usb/ucan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/usb/ucan.c +1 -1
@@ -748,7 +748,7 @@ static void ucan_read_bulk_callback(struct urb *urb) len =le16_to_cpu (m->len);/* check sanity (length of content) */ -if (urb->actual_length - pos < len) { +if ((len ==0 ) || (urb->actual_length - pos < len)) {netdev_warn (up->netdev,"invalid message (short; no data; l:%d)\n" , urb->actual_length);
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 7/12 can: usb: etas_es58x: correctly anchor the urb in the read bulk callback
In reply to Marc Kleine-BuddeFrom: Greg Kroah-Hartman <[email protected]>
When submitting an urb, that is using the anchor pattern, it needs to be anchored before submitting it otherwise it could be leaked if usb_kill_anchored_urbs() is called. This logic is correctly done elsewhere in the driver, except in the read bulk callback so do that here also.
--- drivers/net/can/usb/etas_es58x/es58x_core.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/net/can/usb/etas_es58x/es58x_core.c +7 -1
@@ -1461,12 +1461,18 @@ static void es58x_read_bulk_callback(struct urb *urb) } resubmit_urb: +usb_anchor_urb (urb, &es58x_dev->rx_urbs); ret =usb_submit_urb (urb,GFP_ATOMIC ); +if (!ret) +return ; + +usb_unanchor_urb (urb); +if (ret == -ENODEV ) {for (i =0 ; i < es58x_dev->num_can_ch; i++)if (es58x_dev->netdev[i])netif_device_detach (es58x_dev->netdev[i]); - }else if (ret) + }else dev_err_ratelimited (dev,"Failed resubmitting read bulk urb: %pe\n" ,ERR_PTR (ret));
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 8/12 can: usb: f81604: handle short interrupt urb messages properly
In reply to Marc Kleine-BuddeFrom: Greg Kroah-Hartman <[email protected]>
If an interrupt urb is received that is not the correct length, properly detect it and don't attempt to treat the data as valid.
--- drivers/net/can/usb/f81604.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/can/usb/f81604.c +6 -0
@@ -620,6 +620,12 @@ static void f81604_read_int_callback(struct urb *urb)netdev_info (netdev,"%s: Int URB aborted: %pe\n" , __func__,ERR_PTR (urb->status)); +if (urb->actual_length <sizeof (*data)) { +netdev_warn (netdev,"%s: short int URB: %u < %zu\n" , + __func__, urb->actual_length,sizeof (*data)); + goto resubmit_urb; + } +switch (urb->status) {case 0 :/* success */ break ;
Signature · 1 line
2.51.0
Paolo Abeni
maintainerRe: [PATCH net 08/12] can: usb: f81604: handle short interrupt urb messages properly
Quoted 25 lines · Marc Kleine-Budde
From: Greg Kroah-Hartman <[email protected]>
If an interrupt urb is received that is not the correct length, properly detect it and don't attempt to treat the data as valid.
Cc Ji-Ze Hong (Peter Hong) <[email protected]>Cc Marc Kleine-Budde <[email protected]>Cc Vincent Mailhol <[email protected]>Assisted-by gkh_clanker_2000Signed-off-by Greg Kroah-Hartman <[email protected]>Fixes 88da17436973 ("can: usb: f81604: add Fintek F81604 support")Signed-off-by Marc Kleine-Budde <[email protected]>--- drivers/net/can/usb/f81604.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/net/can/usb/f81604.c +0
-0@@ -620,6 +620,12 @@ static void f81604_read_int_callback(struct urb *urb)netdev_info (netdev,"%s: Int URB aborted: %pe\n" , __func__,ERR_PTR (urb->status));
drivers/net/can/usb/f81604.c static void f81604_read_int_callback(struct urb *urb) · line 631
Quoted 10 lines
drivers/net/can/usb/f81604.c +6
-0+if (urb->actual_length <sizeof (*data)) { +netdev_warn (netdev,"%s: short int URB: %u < %zu\n" , + __func__, urb->actual_length,sizeof (*data)); + goto resubmit_urb; + } +switch (urb->status) {case 0 :/* success */ break ;
AI says:
---
Should the length check happen after the status check instead of before it? With the current ordering, if a URB completes with both a terminal error status (like -ESHUTDOWN, -ENOENT, -EPIPE, or -EPROTO) and insufficient data length, the code will jump to resubmit_urb instead of returning immediately.
Looking at the switch statement that follows:
Quoted 9 lines
drivers/net/can/usb/f81604.c +0
-0switch (urb->status) {case 0 :/* success */ break ;case -ENOENT: case -EPIPE: case -EPROTO: case -ESHUTDOWN: return;
Terminal error codes should cause immediate return without resubmission, but the length check bypasses this. This could lead to inappropriate URB resubmissions when the device is shutting down or has been disconnected.
---
IDK if 'status' is valid in case of short URB, possibly the patch code is fine, but please have a look. Again, not blocking the PR.
/P
Greg Kroah-Hartman
maintainerRe: [PATCH net 08/12] can: usb: f81604: handle short interrupt urb messages properly
Quoted 58 lines · Paolo Abeni
Quoted 25 lines · Marc Kleine-Budde
From: Greg Kroah-Hartman <[email protected]>
If an interrupt urb is received that is not the correct length, properly detect it and don't attempt to treat the data as valid.
Cc Ji-Ze Hong (Peter Hong) <[email protected]>Cc Marc Kleine-Budde <[email protected]>Cc Vincent Mailhol <[email protected]>Assisted-by gkh_clanker_2000Signed-off-by Greg Kroah-Hartman <[email protected]>Fixes 88da17436973 ("can: usb: f81604: add Fintek F81604 support")Signed-off-by Marc Kleine-Budde <[email protected]>--- drivers/net/can/usb/f81604.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/net/can/usb/f81604.c +0
-0@@ -620,6 +620,12 @@ static void f81604_read_int_callback(struct urb *urb)netdev_info (netdev,"%s: Int URB aborted: %pe\n" , __func__,ERR_PTR (urb->status));drivers/net/can/usb/f81604.c static void f81604_read_int_callback(struct urb *urb) · line 631
Quoted 10 lines
drivers/net/can/usb/f81604.c +6
-0+if (urb->actual_length <sizeof (*data)) { +netdev_warn (netdev,"%s: short int URB: %u < %zu\n" , + __func__, urb->actual_length,sizeof (*data)); + goto resubmit_urb; + } +switch (urb->status) {case 0 :/* success */ break ;AI says:
---
Should the length check happen after the status check instead of before it? With the current ordering, if a URB completes with both a terminal error status (like-ESHUTDOWN,-ENOENT,-EPIPE, or-EPROTO) and insufficient data length, the code will jump toresubmit_urbinstead of returning immediately.Looking at the switch statement that follows:
Quoted 9 lines
drivers/net/can/usb/f81604.c +0
-0switch (urb->status) {case 0 :/* success */ break ;case -ENOENT: case -EPIPE: case -EPROTO: case -ESHUTDOWN: return;
Quoted 7 lines
Terminal error codes should cause immediate return without resubmission, but the length check bypasses this. This could lead to inappropriate URB resubmissions when the device is shutting down or has been disconnected.
---IDK if 'status' is valid in case of short URB, possibly the patch code is fine, but please have a look. Again, not blocking the PR.
status will be valid in case of a short URB, so all should be fine.
thanks,
greg k-h
Marc Kleine-Budde
maintainerPATCH 9/12 can: usb: f81604: handle bulk write errors properly
In reply to Marc Kleine-BuddeFrom: Greg Kroah-Hartman <[email protected]>
If a write urb fails then more needs to be done other than just logging the message, otherwise the transmission could be stalled. Properly increment the error counters and wake up the queues so that data will continue to flow.
--- drivers/net/can/usb/f81604.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
drivers/net/can/usb/f81604.c +21 -3
@@ -880,9 +880,27 @@ static void f81604_write_bulk_callback(struct urb *urb)if (!netif_device_present (netdev))return ; -if (urb->status) -netdev_info (netdev,"%s: Tx URB error: %pe\n" , __func__, -ERR_PTR (urb->status)); +if (!urb->status) +return ; + +switch (urb->status) { +case -ENOENT : +case -ECONNRESET : +case -ESHUTDOWN : +return ; +default : +break ; + } + +if (net_ratelimit ()) +netdev_err (netdev,"%s: Tx URB error: %pe\n" , __func__, +ERR_PTR (urb->status)); + +can_free_echo_skb (netdev,0 ,NULL ); + netdev->stats.tx_dropped++; + netdev->stats.tx_errors++; + +netif_wake_queue (netdev); }static void f81604_clear_reg_work (struct work_struct *work)
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 10/12 can: usb: f81604: correctly anchor the urb in the read bulk callback
In reply to Marc Kleine-BuddeFrom: Greg Kroah-Hartman <[email protected]>
When submitting an urb, that is using the anchor pattern, it needs to be anchored before submitting it otherwise it could be leaked if usb_kill_anchored_urbs() is called. This logic is correctly done elsewhere in the driver, except in the read bulk callback so do that here also.
--- drivers/net/can/usb/f81604.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/net/can/usb/f81604.c +13 -2
@@ -413,6 +413,7 @@ static void f81604_read_bulk_callback(struct urb *urb) {struct f81604_can_frame *frame = urb->transfer_buffer;struct net_device *netdev = urb->context; +struct f81604_port_priv *priv =netdev_priv (netdev);int ret;if (!netif_device_present (netdev))
@@ -445,10 +446,15 @@ static void f81604_read_bulk_callback(struct urb *urb)f81604_process_rx_packet (netdev, frame); resubmit_urb: +usb_anchor_urb (urb, &priv->urbs_anchor); ret =usb_submit_urb (urb,GFP_ATOMIC ); +if (!ret) +return ; +usb_unanchor_urb (urb); +if (ret == -ENODEV )netif_device_detach (netdev); -else if (ret) +else netdev_err (netdev,"%s: failed to resubmit read bulk urb: %pe\n" , __func__,ERR_PTR (ret));
@@ -652,10 +658,15 @@ static void f81604_read_int_callback(struct urb *urb)f81604_handle_tx (priv, data); resubmit_urb: +usb_anchor_urb (urb, &priv->urbs_anchor); ret =usb_submit_urb (urb,GFP_ATOMIC ); +if (!ret) +return ; +usb_unanchor_urb (urb); +if (ret == -ENODEV )netif_device_detach (netdev); -else if (ret) +else netdev_err (netdev,"%s: failed to resubmit int urb: %pe\n" , __func__,ERR_PTR (ret)); }
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 11/12 can: gs_usb: gs_can_open(): always configure bitrates before starting device
In reply to Marc Kleine-BuddeSo far the driver populated the struct can_priv::do_set_bittiming() and struct can_priv::fd::do_set_data_bittiming() callbacks.
Before bringing up the interface, user space has to configure the bitrates. With these callbacks the configuration is directly forwarded into the CAN hardware. Then the interface can be brought up.
An ifdown-ifup cycle (without changing the bit rates) doesn't re-configure the bitrates in the CAN hardware. This leads to a problem with the CANable-2.5 [1] firmware, which resets the configured bit rates during ifdown.
To fix the problem remove both bit timing callbacks and always configure the bitrates in the struct net_device_ops::ndo_open() callback.
[1] https://github.com/Elmue/CANable-2.5-firmware-Slcan-and-Candlelight
--- drivers/net/can/usb/gs_usb.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
drivers/net/can/usb/gs_usb.c +16 -6
@@ -772,9 +772,8 @@ static void gs_usb_receive_bulk_callback(struct urb *urb) } } -static int gs_usb_set_bittiming (struct net_device *netdev) +static int gs_usb_set_bittiming (struct gs_can *dev) { -struct gs_can *dev =netdev_priv (netdev);struct can_bittiming *bt = &dev->can.bittiming;struct gs_device_bittiming dbt = { .prop_seg =cpu_to_le32 (bt->prop_seg),
@@ -791,9 +790,8 @@ static int gs_usb_set_bittiming(struct net_device *netdev) GFP_KERNEL); } -static int gs_usb_set_data_bittiming (struct net_device *netdev) +static int gs_usb_set_data_bittiming (struct gs_can *dev) { -struct gs_can *dev =netdev_priv (netdev);struct can_bittiming *bt = &dev->can.fd.data_bittiming;struct gs_device_bittiming dbt = { .prop_seg =cpu_to_le32 (bt->prop_seg),
@@ -1057,6 +1055,20 @@ static int gs_can_open(struct net_device *netdev)if (dev->feature &GS_CAN_FEATURE_HW_TIMESTAMP ) flags |=GS_CAN_MODE_HW_TIMESTAMP ; + rc =gs_usb_set_bittiming (dev); +if (rc) { +netdev_err (netdev,"failed to set bittiming: %pe\n" ,ERR_PTR (rc)); + goto out_usb_kill_anchored_urbs; + } + +if (ctrlmode &CAN_CTRLMODE_FD ) { + rc =gs_usb_set_data_bittiming (dev); +if (rc) { +netdev_err (netdev,"failed to set data bittiming: %pe\n" ,ERR_PTR (rc)); + goto out_usb_kill_anchored_urbs; + } + } +/* finally start device */ dev->can.state =CAN_STATE_ERROR_ACTIVE ; dm.flags =cpu_to_le32 (flags);
@@ -1370,7 +1382,6 @@ static struct gs_can *gs_make_candev(unsigned int channel, dev->can.state =CAN_STATE_STOPPED ; dev->can.clock.freq =le32_to_cpu (bt_const.fclk_can); dev->can.bittiming_const = &dev->bt_const; - dev->can.do_set_bittiming = gs_usb_set_bittiming; dev->can.ctrlmode_supported =CAN_CTRLMODE_CC_LEN8_DLC ;
@@ -1394,7 +1405,6 @@ static struct gs_can *gs_make_candev(unsigned int channel,* GS_CAN_FEATURE_BT_CONST_EXT is set. */ dev->can.fd.data_bittiming_const = &dev->bt_const; - dev->can.fd.do_set_data_bittiming = gs_usb_set_data_bittiming; }if (feature &GS_CAN_FEATURE_TERMINATION ) {
Signature · 1 line
2.51.0
Marc Kleine-Budde
maintainerPATCH 12/12 dt-bindings: net: can: nxp,sja1000: add reference to mc-peripheral-props.yaml
In reply to Marc Kleine-BuddeFrom: Frank Li <[email protected]>
Add a reference to mc-peripheral-props.yaml to allow vendor-specific properties for memory access timings.
Fix below CHECK_DTBS warings:arch/arm/boot/dts/nxp/imx/imx27-phytec-phycore-rdk.dtb: can@4,0 (nxp,sja1000): Unevaluated properties are not allowed ('fsl,weim-cs-timing' was unexpected)
from schema $id: http://devicetree.org/schemas/net/can/nxp,sja1000.yaml
--- Documentation/devicetree/bindings/net/can/nxp,sja1000.yaml | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/net/can/nxp,sja1000.yaml +1 -0
@@ -87,6 +87,7 @@ required: allOf: - $ref: can-controller.yaml# + - $ref: /schemas/memory-controllers/mc-peripheral-props.yaml - if: properties: compatible:
Signature · 1 line
2.51.0