[PATCH v3 00/10] can: peak_usb: fixes, cleanup and input validation hardening

From: Stéphane Grosjean

Date: Tue Oct 20 2026 - 05:14:15 EST


This series contains bug fixes, cleanups and input validation
improvements for the PEAK-System USB CAN drivers.

Patch 1 fixes CAN error frame generation, where CAN_ERR_CNT overwrote
previously set CAN error flags.

Patches 2, 3 and 5 are cleanups: make a public header self-contained,
sort the CAN_CTRLMODE_* flags in ctrlmode_supported, and replace
open-coded bitmask operations with bitops. Patch 5 also makes the
state flag updates atomic, which patch 6 relies on.

Patch 4 adds bounds checks to the PCAN-USB RX parser, so that
truncated or malformed records are rejected instead of being read
beyond the received data.

Patch 6 validates the channel numbers received from PCAN-USB FD
devices, rejects records for channels that are not set up, and stops
RX on all channels before they are released, on disconnect as well as
on probe failure.

Patch 7 fixes the RX parsing of self-received RTR frames with SRR set,
which left the RX cursor one byte behind.

Patches 8 to 10 fix related issues found while reviewing the above:
the same channel slot check in the PCAN-USB Pro driver, the order of
the netdev unregistration in the probe error path, and the dump of
stale RX buffer bytes on decode errors.

---
Changes in v3:
- Fix out-of-bounds read of the error counters in PCAN-USB bus events.
- Harden channel handling in PCAN-USB FD: publish/read channel slots
with smp_store_release()/READ_ONCE(), clear them on teardown, stop RX
on all channels on disconnect and on the siblings on probe failure,
and reject ndo_open() once disconnected.
- Fix RX cursor desync for self-received RTR frames with SRR.
- Replace open-coded bitmask operations with bitops.
- Add channel slot checks to PCAN-USB Pro.
- Unregister the netdev before dev_free() on probe failure.
- Only dump received bytes, rate limited, on decode error.
- Link to v2: https://patch.msgid.link/20261009-canfd_check_channel_idx-v2-0-f7b772929791@xxxxxxxxxxxxxx

Changes in v2:
- Kill all pending RX URBs before unregistering sibling netdevs.
- Reject records targeting unavailable channels during device
initialization in rare corner cases involving malformed device
input.
- Link to v1: https://patch.msgid.link/20261008-canfd_check_channel_idx-v1-0-0a3bb82f4e09@xxxxxxxxxxxxxx

To: Marc Kleine-Budde <mkl@xxxxxxxxxxxxxx>
To: Vincent Mailhol <mailhol@xxxxxxxxxx>
To: Dan Carpenter <error27@xxxxxxxxx>
To: Wolfgang Grandegger <wg@xxxxxxxxxxxxxx>
Cc: Stéphane Grosjean <s.grosjean@xxxxxxxxxxxxxx>
Cc: linux-can@xxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx

---
Marc Kleine-Budde (1):
can: peak_usb: add missing includes

Stefan Günther (1):
can: peak_usb: fix missing CAN_ERR_FLAG when reporting error counters

Stéphane Grosjean (8):
can: peak_usb: sort ctrlmode_supported flags
can: peak_usb: harden PCAN-USB message validation
can: peak_usb: replace open-coded bitmask operations with bitops
can: peak_usb: harden channel handling in PCAN-USB FD
can: peak_usb: fix RX cursor desync for self-received RTR frames with SRR
can: peak_usb: reject records for unset channels in PCAN-USB Pro
can: peak_usb: unregister the netdev before dev_free() on probe failure
can: peak_usb: only dump received bytes on decode error

drivers/net/can/usb/peak_usb/pcan_usb.c | 44 ++++++++-----
drivers/net/can/usb/peak_usb/pcan_usb_core.c | 47 +++++++++++---
drivers/net/can/usb/peak_usb/pcan_usb_core.h | 15 ++++-
drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 96 ++++++++++++++++++++--------
drivers/net/can/usb/peak_usb/pcan_usb_pro.c | 29 +++++++--
5 files changed, 170 insertions(+), 61 deletions(-)
---
base-commit: a7bfaba4823e3c165bb2004c74eff7c096672bc7
change-id: 20261007-canfd_check_channel_idx-a4d7a1a1ee7d

Best regards,
--
Stéphane Grosjean <s.grosjean@xxxxxxxxxxxxxx>