Skip to content

Commit c649e99

Browse files
committed
Merge tag 'linux-can-fixes-for-7.0-20260302' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can
Marc Kleine-Budde says: ==================== pull-request: can 2026-03-02 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. * tag 'linux-can-fixes-for-7.0-20260302' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can: dt-bindings: net: can: nxp,sja1000: add reference to mc-peripheral-props.yaml can: gs_usb: gs_can_open(): always configure bitrates before starting device can: usb: f81604: correctly anchor the urb in the read bulk callback can: usb: f81604: handle bulk write errors properly can: usb: f81604: handle short interrupt urb messages properly can: usb: etas_es58x: correctly anchor the urb in the read bulk callback can: ucan: Fix infinite loop from zero-length messages can: ems_usb: ems_usb_read_bulk_callback(): check the proper length of a message can: esd_usb: add endpoint type validation can: mcp251x: fix deadlock in error path of mcp251x_open can: dummy_can: dummy_can_init(): fix packet statistics can: bcm: fix locking for bcm_op runtime updates ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 18b43be + 7e1e6d6 commit c649e99

10 files changed

Lines changed: 104 additions & 28 deletions

File tree

Documentation/devicetree/bindings/net/can/nxp,sja1000.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ required:
8787

8888
allOf:
8989
- $ref: can-controller.yaml#
90+
- $ref: /schemas/memory-controllers/mc-peripheral-props.yaml
9091
- if:
9192
properties:
9293
compatible:

drivers/net/can/dummy_can.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ static int __init dummy_can_init(void)
241241

242242
dev->netdev_ops = &dummy_can_netdev_ops;
243243
dev->ethtool_ops = &dummy_can_ethtool_ops;
244+
dev->flags |= IFF_ECHO; /* enable echo handling */
244245
priv = netdev_priv(dev);
245246
priv->can.bittiming_const = &dummy_can_bittiming_const;
246247
priv->can.bitrate_max = 20 * MEGA /* BPS */;

drivers/net/can/spi/mcp251x.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,7 @@ static int mcp251x_open(struct net_device *net)
12141214
{
12151215
struct mcp251x_priv *priv = netdev_priv(net);
12161216
struct spi_device *spi = priv->spi;
1217+
bool release_irq = false;
12171218
unsigned long flags = 0;
12181219
int ret;
12191220

@@ -1257,12 +1258,24 @@ static int mcp251x_open(struct net_device *net)
12571258
return 0;
12581259

12591260
out_free_irq:
1260-
free_irq(spi->irq, priv);
1261+
/* The IRQ handler might be running, and if so it will be waiting
1262+
* for the lock. But free_irq() must wait for the handler to finish
1263+
* so calling it here would deadlock.
1264+
*
1265+
* Setting priv->force_quit will let the handler exit right away
1266+
* without any access to the hardware. This make it safe to call
1267+
* free_irq() after the lock is released.
1268+
*/
1269+
priv->force_quit = 1;
1270+
release_irq = true;
1271+
12611272
mcp251x_hw_sleep(spi);
12621273
out_close:
12631274
mcp251x_power_enable(priv->transceiver, 0);
12641275
close_candev(net);
12651276
mutex_unlock(&priv->mcp_lock);
1277+
if (release_irq)
1278+
free_irq(spi->irq, priv);
12661279
return ret;
12671280
}
12681281

drivers/net/can/usb/ems_usb.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,11 @@ static void ems_usb_read_bulk_callback(struct urb *urb)
445445
start = CPC_HEADER_SIZE;
446446

447447
while (msg_count) {
448+
if (start + CPC_MSG_HEADER_LEN > urb->actual_length) {
449+
netdev_err(netdev, "format error\n");
450+
break;
451+
}
452+
448453
msg = (struct ems_cpc_msg *)&ibuf[start];
449454

450455
switch (msg->type) {
@@ -474,7 +479,7 @@ static void ems_usb_read_bulk_callback(struct urb *urb)
474479
start += CPC_MSG_HEADER_LEN + msg->length;
475480
msg_count--;
476481

477-
if (start > urb->transfer_buffer_length) {
482+
if (start > urb->actual_length) {
478483
netdev_err(netdev, "format error\n");
479484
break;
480485
}

drivers/net/can/usb/esd_usb.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ struct esd_usb {
272272

273273
struct usb_anchor rx_submitted;
274274

275+
unsigned int rx_pipe;
276+
unsigned int tx_pipe;
277+
275278
int net_count;
276279
u32 version;
277280
int rxinitdone;
@@ -537,7 +540,7 @@ static void esd_usb_read_bulk_callback(struct urb *urb)
537540
}
538541

539542
resubmit_urb:
540-
usb_fill_bulk_urb(urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
543+
usb_fill_bulk_urb(urb, dev->udev, dev->rx_pipe,
541544
urb->transfer_buffer, ESD_USB_RX_BUFFER_SIZE,
542545
esd_usb_read_bulk_callback, dev);
543546

@@ -626,9 +629,7 @@ static int esd_usb_send_msg(struct esd_usb *dev, union esd_usb_msg *msg)
626629
{
627630
int actual_length;
628631

629-
return usb_bulk_msg(dev->udev,
630-
usb_sndbulkpipe(dev->udev, 2),
631-
msg,
632+
return usb_bulk_msg(dev->udev, dev->tx_pipe, msg,
632633
msg->hdr.len * sizeof(u32), /* convert to # of bytes */
633634
&actual_length,
634635
1000);
@@ -639,12 +640,8 @@ static int esd_usb_wait_msg(struct esd_usb *dev,
639640
{
640641
int actual_length;
641642

642-
return usb_bulk_msg(dev->udev,
643-
usb_rcvbulkpipe(dev->udev, 1),
644-
msg,
645-
sizeof(*msg),
646-
&actual_length,
647-
1000);
643+
return usb_bulk_msg(dev->udev, dev->rx_pipe, msg,
644+
sizeof(*msg), &actual_length, 1000);
648645
}
649646

650647
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)
677674

678675
urb->transfer_dma = buf_dma;
679676

680-
usb_fill_bulk_urb(urb, dev->udev,
681-
usb_rcvbulkpipe(dev->udev, 1),
677+
usb_fill_bulk_urb(urb, dev->udev, dev->rx_pipe,
682678
buf, ESD_USB_RX_BUFFER_SIZE,
683679
esd_usb_read_bulk_callback, dev);
684680
urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
@@ -903,7 +899,7 @@ static netdev_tx_t esd_usb_start_xmit(struct sk_buff *skb,
903899
/* hnd must not be 0 - MSB is stripped in txdone handling */
904900
msg->tx.hnd = BIT(31) | i; /* returned in TX done message */
905901

906-
usb_fill_bulk_urb(urb, dev->udev, usb_sndbulkpipe(dev->udev, 2), buf,
902+
usb_fill_bulk_urb(urb, dev->udev, dev->tx_pipe, buf,
907903
msg->hdr.len * sizeof(u32), /* convert to # of bytes */
908904
esd_usb_write_bulk_callback, context);
909905

@@ -1298,17 +1294,25 @@ static int esd_usb_probe_one_net(struct usb_interface *intf, int index)
12981294
static int esd_usb_probe(struct usb_interface *intf,
12991295
const struct usb_device_id *id)
13001296
{
1297+
struct usb_endpoint_descriptor *ep_in, *ep_out;
13011298
struct esd_usb *dev;
13021299
union esd_usb_msg *msg;
13031300
int i, err;
13041301

1302+
err = usb_find_common_endpoints(intf->cur_altsetting, &ep_in, &ep_out,
1303+
NULL, NULL);
1304+
if (err)
1305+
return err;
1306+
13051307
dev = kzalloc_obj(*dev);
13061308
if (!dev) {
13071309
err = -ENOMEM;
13081310
goto done;
13091311
}
13101312

13111313
dev->udev = interface_to_usbdev(intf);
1314+
dev->rx_pipe = usb_rcvbulkpipe(dev->udev, ep_in->bEndpointAddress);
1315+
dev->tx_pipe = usb_sndbulkpipe(dev->udev, ep_out->bEndpointAddress);
13121316

13131317
init_usb_anchor(&dev->rx_submitted);
13141318

drivers/net/can/usb/etas_es58x/es58x_core.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1461,12 +1461,18 @@ static void es58x_read_bulk_callback(struct urb *urb)
14611461
}
14621462

14631463
resubmit_urb:
1464+
usb_anchor_urb(urb, &es58x_dev->rx_urbs);
14641465
ret = usb_submit_urb(urb, GFP_ATOMIC);
1466+
if (!ret)
1467+
return;
1468+
1469+
usb_unanchor_urb(urb);
1470+
14651471
if (ret == -ENODEV) {
14661472
for (i = 0; i < es58x_dev->num_can_ch; i++)
14671473
if (es58x_dev->netdev[i])
14681474
netif_device_detach(es58x_dev->netdev[i]);
1469-
} else if (ret)
1475+
} else
14701476
dev_err_ratelimited(dev,
14711477
"Failed resubmitting read bulk urb: %pe\n",
14721478
ERR_PTR(ret));

drivers/net/can/usb/f81604.c

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ static void f81604_read_bulk_callback(struct urb *urb)
413413
{
414414
struct f81604_can_frame *frame = urb->transfer_buffer;
415415
struct net_device *netdev = urb->context;
416+
struct f81604_port_priv *priv = netdev_priv(netdev);
416417
int ret;
417418

418419
if (!netif_device_present(netdev))
@@ -445,10 +446,15 @@ static void f81604_read_bulk_callback(struct urb *urb)
445446
f81604_process_rx_packet(netdev, frame);
446447

447448
resubmit_urb:
449+
usb_anchor_urb(urb, &priv->urbs_anchor);
448450
ret = usb_submit_urb(urb, GFP_ATOMIC);
451+
if (!ret)
452+
return;
453+
usb_unanchor_urb(urb);
454+
449455
if (ret == -ENODEV)
450456
netif_device_detach(netdev);
451-
else if (ret)
457+
else
452458
netdev_err(netdev,
453459
"%s: failed to resubmit read bulk urb: %pe\n",
454460
__func__, ERR_PTR(ret));
@@ -620,6 +626,12 @@ static void f81604_read_int_callback(struct urb *urb)
620626
netdev_info(netdev, "%s: Int URB aborted: %pe\n", __func__,
621627
ERR_PTR(urb->status));
622628

629+
if (urb->actual_length < sizeof(*data)) {
630+
netdev_warn(netdev, "%s: short int URB: %u < %zu\n",
631+
__func__, urb->actual_length, sizeof(*data));
632+
goto resubmit_urb;
633+
}
634+
623635
switch (urb->status) {
624636
case 0: /* success */
625637
break;
@@ -646,10 +658,15 @@ static void f81604_read_int_callback(struct urb *urb)
646658
f81604_handle_tx(priv, data);
647659

648660
resubmit_urb:
661+
usb_anchor_urb(urb, &priv->urbs_anchor);
649662
ret = usb_submit_urb(urb, GFP_ATOMIC);
663+
if (!ret)
664+
return;
665+
usb_unanchor_urb(urb);
666+
650667
if (ret == -ENODEV)
651668
netif_device_detach(netdev);
652-
else if (ret)
669+
else
653670
netdev_err(netdev, "%s: failed to resubmit int urb: %pe\n",
654671
__func__, ERR_PTR(ret));
655672
}
@@ -874,9 +891,27 @@ static void f81604_write_bulk_callback(struct urb *urb)
874891
if (!netif_device_present(netdev))
875892
return;
876893

877-
if (urb->status)
878-
netdev_info(netdev, "%s: Tx URB error: %pe\n", __func__,
879-
ERR_PTR(urb->status));
894+
if (!urb->status)
895+
return;
896+
897+
switch (urb->status) {
898+
case -ENOENT:
899+
case -ECONNRESET:
900+
case -ESHUTDOWN:
901+
return;
902+
default:
903+
break;
904+
}
905+
906+
if (net_ratelimit())
907+
netdev_err(netdev, "%s: Tx URB error: %pe\n", __func__,
908+
ERR_PTR(urb->status));
909+
910+
can_free_echo_skb(netdev, 0, NULL);
911+
netdev->stats.tx_dropped++;
912+
netdev->stats.tx_errors++;
913+
914+
netif_wake_queue(netdev);
880915
}
881916

882917
static void f81604_clear_reg_work(struct work_struct *work)

drivers/net/can/usb/gs_usb.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -772,9 +772,8 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
772772
}
773773
}
774774

775-
static int gs_usb_set_bittiming(struct net_device *netdev)
775+
static int gs_usb_set_bittiming(struct gs_can *dev)
776776
{
777-
struct gs_can *dev = netdev_priv(netdev);
778777
struct can_bittiming *bt = &dev->can.bittiming;
779778
struct gs_device_bittiming dbt = {
780779
.prop_seg = cpu_to_le32(bt->prop_seg),
@@ -791,9 +790,8 @@ static int gs_usb_set_bittiming(struct net_device *netdev)
791790
GFP_KERNEL);
792791
}
793792

794-
static int gs_usb_set_data_bittiming(struct net_device *netdev)
793+
static int gs_usb_set_data_bittiming(struct gs_can *dev)
795794
{
796-
struct gs_can *dev = netdev_priv(netdev);
797795
struct can_bittiming *bt = &dev->can.fd.data_bittiming;
798796
struct gs_device_bittiming dbt = {
799797
.prop_seg = cpu_to_le32(bt->prop_seg),
@@ -1057,6 +1055,20 @@ static int gs_can_open(struct net_device *netdev)
10571055
if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP)
10581056
flags |= GS_CAN_MODE_HW_TIMESTAMP;
10591057

1058+
rc = gs_usb_set_bittiming(dev);
1059+
if (rc) {
1060+
netdev_err(netdev, "failed to set bittiming: %pe\n", ERR_PTR(rc));
1061+
goto out_usb_kill_anchored_urbs;
1062+
}
1063+
1064+
if (ctrlmode & CAN_CTRLMODE_FD) {
1065+
rc = gs_usb_set_data_bittiming(dev);
1066+
if (rc) {
1067+
netdev_err(netdev, "failed to set data bittiming: %pe\n", ERR_PTR(rc));
1068+
goto out_usb_kill_anchored_urbs;
1069+
}
1070+
}
1071+
10601072
/* finally start device */
10611073
dev->can.state = CAN_STATE_ERROR_ACTIVE;
10621074
dm.flags = cpu_to_le32(flags);
@@ -1370,7 +1382,6 @@ static struct gs_can *gs_make_candev(unsigned int channel,
13701382
dev->can.state = CAN_STATE_STOPPED;
13711383
dev->can.clock.freq = le32_to_cpu(bt_const.fclk_can);
13721384
dev->can.bittiming_const = &dev->bt_const;
1373-
dev->can.do_set_bittiming = gs_usb_set_bittiming;
13741385

13751386
dev->can.ctrlmode_supported = CAN_CTRLMODE_CC_LEN8_DLC;
13761387

@@ -1394,7 +1405,6 @@ static struct gs_can *gs_make_candev(unsigned int channel,
13941405
* GS_CAN_FEATURE_BT_CONST_EXT is set.
13951406
*/
13961407
dev->can.fd.data_bittiming_const = &dev->bt_const;
1397-
dev->can.fd.do_set_data_bittiming = gs_usb_set_data_bittiming;
13981408
}
13991409

14001410
if (feature & GS_CAN_FEATURE_TERMINATION) {

drivers/net/can/usb/ucan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ static void ucan_read_bulk_callback(struct urb *urb)
748748
len = le16_to_cpu(m->len);
749749

750750
/* check sanity (length of content) */
751-
if (urb->actual_length - pos < len) {
751+
if ((len == 0) || (urb->actual_length - pos < len)) {
752752
netdev_warn(up->netdev,
753753
"invalid message (short; no data; l:%d)\n",
754754
urb->actual_length);

net/can/bcm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,7 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
11761176
if (!op)
11771177
return -ENOMEM;
11781178

1179+
spin_lock_init(&op->bcm_tx_lock);
11791180
op->can_id = msg_head->can_id;
11801181
op->nframes = msg_head->nframes;
11811182
op->cfsiz = CFSIZ(msg_head->flags);

0 commit comments

Comments
 (0)