AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/07/30 16:20 flow patch-triage
5m Args:
null

Results:
{
  "EnableConfigs": [
    "CAN_ISOTP",
    "CAN_J1939",
    "CAN_EMS_USB",
    "CAN_GS_USB",
    "CAN_KVASER_USB",
    "CAN_PEAK_USB",
    "CAN_ETAS_ES58X",
    "CAN_SOFTING",
    "CAN_CTUCANFD_PCI",
    "CAN_C_CAN_PCI"
  ],
  "FocusSymbols": [
    "isotp_sendmsg",
    "isotp_rcv",
    "isotp_rcv_echo",
    "isotp_release",
    "isotp_bind",
    "isotp_poll",
    "j1939_sk_sendmsg",
    "j1939_sk_recvmsg",
    "j1939_sk_bind",
    "j1939_sk_release",
    "j1939_tp_send",
    "j1939_tp_recv",
    "j1939_netdev_start",
    "pcan_usb_fd_decode_buf",
    "kvaser_usb_leaf_read_bulk_callback",
    "ems_usb_read_bulk_callback",
    "gs_usb_receive_bulk_callback",
    "es58x_read_bulk_callback"
  ],
  "Reasoning": "The patch series introduces functional changes to the CAN ISOTP and J1939 protocols, including a major rewrite of the ISOTP tx state machine and error handling to fix race conditions, and reference tracking for J1939 netdevs. It also adds length validation and bounds checking to several USB CAN drivers (ems_usb, gs_usb, kvaser_usb, peak_usb, etas_es58x) and fixes minor issues in other CAN drivers (c_can, ctucanfd, rcar_canfd, softing). These changes are reachable via sockets and USB fuzzing, and should be heavily fuzzed to ensure the new state machine and validation logic are correct.",
  "WorthFuzzing": true
}

1/1 2026/07/30 16:20 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit 6e7412f48e477c512df286057c5b07073d759e58\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Thu Jul 30 16:20:54 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/drivers/net/can/c_can/c_can_main.c b/drivers/net/can/c_can/c_can_main.c\nindex 3702cac7fbf0f..b3b321d9ce68d 100644\n--- a/drivers/net/can/c_can/c_can_main.c\n+++ b/drivers/net/can/c_can/c_can_main.c\n@@ -597,20 +597,20 @@ static int c_can_chip_config(struct net_device *dev)\n \t\treturn err;\n \n \t/* enable automatic retransmission */\n-\tpriv-\u003ewrite_reg(priv, C_CAN_CTRL_REG, CONTROL_ENABLE_AR);\n+\tpriv-\u003ewrite_reg(priv, C_CAN_CTRL_REG, CONTROL_ENABLE_AR | CONTROL_INIT);\n \n \tif ((priv-\u003ecan.ctrlmode \u0026 CAN_CTRLMODE_LISTENONLY) \u0026\u0026\n \t    (priv-\u003ecan.ctrlmode \u0026 CAN_CTRLMODE_LOOPBACK)) {\n \t\t/* loopback + silent mode : useful for hot self-test */\n-\t\tpriv-\u003ewrite_reg(priv, C_CAN_CTRL_REG, CONTROL_TEST);\n+\t\tpriv-\u003ewrite_reg(priv, C_CAN_CTRL_REG, CONTROL_TEST | CONTROL_INIT);\n \t\tpriv-\u003ewrite_reg(priv, C_CAN_TEST_REG, TEST_LBACK | TEST_SILENT);\n \t} else if (priv-\u003ecan.ctrlmode \u0026 CAN_CTRLMODE_LOOPBACK) {\n \t\t/* loopback mode : useful for self-test function */\n-\t\tpriv-\u003ewrite_reg(priv, C_CAN_CTRL_REG, CONTROL_TEST);\n+\t\tpriv-\u003ewrite_reg(priv, C_CAN_CTRL_REG, CONTROL_TEST | CONTROL_INIT);\n \t\tpriv-\u003ewrite_reg(priv, C_CAN_TEST_REG, TEST_LBACK);\n \t} else if (priv-\u003ecan.ctrlmode \u0026 CAN_CTRLMODE_LISTENONLY) {\n \t\t/* silent mode : bus-monitoring mode */\n-\t\tpriv-\u003ewrite_reg(priv, C_CAN_CTRL_REG, CONTROL_TEST);\n+\t\tpriv-\u003ewrite_reg(priv, C_CAN_CTRL_REG, CONTROL_TEST | CONTROL_INIT);\n \t\tpriv-\u003ewrite_reg(priv, C_CAN_TEST_REG, TEST_SILENT);\n \t}\n \ndiff --git a/drivers/net/can/ctucanfd/ctucanfd_base.c b/drivers/net/can/ctucanfd/ctucanfd_base.c\nindex 0ea1ff28dfce8..07d4aa43c700a 100644\n--- a/drivers/net/can/ctucanfd/ctucanfd_base.c\n+++ b/drivers/net/can/ctucanfd/ctucanfd_base.c\n@@ -340,8 +340,8 @@ static void ctucan_set_mode(struct ctucan_priv *priv, const struct can_ctrlmode\n \t\t\t(mode_reg \u0026 ~REG_MODE_FDE);\n \n \tmode_reg = (mode-\u003eflags \u0026 CAN_CTRLMODE_PRESUME_ACK) ?\n-\t\t\t(mode_reg | REG_MODE_ACF) :\n-\t\t\t(mode_reg \u0026 ~REG_MODE_ACF);\n+\t\t\t(mode_reg | REG_MODE_STM) :\n+\t\t\t(mode_reg \u0026 ~REG_MODE_STM);\n \n \tmode_reg = (mode-\u003eflags \u0026 CAN_CTRLMODE_FD_NON_ISO) ?\n \t\t\t(mode_reg | REG_MODE_NISOFD) :\n@@ -869,7 +869,7 @@ static void ctucan_err_interrupt(struct net_device *ndev, u32 isr)\n \t\t\tbreak;\n \t\tcase CAN_STATE_ERROR_ACTIVE:\n \t\t\tif (skb) {\n-\t\t\t\tcf-\u003ecan_id |= CAN_ERR_CNT;\n+\t\t\t\tcf-\u003ecan_id |= CAN_ERR_CRTL | CAN_ERR_CNT;\n \t\t\t\tcf-\u003edata[1] = CAN_ERR_CRTL_ACTIVE;\n \t\t\t\tcf-\u003edata[6] = bec.txerr;\n \t\t\t\tcf-\u003edata[7] = bec.rxerr;\n@@ -1136,8 +1136,12 @@ static irqreturn_t ctucan_interrupt(int irq, void *dev_id)\n \t\t/* Error interrupts */\n \t\tif (FIELD_GET(REG_INT_STAT_EWLI, isr) ||\n \t\t    FIELD_GET(REG_INT_STAT_FCSI, isr) ||\n-\t\t    FIELD_GET(REG_INT_STAT_ALI, isr)) {\n-\t\t\ticr = isr \u0026 (REG_INT_STAT_EWLI | REG_INT_STAT_FCSI | REG_INT_STAT_ALI);\n+\t\t    FIELD_GET(REG_INT_STAT_ALI, isr) ||\n+\t\t    FIELD_GET(REG_INT_STAT_BEI, isr)) {\n+\t\t\ticr = isr \u0026 (REG_INT_STAT_EWLI |\n+\t\t\t\t     REG_INT_STAT_FCSI |\n+\t\t\t\t     REG_INT_STAT_ALI |\n+\t\t\t\t     REG_INT_STAT_BEI);\n \n \t\t\tctucan_netdev_dbg(ndev, \"some ERR interrupt: clearing 0x%08x\\n\", icr);\n \t\t\tctucan_write32(priv, CTUCANFD_INT_STAT, icr);\ndiff --git a/drivers/net/can/ctucanfd/ctucanfd_pci.c b/drivers/net/can/ctucanfd/ctucanfd_pci.c\nindex 625788fa89766..4b6db28f7b670 100644\n--- a/drivers/net/can/ctucanfd/ctucanfd_pci.c\n+++ b/drivers/net/can/ctucanfd/ctucanfd_pci.c\n@@ -194,7 +194,7 @@ static int ctucan_pci_probe(struct pci_dev *pdev,\n \tpci_set_drvdata(pdev, NULL);\n \tkfree(bdata);\n err_pci_iounmap_bar0:\n-\tpci_iounmap(pdev, cra_addr);\n+\tpci_iounmap(pdev, bar0_base);\n err_pci_iounmap_bar1:\n \tpci_iounmap(pdev, addr);\n err_release_regions:\n@@ -266,6 +266,7 @@ static const struct pci_device_id ctucan_pci_tbl[] = {\n \t\tCTUCAN_WITH_CTUCAN_ID)},\n \t{},\n };\n+MODULE_DEVICE_TABLE(pci, ctucan_pci_tbl);\n \n static struct pci_driver ctucan_pci_driver = {\n \t.name = KBUILD_MODNAME,\ndiff --git a/drivers/net/can/rcar/rcar_canfd.c b/drivers/net/can/rcar/rcar_canfd.c\nindex eaf8cac780387..fcc37b73ed436 100644\n--- a/drivers/net/can/rcar/rcar_canfd.c\n+++ b/drivers/net/can/rcar/rcar_canfd.c\n@@ -2003,20 +2003,12 @@ static int rcar_canfd_global_init(struct rcar_canfd_global *gpriv)\n \tu32 ch, sts;\n \tint err;\n \n-\terr = reset_control_reset(gpriv-\u003erstc1);\n-\tif (err)\n-\t\treturn err;\n-\n-\terr = reset_control_reset(gpriv-\u003erstc2);\n-\tif (err)\n-\t\tgoto fail_reset1;\n-\n \t/* Enable peripheral clock for register access */\n \terr = clk_prepare_enable(gpriv-\u003eclkp);\n \tif (err) {\n \t\tdev_err(dev, \"failed to enable peripheral clock: %pe\\n\",\n \t\t\tERR_PTR(err));\n-\t\tgoto fail_reset2;\n+\t\treturn err;\n \t}\n \n \t/* Enable RAM clock */\n@@ -2027,10 +2019,18 @@ static int rcar_canfd_global_init(struct rcar_canfd_global *gpriv)\n \t\tgoto fail_clk;\n \t}\n \n+\terr = reset_control_reset(gpriv-\u003erstc1);\n+\tif (err)\n+\t\tgoto fail_ram_clk;\n+\n+\terr = reset_control_reset(gpriv-\u003erstc2);\n+\tif (err)\n+\t\tgoto fail_reset1;\n+\n \terr = rcar_canfd_reset_controller(gpriv);\n \tif (err) {\n \t\tdev_err(dev, \"reset controller failed: %pe\\n\", ERR_PTR(err));\n-\t\tgoto fail_ram_clk;\n+\t\tgoto fail_reset2;\n \t}\n \n \t/* Controller in Global reset \u0026 Channel reset mode */\n@@ -2068,14 +2068,14 @@ static int rcar_canfd_global_init(struct rcar_canfd_global *gpriv)\n \n fail_mode:\n \trcar_canfd_disable_global_interrupts(gpriv);\n-fail_ram_clk:\n-\tclk_disable_unprepare(gpriv-\u003eclk_ram);\n-fail_clk:\n-\tclk_disable_unprepare(gpriv-\u003eclkp);\n fail_reset2:\n \treset_control_assert(gpriv-\u003erstc2);\n fail_reset1:\n \treset_control_assert(gpriv-\u003erstc1);\n+fail_ram_clk:\n+\tclk_disable_unprepare(gpriv-\u003eclk_ram);\n+fail_clk:\n+\tclk_disable_unprepare(gpriv-\u003eclkp);\n \treturn err;\n }\n \n@@ -2090,10 +2090,10 @@ static void rcar_canfd_global_deinit(struct rcar_canfd_global *gpriv, bool full)\n \t\trcar_canfd_set_bit(gpriv-\u003ebase, RCANFD_GCTR, RCANFD_GCTR_GSLPR);\n \t}\n \n-\tclk_disable_unprepare(gpriv-\u003eclk_ram);\n-\tclk_disable_unprepare(gpriv-\u003eclkp);\n \treset_control_assert(gpriv-\u003erstc2);\n \treset_control_assert(gpriv-\u003erstc1);\n+\tclk_disable_unprepare(gpriv-\u003eclk_ram);\n+\tclk_disable_unprepare(gpriv-\u003eclkp);\n }\n \n static int rcar_canfd_probe(struct platform_device *pdev)\ndiff --git a/drivers/net/can/softing/softing_fw.c b/drivers/net/can/softing/softing_fw.c\nindex 721df91cdbfbc..282570daf3efe 100644\n--- a/drivers/net/can/softing/softing_fw.c\n+++ b/drivers/net/can/softing/softing_fw.c\n@@ -91,12 +91,12 @@ int softing_bootloader_command(struct softing *card, int16_t cmd,\n \treturn ret;\n }\n \n-static int fw_parse(const uint8_t **pmem, uint16_t *ptype, uint32_t *paddr,\n-\t\tuint16_t *plen, const uint8_t **pdat)\n+static int fw_parse(const u8 **pmem, const u8 *limit, u16 *ptype,\n+\t\t    u32 *paddr, u16 *plen, const u8 **pdat)\n {\n \tuint16_t checksum[2];\n-\tconst uint8_t *mem;\n-\tconst uint8_t *end;\n+\tconst u8 *mem;\n+\tconst u8 *record_end;\n \n \t/*\n \t * firmware records are a binary, unaligned stream composed of:\n@@ -114,14 +114,21 @@ static int fw_parse(const uint8_t **pmem, uint16_t *ptype, uint32_t *paddr,\n \t * endianness \u0026 alignment.\n \t */\n \tmem = *pmem;\n+\t/* A record needs an 8-byte prefix and a 2-byte checksum. */\n+\tif (mem \u003e limit || limit - mem \u003c 10)\n+\t\treturn -EINVAL;\n+\n \t*ptype = le16_to_cpup((void *)\u0026mem[0]);\n \t*paddr = le32_to_cpup((void *)\u0026mem[2]);\n \t*plen = le16_to_cpup((void *)\u0026mem[6]);\n+\tif (*plen \u003e limit - mem - 10)\n+\t\treturn -EINVAL;\n+\n \t*pdat = \u0026mem[8];\n \t/* verify checksum */\n-\tend = \u0026mem[8 + *plen];\n-\tchecksum[0] = le16_to_cpup((void *)end);\n-\tfor (checksum[1] = 0; mem \u003c end; ++mem)\n+\trecord_end = \u0026mem[8 + *plen];\n+\tchecksum[0] = le16_to_cpup((void *)record_end);\n+\tfor (checksum[1] = 0; mem \u003c record_end; ++mem)\n \t\tchecksum[1] += *mem;\n \tif (checksum[0] != checksum[1])\n \t\treturn -EINVAL;\n@@ -139,6 +146,7 @@ int softing_load_fw(const char *file, struct softing *card,\n \tuint16_t type, len;\n \tuint32_t addr;\n \tuint8_t *buf = NULL, *new_buf;\n+\ts64 dpram_offset;\n \tint buflen = 0;\n \tint8_t type_end = 0;\n \n@@ -153,7 +161,7 @@ int softing_load_fw(const char *file, struct softing *card,\n \tmem = fw-\u003edata;\n \tend = \u0026mem[fw-\u003esize];\n \t/* look for header record */\n-\tret = fw_parse(\u0026mem, \u0026type, \u0026addr, \u0026len, \u0026dat);\n+\tret = fw_parse(\u0026mem, end, \u0026type, \u0026addr, \u0026len, \u0026dat);\n \tif (ret \u003c 0)\n \t\tgoto failed;\n \tif (type != 0xffff)\n@@ -164,7 +172,7 @@ int softing_load_fw(const char *file, struct softing *card,\n \t}\n \t/* ok, we had a header */\n \twhile (mem \u003c end) {\n-\t\tret = fw_parse(\u0026mem, \u0026type, \u0026addr, \u0026len, \u0026dat);\n+\t\tret = fw_parse(\u0026mem, end, \u0026type, \u0026addr, \u0026len, \u0026dat);\n \t\tif (ret \u003c 0)\n \t\t\tgoto failed;\n \t\tif (type == 3) {\n@@ -179,9 +187,13 @@ int softing_load_fw(const char *file, struct softing *card,\n \t\t\tgoto failed;\n \t\t}\n \n-\t\tif ((addr + len + offset) \u003e size)\n+\t\tdpram_offset = (s64)addr + offset;\n+\t\tif (dpram_offset \u003c 0 || dpram_offset \u003e size ||\n+\t\t    len \u003e size - dpram_offset) {\n+\t\t\tret = -EINVAL;\n \t\t\tgoto failed;\n-\t\tmemcpy_toio(\u0026dpram[addr + offset], dat, len);\n+\t\t}\n+\t\tmemcpy_toio(\u0026dpram[dpram_offset], dat, len);\n \t\t/* be sure to flush caches from IO space */\n \t\tmb();\n \t\tif (len \u003e buflen) {\n@@ -195,7 +207,7 @@ int softing_load_fw(const char *file, struct softing *card,\n \t\t\tbuf = new_buf;\n \t\t}\n \t\t/* verify record data */\n-\t\tmemcpy_fromio(buf, \u0026dpram[addr + offset], len);\n+\t\tmemcpy_fromio(buf, \u0026dpram[dpram_offset], len);\n \t\tif (memcmp(buf, dat, len)) {\n \t\t\t/* is not ok */\n \t\t\tdev_alert(\u0026card-\u003epdev-\u003edev, \"DPRAM readback failed\\n\");\n@@ -237,7 +249,7 @@ int softing_load_app_fw(const char *file, struct softing *card)\n \tmem = fw-\u003edata;\n \tend = \u0026mem[fw-\u003esize];\n \t/* look for header record */\n-\tret = fw_parse(\u0026mem, \u0026type, \u0026addr, \u0026len, \u0026dat);\n+\tret = fw_parse(\u0026mem, end, \u0026type, \u0026addr, \u0026len, \u0026dat);\n \tif (ret)\n \t\tgoto failed;\n \tret = -EINVAL;\n@@ -253,7 +265,7 @@ int softing_load_app_fw(const char *file, struct softing *card)\n \t}\n \t/* ok, we had a header */\n \twhile (mem \u003c end) {\n-\t\tret = fw_parse(\u0026mem, \u0026type, \u0026addr, \u0026len, \u0026dat);\n+\t\tret = fw_parse(\u0026mem, end, \u0026type, \u0026addr, \u0026len, \u0026dat);\n \t\tif (ret)\n \t\t\tgoto failed;\n \n@@ -279,6 +291,12 @@ int softing_load_app_fw(const char *file, struct softing *card)\n \t\t/* work in 16bit (target) */\n \t\tsum \u0026= 0xffff;\n \n+\t\tif (card-\u003epdat-\u003eapp.offs \u003e card-\u003edpram_size ||\n+\t\t    len \u003e card-\u003edpram_size - card-\u003epdat-\u003eapp.offs) {\n+\t\t\tret = -EINVAL;\n+\t\t\tgoto failed;\n+\t\t}\n+\n \t\tmemcpy_toio(\u0026card-\u003edpram[card-\u003epdat-\u003eapp.offs], dat, len);\n \t\tiowrite32(card-\u003epdat-\u003eapp.offs + card-\u003epdat-\u003eapp.addr,\n \t\t\t\t\u0026card-\u003edpram[DPRAM_COMMAND + 2]);\ndiff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c\nindex 9b25dda7c1838..24cf8f651f8f1 100644\n--- a/drivers/net/can/usb/ems_usb.c\n+++ b/drivers/net/can/usb/ems_usb.c\n@@ -409,6 +409,40 @@ static void ems_usb_rx_err(struct ems_usb *dev, struct ems_cpc_msg *msg)\n \t\tnetif_rx(skb);\n }\n \n+static bool ems_usb_rx_msg_len_valid(struct ems_cpc_msg *msg)\n+{\n+\tsize_t len = msg-\u003elength;\n+\tsize_t can_len;\n+\n+\tswitch (msg-\u003etype) {\n+\tcase CPC_MSG_TYPE_CAN_STATE:\n+\t\treturn len \u003e= sizeof(msg-\u003emsg.can_state);\n+\n+\tcase CPC_MSG_TYPE_CAN_FRAME:\n+\tcase CPC_MSG_TYPE_EXT_CAN_FRAME:\n+\tcase CPC_MSG_TYPE_RTR_FRAME:\n+\tcase CPC_MSG_TYPE_EXT_RTR_FRAME:\n+\t\tif (len \u003c CPC_CAN_MSG_MIN_SIZE)\n+\t\t\treturn false;\n+\n+\t\tif (msg-\u003etype == CPC_MSG_TYPE_RTR_FRAME ||\n+\t\t    msg-\u003etype == CPC_MSG_TYPE_EXT_RTR_FRAME)\n+\t\t\treturn true;\n+\n+\t\tcan_len = can_cc_dlc2len(msg-\u003emsg.can_msg.length \u0026 0xf);\n+\t\treturn len \u003e= CPC_CAN_MSG_MIN_SIZE + can_len;\n+\n+\tcase CPC_MSG_TYPE_CAN_FRAME_ERROR:\n+\t\treturn len \u003e= sizeof(msg-\u003emsg.error);\n+\n+\tcase CPC_MSG_TYPE_OVERRUN:\n+\t\treturn len \u003e= sizeof(msg-\u003emsg.overrun);\n+\n+\tdefault:\n+\t\treturn true;\n+\t}\n+}\n+\n /*\n  * callback for bulk IN urb\n  */\n@@ -451,6 +485,15 @@ static void ems_usb_read_bulk_callback(struct urb *urb)\n \t\t\t}\n \n \t\t\tmsg = (struct ems_cpc_msg *)\u0026ibuf[start];\n+\t\t\tif (msg-\u003elength \u003e\n+\t\t\t    urb-\u003eactual_length - start - CPC_MSG_HEADER_LEN) {\n+\t\t\t\tnetdev_err(netdev, \"format error\\n\");\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\tif (!ems_usb_rx_msg_len_valid(msg)) {\n+\t\t\t\tnetdev_err(netdev, \"format error\\n\");\n+\t\t\t\tbreak;\n+\t\t\t}\n \n \t\t\tswitch (msg-\u003etype) {\n \t\t\tcase CPC_MSG_TYPE_CAN_STATE:\ndiff --git a/drivers/net/can/usb/etas_es58x/es58x_core.c b/drivers/net/can/usb/etas_es58x/es58x_core.c\nindex b259f61098083..e1724ae79c5a1 100644\n--- a/drivers/net/can/usb/etas_es58x/es58x_core.c\n+++ b/drivers/net/can/usb/etas_es58x/es58x_core.c\n@@ -1476,7 +1476,6 @@ static void es58x_read_bulk_callback(struct urb *urb)\n \t\tdev_err_ratelimited(dev,\n \t\t\t\t    \"Failed resubmitting read bulk urb: %pe\\n\",\n \t\t\t\t    ERR_PTR(ret));\n-\treturn;\n \n  free_urb:\n \tusb_free_coherent(urb-\u003edev, urb-\u003etransfer_buffer_length,\ndiff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c\nindex ec9a7cbbbc696..82508a8650959 100644\n--- a/drivers/net/can/usb/gs_usb.c\n+++ b/drivers/net/can/usb/gs_usb.c\n@@ -674,7 +674,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)\n \t\tif (hf-\u003eflags \u0026 GS_CAN_FLAG_FD) {\n \t\t\tskb = alloc_canfd_skb(netdev, \u0026cfd);\n \t\t\tif (!skb)\n-\t\t\t\treturn;\n+\t\t\t\tgoto resubmit_urb;\n \n \t\t\tcfd-\u003ecan_id = le32_to_cpu(hf-\u003ecan_id);\n \t\t\tcfd-\u003elen = data_length;\n@@ -687,7 +687,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)\n \t\t} else {\n \t\t\tskb = alloc_can_skb(netdev, \u0026cf);\n \t\t\tif (!skb)\n-\t\t\t\treturn;\n+\t\t\t\tgoto resubmit_urb;\n \n \t\t\tcf-\u003ecan_id = le32_to_cpu(hf-\u003ecan_id);\n \t\t\tcan_frame_set_cc_len(cf, hf-\u003ecan_dlc, dev-\u003ecan.ctrlmode);\ndiff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c\nindex e09d663e362f9..efbb7bed34c9d 100644\n--- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c\n+++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c\n@@ -1626,6 +1626,7 @@ static int kvaser_usb_hydra_get_busparams(struct kvaser_usb_net_priv *priv,\n \treinit_completion(\u0026priv-\u003eget_busparams_comp);\n \n \terr = kvaser_usb_send_cmd(dev, cmd, cmd_len);\n+\tkfree(cmd);\n \tif (err)\n \t\treturn err;\n \ndiff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c\nindex df737cfc5ea0c..a876c7819b81c 100644\n--- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c\n+++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c\n@@ -691,13 +691,22 @@ static int kvaser_usb_leaf_wait_cmd(const struct kvaser_usb *dev, u8 id,\n \t\t\t\tcontinue;\n \t\t\t}\n \n-\t\t\tif (pos + tmp-\u003elen \u003e actual_len) {\n+\t\t\tif (tmp-\u003elen \u003c CMD_HEADER_LEN ||\n+\t\t\t    tmp-\u003elen \u003e actual_len - pos) {\n \t\t\t\tdev_err_ratelimited(\u0026dev-\u003eintf-\u003edev,\n \t\t\t\t\t\t    \"Format error\\n\");\n \t\t\t\tbreak;\n \t\t\t}\n \n \t\t\tif (tmp-\u003eid == id) {\n+\t\t\t\tif (tmp-\u003elen \u003e sizeof(*cmd)) {\n+\t\t\t\t\tdev_err_ratelimited(\u0026dev-\u003eintf-\u003edev,\n+\t\t\t\t\t\t\t    \"Received command %u too large (%u)\\n\",\n+\t\t\t\t\t\t\t    tmp-\u003eid, tmp-\u003elen);\n+\t\t\t\t\terr = -EIO;\n+\t\t\t\t\tgoto end;\n+\t\t\t\t}\n+\n \t\t\t\tmemcpy(cmd, tmp, tmp-\u003elen);\n \t\t\t\tgoto end;\n \t\t\t}\n@@ -1737,7 +1746,7 @@ static void kvaser_usb_leaf_read_bulk_callback(struct kvaser_usb *dev,\n \t\t\tcontinue;\n \t\t}\n \n-\t\tif (pos + cmd-\u003elen \u003e len) {\n+\t\tif (cmd-\u003elen \u003c CMD_HEADER_LEN || cmd-\u003elen \u003e len - pos) {\n \t\t\tdev_err_ratelimited(\u0026dev-\u003eintf-\u003edev, \"Format error\\n\");\n \t\t\tbreak;\n \t\t}\ndiff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c\nindex c7933d1acc99a..55aad01cd8cac 100644\n--- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c\n+++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c\n@@ -470,7 +470,6 @@ static int peak_usb_start(struct peak_usb_device *dev)\n \t\t\t\tnetif_device_detach(dev-\u003enetdev);\n \n \t\t\tusb_unanchor_urb(urb);\n-\t\t\tkfree(buf);\n \t\t\tusb_free_urb(urb);\n \t\t\tbreak;\n \t\t}\ndiff --git a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c\nindex ef9fd693e9bd3..0d46f4ce5dca7 100644\n--- a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c\n+++ b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c\n@@ -566,6 +566,13 @@ static int pcan_usb_fd_decode_canmsg(struct pcan_usb_fd_if *usb_if,\n \t\t\t\t     dev-\u003ecan.ctrlmode);\n \t}\n \n+\tif (!(rx_msg_flags \u0026 PUCAN_MSG_RTR) \u0026\u0026\n+\t    le16_to_cpu(rx_msg-\u003esize) - offsetof(struct pucan_rx_msg, d) \u003c\n+\t    cfd-\u003elen) {\n+\t\tkfree_skb(skb);\n+\t\treturn -EBADMSG;\n+\t}\n+\n \tcfd-\u003ecan_id = le32_to_cpu(rm-\u003ecan_id);\n \n \tif (rx_msg_flags \u0026 PUCAN_MSG_EXT_ID)\n@@ -714,6 +721,24 @@ static void pcan_usb_fd_decode_ts(struct pcan_usb_fd_if *usb_if,\n \t\tpeak_usb_set_ts_now(\u0026usb_if-\u003etime_ref, le32_to_cpu(ts-\u003ets_low));\n }\n \n+static size_t pcan_usb_fd_rx_msg_min_size(u16 rx_msg_type)\n+{\n+\tswitch (rx_msg_type) {\n+\tcase PUCAN_MSG_CAN_RX:\n+\t\treturn offsetof(struct pucan_rx_msg, d);\n+\tcase PCAN_UFD_MSG_CALIBRATION:\n+\t\treturn sizeof(struct pcan_ufd_ts_msg);\n+\tcase PUCAN_MSG_ERROR:\n+\t\treturn sizeof(struct pucan_error_msg);\n+\tcase PUCAN_MSG_STATUS:\n+\t\treturn sizeof(struct pucan_status_msg);\n+\tcase PCAN_UFD_MSG_OVERRUN:\n+\t\treturn sizeof(struct pcan_ufd_ovr_msg);\n+\tdefault:\n+\t\treturn sizeof(struct pucan_msg);\n+\t}\n+}\n+\n /* callback for bulk IN urb */\n static int pcan_usb_fd_decode_buf(struct peak_usb_device *dev, struct urb *urb)\n {\n@@ -728,6 +753,12 @@ static int pcan_usb_fd_decode_buf(struct peak_usb_device *dev, struct urb *urb)\n \tmsg_end = urb-\u003etransfer_buffer + urb-\u003eactual_length;\n \tfor (; msg_ptr \u003c msg_end;) {\n \t\tu16 rx_msg_type, rx_msg_size;\n+\t\tsize_t rx_msg_min_size;\n+\n+\t\tif (msg_end - msg_ptr \u003c sizeof(*rx_msg)) {\n+\t\t\terr = -EBADMSG;\n+\t\t\tbreak;\n+\t\t}\n \n \t\trx_msg = (struct pucan_msg *)msg_ptr;\n \t\tif (!rx_msg-\u003esize) {\n@@ -739,13 +770,20 @@ static int pcan_usb_fd_decode_buf(struct peak_usb_device *dev, struct urb *urb)\n \t\trx_msg_type = le16_to_cpu(rx_msg-\u003etype);\n \n \t\t/* check if the record goes out of current packet */\n-\t\tif (msg_ptr + rx_msg_size \u003e msg_end) {\n+\t\tif (rx_msg_size \u003e msg_end - msg_ptr) {\n \t\t\tnetdev_err(netdev,\n \t\t\t\t   \"got frag rec: should inc usb rx buf sze\\n\");\n \t\t\terr = -EBADMSG;\n \t\t\tbreak;\n \t\t}\n \n+\t\trx_msg_min_size = pcan_usb_fd_rx_msg_min_size(rx_msg_type);\n+\t\tif (rx_msg_size \u003c rx_msg_min_size) {\n+\t\t\tnetdev_err(netdev, \"got short rec\\n\");\n+\t\t\terr = -EBADMSG;\n+\t\t\tbreak;\n+\t\t}\n+\n \t\tswitch (rx_msg_type) {\n \t\tcase PUCAN_MSG_CAN_RX:\n \t\t\terr = pcan_usb_fd_decode_canmsg(usb_if, rx_msg);\ndiff --git a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c\nindex aefcded8e12a8..b6be8c19e537f 100644\n--- a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c\n+++ b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c\n@@ -534,12 +534,18 @@ static int pcan_usb_pro_handle_canmsg(struct pcan_usb_pro_interface *usb_if,\n \t\t\t\t      struct pcan_usb_pro_rxmsg *rx)\n {\n \tconst unsigned int ctrl_idx = (rx-\u003elen \u003e\u003e 4) \u0026 0x0f;\n-\tstruct peak_usb_device *dev = usb_if-\u003edev[ctrl_idx];\n-\tstruct net_device *netdev = dev-\u003enetdev;\n+\tstruct peak_usb_device *dev;\n+\tstruct net_device *netdev;\n \tstruct can_frame *can_frame;\n \tstruct sk_buff *skb;\n \tstruct skb_shared_hwtstamps *hwts;\n \n+\tif (ctrl_idx \u003e= ARRAY_SIZE(usb_if-\u003edev))\n+\t\treturn -EINVAL;\n+\n+\tdev = usb_if-\u003edev[ctrl_idx];\n+\tnetdev = dev-\u003enetdev;\n+\n \tskb = alloc_can_skb(netdev, \u0026can_frame);\n \tif (!skb)\n \t\treturn -ENOMEM;\n@@ -573,14 +579,20 @@ static int pcan_usb_pro_handle_error(struct pcan_usb_pro_interface *usb_if,\n {\n \tconst u16 raw_status = le16_to_cpu(er-\u003estatus);\n \tconst unsigned int ctrl_idx = (er-\u003echannel \u003e\u003e 4) \u0026 0x0f;\n-\tstruct peak_usb_device *dev = usb_if-\u003edev[ctrl_idx];\n-\tstruct net_device *netdev = dev-\u003enetdev;\n+\tstruct peak_usb_device *dev;\n+\tstruct net_device *netdev;\n \tstruct can_frame *can_frame;\n \tenum can_state new_state = CAN_STATE_ERROR_ACTIVE;\n \tu8 err_mask = 0;\n \tstruct sk_buff *skb;\n \tstruct skb_shared_hwtstamps *hwts;\n \n+\tif (ctrl_idx \u003e= ARRAY_SIZE(usb_if-\u003edev))\n+\t\treturn -EINVAL;\n+\n+\tdev = usb_if-\u003edev[ctrl_idx];\n+\tnetdev = dev-\u003enetdev;\n+\n \t/* nothing should be sent while in BUS_OFF state */\n \tif (dev-\u003ecan.state == CAN_STATE_BUS_OFF)\n \t\treturn 0;\ndiff --git a/net/can/isotp.c b/net/can/isotp.c\nindex 54becaf6898f1..155530aedce2e 100644\n--- a/net/can/isotp.c\n+++ b/net/can/isotp.c\n@@ -127,6 +127,15 @@ MODULE_PARM_DESC(max_pdu_size, \"maximum isotp pdu size (default \"\n #define ISOTP_FC_TIMEOUT 1\t/* 1 sec */\n #define ISOTP_ECHO_TIMEOUT 2\t/* 2 secs */\n \n+/* so-\u003etx_result[so-\u003etx_gen % ISOTP_TX_RESULT_SLOTS] holds the packed value\n+ * (err \u003c\u003c ISOTP_TX_RESULT_GEN_BITS | gen) for each tx generation slot, so it\n+ * can be handled with a single READ_ONCE()/WRITE_ONCE() access.\n+ */\n+#define ISOTP_TX_RESULT_SLOTS 4\n+#define ISOTP_TX_RESULT_GEN_BITS 24\n+#define ISOTP_TX_RESULT_GEN_MASK ((1U \u003c\u003c ISOTP_TX_RESULT_GEN_BITS) - 1)\n+#define ISOTP_TX_RESULT_ERR_MASK 0xFF\n+\n enum {\n \tISOTP_IDLE = 0,\n \tISOTP_WAIT_FIRST_FC,\n@@ -166,7 +175,8 @@ struct isotp_sock {\n \tu32 force_tx_stmin;\n \tu32 force_rx_stmin;\n \tu32 cfecho; /* consecutive frame echo tag */\n-\tu32 tx_gen; /* generation, bumped per new tx transfer */\n+\tu32 tx_gen; /* transfer generation, increased per new tx transfer */\n+\tu32 tx_result[ISOTP_TX_RESULT_SLOTS]; /* per-generation result slots */\n \tstruct tpcon rx, tx;\n \tstruct list_head notifier;\n \twait_queue_head_t wait;\n@@ -177,6 +187,65 @@ static LIST_HEAD(isotp_notifier_list);\n static DEFINE_SPINLOCK(isotp_notifier_lock);\n static struct isotp_sock *isotp_busy_notifier;\n \n+/* increase (24 bit) tx generation value */\n+static u32 isotp_inc_tx_gen(u32 gen)\n+{\n+\treturn (gen + 1) \u0026 ISOTP_TX_RESULT_GEN_MASK;\n+}\n+\n+/* store 8 bit error and 24 bit tx generation values in packed u32 element */\n+static u32 isotp_pack_tx_result(u32 gen, int err)\n+{\n+\treturn gen | ((u32)err \u003c\u003c ISOTP_TX_RESULT_GEN_BITS);\n+}\n+\n+/* get the 24 bit tx generation value from the tx result */\n+static u32 isotp_get_tx_gen(u32 gen_err)\n+{\n+\treturn gen_err \u0026 ISOTP_TX_RESULT_GEN_MASK;\n+}\n+\n+/* get the 8 bit error value from the tx result */\n+static u32 isotp_get_tx_err(u32 gen_err)\n+{\n+\treturn (gen_err \u003e\u003e ISOTP_TX_RESULT_GEN_BITS) \u0026 ISOTP_TX_RESULT_ERR_MASK;\n+}\n+\n+/* store transfer result in per-generation%4 so-\u003etx_result[] slot */\n+static void isotp_set_tx_result(struct isotp_sock *so, u32 gen, int err)\n+{\n+\tWRITE_ONCE(so-\u003etx_result[gen % ISOTP_TX_RESULT_SLOTS],\n+\t\t   isotp_pack_tx_result(gen, err));\n+}\n+\n+/* fetch the result recorded for 'gen', as a (negative) errno (0 for success) */\n+static int isotp_get_tx_result(struct isotp_sock *so, u32 gen)\n+{\n+\tu32 result = READ_ONCE(so-\u003etx_result[gen % ISOTP_TX_RESULT_SLOTS]);\n+\n+\tif (isotp_get_tx_gen(result) != gen) {\n+\t\tpr_notice_once(\"can-isotp: tx_result[] slot reused before read\\n\");\n+\n+\t\t/* report failure rather than risk a false success */\n+\t\treturn -ECOMM;\n+\t}\n+\n+\treturn -(isotp_get_tx_err(result));\n+}\n+\n+/* true if done, shut down or superseded ('gen' is no longer the active\n+ * transfer). Reads tx.state first (acquire) so tx_gen/tx_result reads\n+ * below see at least what that state write published (common sequence).\n+ */\n+static bool isotp_tx_gen_done(struct isotp_sock *so, u32 gen)\n+{\n+\t/* read tx.state first for the common sequence */\n+\tu32 state = smp_load_acquire(\u0026so-\u003etx.state);\n+\n+\treturn state == ISOTP_IDLE || state == ISOTP_SHUTDOWN ||\n+\t       READ_ONCE(so-\u003etx_gen) != gen;\n+}\n+\n static inline struct isotp_sock *isotp_sk(const struct sock *sk)\n {\n \treturn (struct isotp_sock *)sk;\n@@ -199,7 +268,7 @@ static enum hrtimer_restart isotp_rx_timer_handler(struct hrtimer *hrtimer)\n \t\t\t\t\t     rxtimer);\n \tstruct sock *sk = \u0026so-\u003esk;\n \n-\tif (so-\u003erx.state == ISOTP_WAIT_DATA) {\n+\tif (READ_ONCE(so-\u003erx.state) == ISOTP_WAIT_DATA) {\n \t\t/* we did not get new data frames in time */\n \n \t\t/* report 'connection timed out' */\n@@ -208,7 +277,7 @@ static enum hrtimer_restart isotp_rx_timer_handler(struct hrtimer *hrtimer)\n \t\t\tsk_error_report(sk);\n \n \t\t/* reset rx state */\n-\t\tso-\u003erx.state = ISOTP_IDLE;\n+\t\tWRITE_ONCE(so-\u003erx.state, ISOTP_IDLE);\n \t}\n \n \treturn HRTIMER_NORESTART;\n@@ -372,20 +441,19 @@ static void isotp_send_cframe(struct isotp_sock *so);\n static int isotp_rcv_fc(struct isotp_sock *so, struct canfd_frame *cf, int ae)\n {\n \tstruct sock *sk = \u0026so-\u003esk;\n+\tint tx_err = EBADMSG; /* default for unknown FC status */\n \n-\tif (so-\u003etx.state != ISOTP_WAIT_FC \u0026\u0026\n-\t    so-\u003etx.state != ISOTP_WAIT_FIRST_FC)\n+\tif (READ_ONCE(so-\u003etx.state) != ISOTP_WAIT_FC \u0026\u0026\n+\t    READ_ONCE(so-\u003etx.state) != ISOTP_WAIT_FIRST_FC)\n \t\treturn 0;\n \n \thrtimer_cancel(\u0026so-\u003etxtimer);\n \n \t/* isotp_tx_timeout() may have given up on this job while\n-\t * hrtimer_cancel() above waited for it to finish; so-\u003erx_lock\n-\t * (held by our caller isotp_rcv()) rules out a concurrent claim,\n-\t * so a plain recheck is enough here.\n+\t * hrtimer_cancel() above waited for it to finish =\u003e recheck\n \t */\n-\tif (so-\u003etx.state != ISOTP_WAIT_FC \u0026\u0026\n-\t    so-\u003etx.state != ISOTP_WAIT_FIRST_FC)\n+\tif (READ_ONCE(so-\u003etx.state) != ISOTP_WAIT_FC \u0026\u0026\n+\t    READ_ONCE(so-\u003etx.state) != ISOTP_WAIT_FIRST_FC)\n \t\treturn 1;\n \n \tif ((cf-\u003elen \u003c ae + FC_CONTENT_SZ) ||\n@@ -396,13 +464,15 @@ static int isotp_rcv_fc(struct isotp_sock *so, struct canfd_frame *cf, int ae)\n \t\tif (!sock_flag(sk, SOCK_DEAD))\n \t\t\tsk_error_report(sk);\n \n-\t\tso-\u003etx.state = ISOTP_IDLE;\n+\t\tisotp_set_tx_result(so, so-\u003etx_gen, EBADMSG);\n+\t\t/* set to IDLE after publishing tx_result */\n+\t\tsmp_store_release(\u0026so-\u003etx.state, ISOTP_IDLE);\n \t\twake_up_interruptible(\u0026so-\u003ewait);\n \t\treturn 1;\n \t}\n \n \t/* get static/dynamic communication params from first/every FC frame */\n-\tif (so-\u003etx.state == ISOTP_WAIT_FIRST_FC ||\n+\tif (READ_ONCE(so-\u003etx.state) == ISOTP_WAIT_FIRST_FC ||\n \t    so-\u003eopt.flags \u0026 CAN_ISOTP_DYN_FC_PARMS) {\n \t\tso-\u003etxfc.bs = cf-\u003edata[ae + 1];\n \t\tso-\u003etxfc.stmin = cf-\u003edata[ae + 2];\n@@ -426,13 +496,13 @@ static int isotp_rcv_fc(struct isotp_sock *so, struct canfd_frame *cf, int ae)\n \t\t\tso-\u003etx_gap = ktime_add_ns(so-\u003etx_gap,\n \t\t\t\t\t\t  (so-\u003etxfc.stmin - 0xF0)\n \t\t\t\t\t\t  * 100000);\n-\t\tso-\u003etx.state = ISOTP_WAIT_FC;\n+\t\tWRITE_ONCE(so-\u003etx.state, ISOTP_WAIT_FC);\n \t}\n \n \tswitch (cf-\u003edata[ae] \u0026 0x0F) {\n \tcase ISOTP_FC_CTS:\n \t\tso-\u003etx.bs = 0;\n-\t\tso-\u003etx.state = ISOTP_SENDING;\n+\t\tWRITE_ONCE(so-\u003etx.state, ISOTP_SENDING);\n \t\t/* send CF frame and enable echo timeout handling */\n \t\thrtimer_start(\u0026so-\u003eechotimer, ktime_set(ISOTP_ECHO_TIMEOUT, 0),\n \t\t\t      HRTIMER_MODE_REL_SOFT);\n@@ -447,14 +517,19 @@ static int isotp_rcv_fc(struct isotp_sock *so, struct canfd_frame *cf, int ae)\n \n \tcase ISOTP_FC_OVFLW:\n \t\t/* overflow on receiver side - report 'message too long' */\n-\t\tsk-\u003esk_err = EMSGSIZE;\n-\t\tif (!sock_flag(sk, SOCK_DEAD))\n-\t\t\tsk_error_report(sk);\n+\t\ttx_err = EMSGSIZE;\n \t\tfallthrough;\n \n \tdefault:\n-\t\t/* stop this tx job */\n-\t\tso-\u003etx.state = ISOTP_IDLE;\n+\t\t/* reserved/unknown flow status (tx_err defaults to EBADMSG) */\n+\n+\t\tsk-\u003esk_err = tx_err;\n+\t\tif (!sock_flag(sk, SOCK_DEAD))\n+\t\t\tsk_error_report(sk);\n+\n+\t\tisotp_set_tx_result(so, so-\u003etx_gen, tx_err);\n+\t\t/* set to IDLE after publishing tx_result */\n+\t\tsmp_store_release(\u0026so-\u003etx.state, ISOTP_IDLE);\n \t\twake_up_interruptible(\u0026so-\u003ewait);\n \t}\n \treturn 0;\n@@ -467,7 +542,7 @@ static int isotp_rcv_sf(struct sock *sk, struct canfd_frame *cf, int pcilen,\n \tstruct sk_buff *nskb;\n \n \thrtimer_cancel(\u0026so-\u003erxtimer);\n-\tso-\u003erx.state = ISOTP_IDLE;\n+\tWRITE_ONCE(so-\u003erx.state, ISOTP_IDLE);\n \n \tif (!len || len \u003e cf-\u003elen - pcilen)\n \t\treturn 1;\n@@ -501,7 +576,7 @@ static int isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae)\n \tint ff_pci_sz;\n \n \thrtimer_cancel(\u0026so-\u003erxtimer);\n-\tso-\u003erx.state = ISOTP_IDLE;\n+\tWRITE_ONCE(so-\u003erx.state, ISOTP_IDLE);\n \n \t/* get the used sender LL_DL from the (first) CAN frame data length */\n \tso-\u003erx.ll_dl = padlen(cf-\u003elen);\n@@ -555,7 +630,7 @@ static int isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae)\n \n \t/* initial setup for this pdu reception */\n \tso-\u003erx.sn = 1;\n-\tso-\u003erx.state = ISOTP_WAIT_DATA;\n+\tWRITE_ONCE(so-\u003erx.state, ISOTP_WAIT_DATA);\n \n \t/* no creation of flow control frames */\n \tif (so-\u003eopt.flags \u0026 CAN_ISOTP_LISTEN_MODE)\n@@ -573,7 +648,7 @@ static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,\n \tstruct sk_buff *nskb;\n \tint i;\n \n-\tif (so-\u003erx.state != ISOTP_WAIT_DATA)\n+\tif (READ_ONCE(so-\u003erx.state) != ISOTP_WAIT_DATA)\n \t\treturn 0;\n \n \t/* drop if timestamp gap is less than force_rx_stmin nano secs */\n@@ -588,11 +663,9 @@ static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,\n \thrtimer_cancel(\u0026so-\u003erxtimer);\n \n \t/* isotp_rx_timer_handler() may have raced us for so-\u003erx.state\n-\t * while hrtimer_cancel() above waited for it to finish, already\n-\t * reporting ETIMEDOUT and resetting the reception; don't process\n-\t * this CF into a reassembly that has already been given up on.\n+\t * while hrtimer_cancel() above waited for it to finish =\u003e recheck\n \t */\n-\tif (so-\u003erx.state != ISOTP_WAIT_DATA)\n+\tif (READ_ONCE(so-\u003erx.state) != ISOTP_WAIT_DATA)\n \t\treturn 1;\n \n \t/* CFs are never longer than the FF */\n@@ -613,7 +686,7 @@ static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,\n \t\t\tsk_error_report(sk);\n \n \t\t/* reset rx state */\n-\t\tso-\u003erx.state = ISOTP_IDLE;\n+\t\tWRITE_ONCE(so-\u003erx.state, ISOTP_IDLE);\n \t\treturn 1;\n \t}\n \tso-\u003erx.sn++;\n@@ -627,7 +700,7 @@ static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,\n \n \tif (so-\u003erx.idx \u003e= so-\u003erx.len) {\n \t\t/* we are done */\n-\t\tso-\u003erx.state = ISOTP_IDLE;\n+\t\tWRITE_ONCE(so-\u003erx.state, ISOTP_IDLE);\n \n \t\tif ((so-\u003eopt.flags \u0026 ISOTP_CHECK_PADDING) \u0026\u0026\n \t\t    check_pad(so, cf, i + 1, so-\u003eopt.rxpad_content)) {\n@@ -698,8 +771,10 @@ static void isotp_rcv(struct sk_buff *skb, void *data)\n \n \tif (so-\u003eopt.flags \u0026 CAN_ISOTP_HALF_DUPLEX) {\n \t\t/* check rx/tx path half duplex expectations */\n-\t\tif ((so-\u003etx.state != ISOTP_IDLE \u0026\u0026 n_pci_type != N_PCI_FC) ||\n-\t\t    (so-\u003erx.state != ISOTP_IDLE \u0026\u0026 n_pci_type == N_PCI_FC))\n+\t\tif ((READ_ONCE(so-\u003etx.state) != ISOTP_IDLE \u0026\u0026\n+\t\t     n_pci_type != N_PCI_FC) ||\n+\t\t    (READ_ONCE(so-\u003erx.state) != ISOTP_IDLE \u0026\u0026\n+\t\t     n_pci_type == N_PCI_FC))\n \t\t\tgoto out_unlock;\n \t}\n \n@@ -794,6 +869,7 @@ static void isotp_send_cframe(struct isotp_sock *so)\n \tstruct canfd_frame *cf;\n \tint can_send_ret;\n \tint ae = (so-\u003eopt.flags \u0026 CAN_ISOTP_EXTEND_ADDR) ? 1 : 0;\n+\tu32 old_cfecho;\n \n \tdev = dev_get_by_index(sock_net(sk), so-\u003eifindex);\n \tif (!dev)\n@@ -814,6 +890,9 @@ static void isotp_send_cframe(struct isotp_sock *so)\n \n \tcsx-\u003ecan_iif = dev-\u003eifindex;\n \n+\t/* set uid in tx skb to identify CF echo frames */\n+\tcan_set_skb_uid(skb);\n+\n \tcf = (struct canfd_frame *)skb-\u003edata;\n \tskb_put_zero(skb, so-\u003ell.mtu);\n \n@@ -830,12 +909,15 @@ static void isotp_send_cframe(struct isotp_sock *so)\n \tskb-\u003edev = dev;\n \tcan_skb_set_owner(skb, sk);\n \n-\t/* cfecho should have been zero'ed by init/isotp_rcv_echo() */\n-\tif (so-\u003ecfecho)\n-\t\tpr_notice_once(\"can-isotp: cfecho is %08X != 0\\n\", so-\u003ecfecho);\n+\t/* zero'ed by init/isotp_rcv_echo(); reached lock-free via\n+\t * isotp_txfr_timer_handler() too, so use READ_ONCE()/WRITE_ONCE()\n+\t */\n+\told_cfecho = READ_ONCE(so-\u003ecfecho);\n+\tif (old_cfecho)\n+\t\tpr_notice_once(\"can-isotp: cfecho is %08X != 0\\n\", old_cfecho);\n \n \t/* set consecutive frame echo tag */\n-\tso-\u003ecfecho = *(u32 *)cf-\u003edata;\n+\tWRITE_ONCE(so-\u003ecfecho, skb-\u003ehash);\n \n \t/* send frame with local echo enabled */\n \tcan_send_ret = can_send(skb, 1);\n@@ -887,7 +969,6 @@ static void isotp_rcv_echo(struct sk_buff *skb, void *data)\n {\n \tstruct sock *sk = (struct sock *)data;\n \tstruct isotp_sock *so = isotp_sk(sk);\n-\tstruct canfd_frame *cf = (struct canfd_frame *)skb-\u003edata;\n \n \t/* only handle my own local echo CF/SF skb's (no FF!) */\n \tif (skb-\u003esk != sk)\n@@ -899,32 +980,35 @@ static void isotp_rcv_echo(struct sk_buff *skb, void *data)\n \tspin_lock(\u0026so-\u003erx_lock);\n \n \t/* so-\u003ecfecho may since belong to a new transfer; recheck under lock */\n-\tif (so-\u003ecfecho != *(u32 *)cf-\u003edata)\n+\tif (READ_ONCE(so-\u003ecfecho) != skb-\u003ehash)\n \t\tgoto out_unlock;\n \n \t/* cancel local echo timeout */\n \thrtimer_cancel(\u0026so-\u003eechotimer);\n \n \t/* local echo skb with consecutive frame has been consumed */\n-\tso-\u003ecfecho = 0;\n+\tWRITE_ONCE(so-\u003ecfecho, 0);\n \n \t/* claiming a transfer also takes so-\u003erx_lock, so a plain recheck\n \t * is enough: so-\u003etx.state can't have flipped to ISOTP_SENDING for\n \t * a new claim while we're still in here\n \t */\n-\tif (so-\u003etx.state != ISOTP_SENDING)\n+\tif (READ_ONCE(so-\u003etx.state) != ISOTP_SENDING)\n \t\tgoto out_unlock;\n \n \tif (so-\u003etx.idx \u003e= so-\u003etx.len) {\n \t\t/* we are done */\n-\t\tso-\u003etx.state = ISOTP_IDLE;\n+\n+\t\tisotp_set_tx_result(so, so-\u003etx_gen, 0);\n+\t\t/* set to IDLE after publishing tx_result */\n+\t\tsmp_store_release(\u0026so-\u003etx.state, ISOTP_IDLE);\n \t\twake_up_interruptible(\u0026so-\u003ewait);\n \t\tgoto out_unlock;\n \t}\n \n \tif (so-\u003etxfc.bs \u0026\u0026 so-\u003etx.bs \u003e= so-\u003etxfc.bs) {\n \t\t/* stop and wait for FC with timeout */\n-\t\tso-\u003etx.state = ISOTP_WAIT_FC;\n+\t\tWRITE_ONCE(so-\u003etx.state, ISOTP_WAIT_FC);\n \t\thrtimer_start(\u0026so-\u003etxtimer, ktime_set(ISOTP_FC_TIMEOUT, 0),\n \t\t\t      HRTIMER_MODE_REL_SOFT);\n \t\tgoto out_unlock;\n@@ -946,16 +1030,20 @@ static void isotp_rcv_echo(struct sk_buff *skb, void *data)\n \tspin_unlock(\u0026so-\u003erx_lock);\n }\n \n-/* shared by so-\u003etxtimer's and so-\u003eechotimer's callbacks. Both timers get\n- * cancelled under so-\u003erx_lock elsewhere, so this must stay lock-free to\n- * avoid deadlocking with that; uses so-\u003etx_gen instead to avoid tainting\n- * a new transfer with an error from the one that just timed out.\n+/* isotp_tx_timeout: we did not get any flow control or echo frame in time\n+ *\n+ * Shared by so-\u003etxtimer's and so-\u003eechotimer's callbacks. Both timers get\n+ * cancelled under so-\u003erx_lock elsewhere, so this must stay lock-free.\n+ *\n+ * tx.state is acquired before tx_gen. Common sequence in isotp_tx_gen_done().\n+ * cmpxchg() only orders itself, not the two preceding loads.\n  */\n static enum hrtimer_restart isotp_tx_timeout(struct isotp_sock *so)\n {\n \tstruct sock *sk = \u0026so-\u003esk;\n+\t/* read tx.state first for the common sequence */\n+\tu32 old_state = smp_load_acquire(\u0026so-\u003etx.state);\n \tu32 gen = READ_ONCE(so-\u003etx_gen);\n-\tu32 old_state = READ_ONCE(so-\u003etx.state);\n \n \t/* don't handle timeouts in IDLE or SHUTDOWN state */\n \tif (old_state == ISOTP_IDLE || old_state == ISOTP_SHUTDOWN)\n@@ -965,14 +1053,14 @@ static enum hrtimer_restart isotp_tx_timeout(struct isotp_sock *so)\n \tif (cmpxchg(\u0026so-\u003etx.state, old_state, ISOTP_IDLE) != old_state)\n \t\treturn HRTIMER_NORESTART;\n \n-\t/* we did not get any flow control or echo frame in time */\n+\t/* detected timeout: report 'communication error on send' */\n \n-\tif (READ_ONCE(so-\u003etx_gen) == gen) {\n-\t\t/* report 'communication error on send' */\n-\t\tsk-\u003esk_err = ECOMM;\n-\t\tif (!sock_flag(sk, SOCK_DEAD))\n-\t\t\tsk_error_report(sk);\n-\t}\n+\t/* a stale read of this slot by a waiter still falls back to ECOMM */\n+\tisotp_set_tx_result(so, gen, ECOMM);\n+\n+\tsk-\u003esk_err = ECOMM;\n+\tif (!sock_flag(sk, SOCK_DEAD))\n+\t\tsk_error_report(sk);\n \n \twake_up_interruptible(\u0026so-\u003ewait);\n \n@@ -1007,7 +1095,7 @@ static enum hrtimer_restart isotp_txfr_timer_handler(struct hrtimer *hrtimer)\n \t\t      HRTIMER_MODE_REL_SOFT);\n \n \t/* cfecho should be consumed by isotp_rcv_echo() here */\n-\tif (so-\u003etx.state == ISOTP_SENDING \u0026\u0026 !so-\u003ecfecho)\n+\tif (READ_ONCE(so-\u003etx.state) == ISOTP_SENDING \u0026\u0026 !READ_ONCE(so-\u003ecfecho))\n \t\tisotp_send_cframe(so);\n \n \treturn HRTIMER_NORESTART;\n@@ -1026,10 +1114,12 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)\n \ts64 hrtimer_sec = ISOTP_ECHO_TIMEOUT;\n \tstruct hrtimer *tx_hrt = \u0026so-\u003eechotimer;\n \tu32 new_state = ISOTP_SENDING;\n+\tu32 my_gen;\n+\tu32 old_cfecho;\n \tint off;\n \tint err;\n \n-\tif (!so-\u003ebound || so-\u003etx.state == ISOTP_SHUTDOWN)\n+\tif (!so-\u003ebound || READ_ONCE(so-\u003etx.state) == ISOTP_SHUTDOWN)\n \t\treturn -EADDRNOTAVAIL;\n \n \t/* claim the socket under so-\u003erx_lock: this serializes the claim\n@@ -1046,29 +1136,33 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)\n \t\tif (msg-\u003emsg_flags \u0026 MSG_DONTWAIT)\n \t\t\treturn -EAGAIN;\n \n-\t\tif (so-\u003etx.state == ISOTP_SHUTDOWN)\n+\t\tif (READ_ONCE(so-\u003etx.state) == ISOTP_SHUTDOWN)\n \t\t\treturn -EADDRNOTAVAIL;\n \n \t\t/* wait for complete transmission of current pdu */\n \t\terr = wait_event_interruptible(so-\u003ewait,\n-\t\t\t\t\t       so-\u003etx.state == ISOTP_IDLE);\n+\t\t\t\t\t       READ_ONCE(so-\u003etx.state) == ISOTP_IDLE ||\n+\t\t\t\t\t       READ_ONCE(so-\u003etx.state) == ISOTP_SHUTDOWN);\n \t\tif (err)\n \t\t\treturn err;\n \t}\n \n-\t/* new transfer: bump so-\u003etx_gen and drain the old one's timers,\n-\t * still under the so-\u003erx_lock we just claimed the socket with\n-\t */\n-\tWRITE_ONCE(so-\u003etx.state, ISOTP_SENDING);\n-\tWRITE_ONCE(so-\u003etx_gen, READ_ONCE(so-\u003etx_gen) + 1);\n+\t/* txfrtimer's callback re-arms echotimer lock-free: drain it first */\n+\thrtimer_cancel(\u0026so-\u003etxfrtimer);\n \thrtimer_cancel(\u0026so-\u003etxtimer);\n \thrtimer_cancel(\u0026so-\u003eechotimer);\n-\thrtimer_cancel(\u0026so-\u003etxfrtimer);\n-\tso-\u003ecfecho = 0;\n+\n+\t/* new transfer: increment so-\u003etx_gen and set tx.state after barrier */\n+\tmy_gen = isotp_inc_tx_gen(READ_ONCE(so-\u003etx_gen));\n+\tisotp_set_tx_result(so, my_gen, ECOMM); /* prevent stale slot matching */\n+\tWRITE_ONCE(so-\u003etx_gen, my_gen);\n+\tsmp_wmb(); /* see smp_load_acquire() in isotp_tx_[timeout|gen_done] */\n+\tWRITE_ONCE(so-\u003etx.state, ISOTP_SENDING);\n+\tWRITE_ONCE(so-\u003ecfecho, 0);\n \tspin_unlock_bh(\u0026so-\u003erx_lock);\n \n \t/* so-\u003ebound is only checked once above - a wakeup may have\n-\t * unbound/rebound the socket meanwhile, so re-validate it\n+\t * unbound/rebound the socket meanwhile =\u003e recheck\n \t */\n \tif (!so-\u003ebound) {\n \t\terr = -EADDRNOTAVAIL;\n@@ -1127,6 +1221,9 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)\n \n \tcsx-\u003ecan_iif = dev-\u003eifindex;\n \n+\t/* set uid in tx skb to identify CF echo frames */\n+\tcan_set_skb_uid(skb);\n+\n \tso-\u003etx.len = size;\n \tso-\u003etx.idx = 0;\n \n@@ -1134,8 +1231,9 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)\n \tskb_put_zero(skb, so-\u003ell.mtu);\n \n \t/* cfecho should have been zero'ed by init / former isotp_rcv_echo() */\n-\tif (so-\u003ecfecho)\n-\t\tpr_notice_once(\"can-isotp: uninit cfecho %08X\\n\", so-\u003ecfecho);\n+\told_cfecho = READ_ONCE(so-\u003ecfecho);\n+\tif (old_cfecho)\n+\t\tpr_notice_once(\"can-isotp: uninit cfecho %08X\\n\", old_cfecho);\n \n \t/* check for single frame transmission depending on TX_DL */\n \tif (size \u003c= so-\u003etx.ll_dl - SF_PCI_SZ4 - ae - off) {\n@@ -1163,7 +1261,7 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)\n \t\t\tcf-\u003edata[ae] |= size;\n \n \t\t/* set CF echo tag for isotp_rcv_echo() (SF-mode) */\n-\t\tso-\u003ecfecho = *(u32 *)cf-\u003edata;\n+\t\tWRITE_ONCE(so-\u003ecfecho, skb-\u003ehash);\n \t} else {\n \t\t/* send first frame */\n \n@@ -1180,7 +1278,7 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)\n \t\t\tso-\u003etxfc.bs = 0;\n \n \t\t\t/* set CF echo tag for isotp_rcv_echo() (CF-mode) */\n-\t\t\tso-\u003ecfecho = *(u32 *)cf-\u003edata;\n+\t\t\tWRITE_ONCE(so-\u003ecfecho, skb-\u003ehash);\n \t\t} else {\n \t\t\t/* standard flow control check */\n \t\t\tnew_state = ISOTP_WAIT_FIRST_FC;\n@@ -1190,12 +1288,12 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)\n \t\t\ttx_hrt = \u0026so-\u003etxtimer;\n \n \t\t\t/* no CF echo tag for isotp_rcv_echo() (FF-mode) */\n-\t\t\tso-\u003ecfecho = 0;\n+\t\t\tWRITE_ONCE(so-\u003ecfecho, 0);\n \t\t}\n \t}\n \n \tspin_lock_bh(\u0026so-\u003erx_lock);\n-\tif (so-\u003etx.state == ISOTP_SHUTDOWN) {\n+\tif (READ_ONCE(so-\u003etx.state) == ISOTP_SHUTDOWN) {\n \t\t/* isotp_release() has since taken over and already drained\n \t\t * our timers - don't send into a socket that's going away\n \t\t */\n@@ -1206,7 +1304,7 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)\n \t\treturn -EADDRNOTAVAIL;\n \t}\n \t/* WAIT_FIRST_FC for standard FF, else stays ISOTP_SENDING */\n-\tso-\u003etx.state = new_state;\n+\tWRITE_ONCE(so-\u003etx.state, new_state);\n \thrtimer_start(tx_hrt, ktime_set(hrtimer_sec, 0),\n \t\t      HRTIMER_MODE_REL_SOFT);\n \tspin_unlock_bh(\u0026so-\u003erx_lock);\n@@ -1223,20 +1321,49 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)\n \t\t\t       __func__, ERR_PTR(err));\n \n \t\tspin_lock_bh(\u0026so-\u003erx_lock);\n+\n+\t\t/* new transfer already claimed by a concurrent completion,\n+\t\t * timeout or sendmsg() while we were stuck in can_send()?\n+\t\t */\n+\t\tif (READ_ONCE(so-\u003etx_gen) != my_gen) {\n+\t\t\t/* don't touch timers and state of the new transfer */\n+\t\t\tspin_unlock_bh(\u0026so-\u003erx_lock);\n+\t\t\treturn err;\n+\t\t}\n+\n \t\t/* no transmission -\u003e no timeout monitoring */\n \t\thrtimer_cancel(tx_hrt);\n \t\tgoto err_out_drop_locked;\n \t}\n \n \tif (wait_tx_done) {\n-\t\t/* wait for complete transmission of current pdu */\n-\t\terr = wait_event_interruptible(so-\u003ewait, so-\u003etx.state == ISOTP_IDLE);\n+\t\t/* wake up for:\n+\t\t * - concurrent sendmsg() claiming a new transfer\n+\t\t * - complete transmission of current PDU\n+\t\t * - shutdown state change in isotp_release()\n+\t\t * isotp_tx_gen_done() uses common tx.state/tx_gen read sequence\n+\t\t */\n+\t\terr = wait_event_interruptible(so-\u003ewait,\n+\t\t\t\t\t       isotp_tx_gen_done(so, my_gen));\n \t\tif (err)\n \t\t\tgoto err_event_drop;\n \n-\t\terr = sock_error(sk);\n-\t\tif (err)\n-\t\t\treturn err;\n+\t\t/* still our claim, but isotp_release() force-shut it down */\n+\t\tif (smp_load_acquire(\u0026so-\u003etx.state) == ISOTP_SHUTDOWN \u0026\u0026\n+\t\t    READ_ONCE(so-\u003etx_gen) == my_gen) {\n+\t\t\terr = -EADDRNOTAVAIL;\n+\t\t\tgoto err_event_drop;\n+\t\t}\n+\n+\t\t/* own completion, or tx_gen moved on - either way this is\n+\t\t * what isotp_get_tx_result() recorded for my_gen\n+\t\t */\n+\t\terr = isotp_get_tx_result(so, my_gen);\n+\n+\t\t/* drain to avoid stale error for a later poll()/SO_ERROR */\n+\t\tsock_error(sk);\n+\n+\t\treturn err ? err : size;\n \t}\n \n \treturn size;\n@@ -1246,15 +1373,26 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)\n \tspin_lock_bh(\u0026so-\u003erx_lock);\n \tgoto err_out_drop_locked;\n err_event_drop:\n-\t/* interrupted waiting on our own transfer - drain its timers */\n+\t/* interrupted or shut down while waiting on our own transfer */\n \tspin_lock_bh(\u0026so-\u003erx_lock);\n+\n+\t/* new transfer already started by concurrent sendmsg()? */\n+\tif (READ_ONCE(so-\u003etx_gen) != my_gen) {\n+\t\t/* don't touch timers and states of the new transfer */\n+\t\tspin_unlock_bh(\u0026so-\u003erx_lock);\n+\t\treturn err;\n+\t}\n+\n \thrtimer_cancel(\u0026so-\u003etxfrtimer);\n \thrtimer_cancel(\u0026so-\u003etxtimer);\n \thrtimer_cancel(\u0026so-\u003eechotimer);\n err_out_drop_locked:\n \t/* release the claim; so-\u003erx_lock still held from above */\n-\tso-\u003ecfecho = 0;\n-\tso-\u003etx.state = ISOTP_IDLE;\n+\tWRITE_ONCE(so-\u003ecfecho, 0);\n+\n+\t/* only claim to IDLE if isotp_release() has not taken over */\n+\tif (READ_ONCE(so-\u003etx.state) != ISOTP_SHUTDOWN)\n+\t\tWRITE_ONCE(so-\u003etx.state, ISOTP_IDLE);\n \tspin_unlock_bh(\u0026so-\u003erx_lock);\n \twake_up_interruptible(\u0026so-\u003ewait);\n \n@@ -1320,8 +1458,9 @@ static int isotp_release(struct socket *sock)\n \t/* best-effort: wait for a running pdu to finish, but don't block on\n \t * it forever - give up after the first signal\n \t */\n-\twhile (so-\u003etx.state != ISOTP_IDLE \u0026\u0026\n-\t       wait_event_interruptible(so-\u003ewait, so-\u003etx.state == ISOTP_IDLE) == 0)\n+\twhile (READ_ONCE(so-\u003etx.state) != ISOTP_IDLE \u0026\u0026\n+\t       wait_event_interruptible(so-\u003ewait,\n+\t\t\t\t\tREAD_ONCE(so-\u003etx.state) == ISOTP_IDLE) == 0)\n \t\t;\n \n \t/* claim the socket under so-\u003erx_lock like sendmsg() does, so its\n@@ -1329,9 +1468,12 @@ static int isotp_release(struct socket *sock)\n \t * unconditionally, even when a signal cut the wait above short\n \t */\n \tspin_lock_bh(\u0026so-\u003erx_lock);\n-\tso-\u003etx.state = ISOTP_SHUTDOWN;\n+\tWRITE_ONCE(so-\u003etx.state, ISOTP_SHUTDOWN);\n \tspin_unlock_bh(\u0026so-\u003erx_lock);\n-\tso-\u003erx.state = ISOTP_IDLE;\n+\tWRITE_ONCE(so-\u003erx.state, ISOTP_IDLE);\n+\n+\t/* forced SHUTDOWN may have skipped IDLE (gave up on a signal) */\n+\twake_up_interruptible(\u0026so-\u003ewait);\n \n \tspin_lock(\u0026isotp_notifier_lock);\n \twhile (isotp_busy_notifier == so) {\n@@ -1447,7 +1589,8 @@ static int isotp_bind(struct socket *sock, struct sockaddr_unsized *uaddr, int l\n \t * with so-\u003ebound in the same lock_sock() section above, so there is\n \t * no window in which a concurrent isotp_notify() could be missed.\n \t */\n-\tif (so-\u003etx.state != ISOTP_IDLE || so-\u003erx.state != ISOTP_IDLE) {\n+\tif (READ_ONCE(so-\u003etx.state) != ISOTP_IDLE ||\n+\t    READ_ONCE(so-\u003erx.state) != ISOTP_IDLE) {\n \t\terr = -EAGAIN;\n \t\tgoto out;\n \t}\n@@ -1481,7 +1624,7 @@ static int isotp_bind(struct socket *sock, struct sockaddr_unsized *uaddr, int l\n \t\t\t\tisotp_rcv, sk, \"isotp\", sk);\n \n \t/* no consecutive frame echo skb in flight */\n-\tso-\u003ecfecho = 0;\n+\tWRITE_ONCE(so-\u003ecfecho, 0);\n \n \t/* register for echo skb's */\n \tcan_rx_register(net, dev, tx_id, SINGLE_MASK(tx_id),\n@@ -1847,7 +1990,7 @@ static __poll_t isotp_poll(struct file *file, struct socket *sock, poll_table *w\n \tpoll_wait(file, \u0026so-\u003ewait, wait);\n \n \t/* Check for false positives due to TX state */\n-\tif ((mask \u0026 EPOLLWRNORM) \u0026\u0026 (so-\u003etx.state != ISOTP_IDLE))\n+\tif ((mask \u0026 EPOLLWRNORM) \u0026\u0026 (READ_ONCE(so-\u003etx.state) != ISOTP_IDLE))\n \t\tmask \u0026= ~(EPOLLOUT | EPOLLWRNORM);\n \n \treturn mask;\n@@ -1907,13 +2050,18 @@ static __init int isotp_module_init(void)\n \n \tpr_info(\"can: isotp protocol (max_pdu_size %d)\\n\", max_pdu_size);\n \n+\terr = register_netdevice_notifier(\u0026canisotp_notifier);\n+\tif (err)\n+\t\treturn err;\n+\n \terr = can_proto_register(\u0026isotp_can_proto);\n-\tif (err \u003c 0)\n+\tif (err \u003c 0) {\n \t\tpr_err(\"can: registration of isotp protocol failed %pe\\n\", ERR_PTR(err));\n-\telse\n-\t\tregister_netdevice_notifier(\u0026canisotp_notifier);\n+\t\tunregister_netdevice_notifier(\u0026canisotp_notifier);\n+\t\treturn err;\n+\t}\n \n-\treturn err;\n+\treturn 0;\n }\n \n static __exit void isotp_module_exit(void)\ndiff --git a/net/can/j1939/bus.c b/net/can/j1939/bus.c\nindex dc374286eeb6e..cdc3c0a719379 100644\n--- a/net/can/j1939/bus.c\n+++ b/net/can/j1939/bus.c\n@@ -20,6 +20,7 @@ static void __j1939_ecu_release(struct kref *kref)\n \tstruct j1939_priv *priv = ecu-\u003epriv;\n \n \tlist_del(\u0026ecu-\u003elist);\n+\tnetdev_put(priv-\u003endev, \u0026ecu-\u003epriv_dev_tracker);\n \tkfree(ecu);\n \tj1939_priv_put(priv);\n }\n@@ -155,6 +156,7 @@ struct j1939_ecu *j1939_ecu_create_locked(struct j1939_priv *priv, name_t name)\n \tif (!ecu)\n \t\treturn ERR_PTR(-ENOMEM);\n \tkref_init(\u0026ecu-\u003ekref);\n+\tnetdev_hold(priv-\u003endev, \u0026ecu-\u003epriv_dev_tracker, gfp_any());\n \tecu-\u003eaddr = J1939_IDLE_ADDR;\n \tecu-\u003ename = name;\n \ndiff --git a/net/can/j1939/j1939-priv.h b/net/can/j1939/j1939-priv.h\nindex 81f58924b4acd..cf26352d1d8ce 100644\n--- a/net/can/j1939/j1939-priv.h\n+++ b/net/can/j1939/j1939-priv.h\n@@ -38,6 +38,7 @@ struct j1939_ecu {\n \tstruct hrtimer ac_timer;\n \tstruct kref kref;\n \tstruct j1939_priv *priv;\n+\tnetdevice_tracker priv_dev_tracker;\n \n \t/* count users, to help transport protocol decide for interaction */\n \tint nusers;\n@@ -60,6 +61,7 @@ struct j1939_priv {\n \trwlock_t lock;\n \n \tstruct net_device *ndev;\n+\tnetdevice_tracker dev_tracker;\n \n \t/* list of 256 ecu ptrs, that cache the claimed addresses.\n \t * also protected by the above lock\n@@ -230,6 +232,7 @@ enum j1939_session_state {\n \n struct j1939_session {\n \tstruct j1939_priv *priv;\n+\tnetdevice_tracker priv_dev_tracker;\n \tstruct list_head active_session_list_entry;\n \tstruct list_head sk_session_queue_entry;\n \tstruct kref kref;\ndiff --git a/net/can/j1939/main.c b/net/can/j1939/main.c\nindex 9937c04241bc3..5e5e6c228f225 100644\n--- a/net/can/j1939/main.c\n+++ b/net/can/j1939/main.c\n@@ -137,7 +137,7 @@ static struct j1939_priv *j1939_priv_create(struct net_device *ndev)\n \tpriv-\u003endev = ndev;\n \tkref_init(\u0026priv-\u003ekref);\n \tkref_init(\u0026priv-\u003erx_kref);\n-\tdev_hold(ndev);\n+\tnetdev_hold(ndev, \u0026priv-\u003edev_tracker, GFP_KERNEL);\n \n \tnetdev_dbg(priv-\u003endev, \"%s : 0x%p\\n\", __func__, priv);\n \n@@ -163,7 +163,7 @@ static void __j1939_priv_release(struct kref *kref)\n \tWARN_ON_ONCE(!list_empty(\u0026priv-\u003eecus));\n \tWARN_ON_ONCE(!list_empty(\u0026priv-\u003ej1939_socks));\n \n-\tdev_put(ndev);\n+\tnetdev_put(ndev, \u0026priv-\u003edev_tracker);\n \tkfree(priv);\n }\n \n@@ -281,7 +281,7 @@ struct j1939_priv *j1939_netdev_start(struct net_device *ndev)\n \t\t */\n \t\tkref_get(\u0026priv_new-\u003erx_kref);\n \t\tmutex_unlock(\u0026j1939_netdev_lock);\n-\t\tdev_put(ndev);\n+\t\tnetdev_put(ndev, \u0026priv-\u003edev_tracker);\n \t\tkfree(priv);\n \t\treturn priv_new;\n \t}\n@@ -298,7 +298,7 @@ struct j1939_priv *j1939_netdev_start(struct net_device *ndev)\n \tj1939_priv_set(ndev, NULL);\n \tmutex_unlock(\u0026j1939_netdev_lock);\n \n-\tdev_put(ndev);\n+\tnetdev_put(ndev, \u0026priv-\u003edev_tracker);\n \tkfree(priv);\n \n \treturn ERR_PTR(ret);\ndiff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c\nindex 8a31cb23bc76d..8fcfd13e5e6f8 100644\n--- a/net/can/j1939/transport.c\n+++ b/net/can/j1939/transport.c\n@@ -283,6 +283,7 @@ static void j1939_session_destroy(struct j1939_session *session)\n \t\tkfree_skb(skb);\n \t}\n \t__j1939_session_drop(session);\n+\tnetdev_put(session-\u003epriv-\u003endev, \u0026session-\u003epriv_dev_tracker);\n \tj1939_priv_put(session-\u003epriv);\n \tkfree(session);\n }\n@@ -1526,6 +1527,7 @@ static struct j1939_session *j1939_session_new(struct j1939_priv *priv,\n \tINIT_LIST_HEAD(\u0026session-\u003eactive_session_list_entry);\n \tINIT_LIST_HEAD(\u0026session-\u003esk_session_queue_entry);\n \tkref_init(\u0026session-\u003ekref);\n+\tnetdev_hold(priv-\u003endev, \u0026session-\u003epriv_dev_tracker, gfp_any());\n \n \tj1939_priv_get(priv);\n \tsession-\u003epriv = priv;\n@@ -1579,7 +1581,7 @@ j1939_session *j1939_session_fresh_new(struct j1939_priv *priv,\n \t}\n \n \t/* alloc data area */\n-\tskb_put(skb, size);\n+\tskb_put_zero(skb, size);\n \t/* skb is recounted in j1939_session_new() */\n \treturn session;\n }\n"
}

2/1 2026/07/30 16:20 agent patch-evaluator
5m Model:
best-expensive

Args:
null

Results:
{
  "EnableConfigs": [
    "CAN_ISOTP",
    "CAN_J1939",
    "CAN_EMS_USB",
    "CAN_GS_USB",
    "CAN_KVASER_USB",
    "CAN_PEAK_USB",
    "CAN_ETAS_ES58X",
    "CAN_SOFTING",
    "CAN_CTUCANFD_PCI",
    "CAN_C_CAN_PCI"
  ],
  "FocusSymbols": [
    "isotp_sendmsg",
    "isotp_rcv",
    "isotp_rcv_echo",
    "isotp_release",
    "isotp_bind",
    "isotp_poll",
    "j1939_sk_sendmsg",
    "j1939_sk_recvmsg",
    "j1939_sk_bind",
    "j1939_sk_release",
    "j1939_tp_send",
    "j1939_tp_recv",
    "j1939_netdev_start",
    "pcan_usb_fd_decode_buf",
    "kvaser_usb_leaf_read_bulk_callback",
    "ems_usb_read_bulk_callback",
    "gs_usb_receive_bulk_callback",
    "es58x_read_bulk_callback"
  ],
  "Reasoning": "The patch series introduces functional changes to the CAN ISOTP and J1939 protocols, including a major rewrite of the ISOTP tx state machine and error handling to fix race conditions, and reference tracking for J1939 netdevs. It also adds length validation and bounds checking to several USB CAN drivers (ems_usb, gs_usb, kvaser_usb, peak_usb, etas_es58x) and fixes minor issues in other CAN drivers (c_can, ctucanfd, rcar_canfd, softing). These changes are reachable via sockets and USB fuzzing, and should be heavily fuzzed to ensure the new state machine and validation logic are correct.",
  "WorthFuzzing": true
}

Instruction:
You are an expert Linux kernel maintainer.
Your job is to review a provided patch series and determine
if it makes functional changes to the kernel that should be fuzzed.

IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on your internal knowledge of the kernel. You must actively
use your code access tools to examine the actual source code and confirm any assumptions.

Return WorthFuzzing=false if the patch only contains:
- Modifications to Documentation/, Kconfig files, or code comments.
- Purely decorative changes, such as logging (e.g., pr_err, printk) or tracepoints.
- Changes to numeric constants or macros that do not functionally alter execution flow.
- Code paths that are impossible to reach in virtualized environments like GCE or QEMU,
  even when utilizing software-emulated hardware (e.g., usb gadget, mac80211_hwsim).
- Code in vendor-specific PCIe switch, SmartNIC, or GPU drivers (e.g., mlxsw, pds_core, qed,
  ionic, amdgpu) that require physical PCIe hardware cards not emulated in standard QEMU.
- Driver .remove, .shutdown, or pci_unregister_driver teardown callbacks (e.g., igb_remove)
  that are executed only during PCI hot-unplug or sysfs driver unbind operations.

If it modifies reachable core kernel logic, drivers, or architectures, use your code search
tools to verify the code can be executed, then return WorthFuzzing=true.

When returning WorthFuzzing=true, you MUST ALSO:
1. Extract any specific kernel functions that should be heavily fuzzed into FocusSymbols.
   Avoid listing generic hot-path functions to prevent skewed test distributions.
   Prefer non-static, non-inlined API entrypoint functions over internal static helper functions
   (which are inlined by the compiler and do not have distinct symbol addresses).
2. Identify any specific CONFIG_ options required to properly test this new/modified feature.
   Go and look into the Kconfig files and check for ifdefs around the code, do not make assumptions.
   Also check "depends on" lines in Kconfig to include any non-standard parent subsystem configs
   needed for Kbuild to compile the code statically into vmlinux. List them in the EnableConfigs
   output array, and DO NOT add a 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
For your convenience, here is the diff of the changes:
commit 6e7412f48e477c512df286057c5b07073d759e58
Author: syz-cluster <triage@syzkaller.com>
Date:   Thu Jul 30 16:20:54 2026 +0000

    syz-cluster: applied patch under review

diff --git a/drivers/net/can/c_can/c_can_main.c b/drivers/net/can/c_can/c_can_main.c
index 3702cac7fbf0f..b3b321d9ce68d 100644
--- a/drivers/net/can/c_can/c_can_main.c
+++ b/drivers/net/can/c_can/c_can_main.c
@@ -597,20 +597,20 @@ static int c_can_chip_config(struct net_device *dev)
 		return err;
 
 	/* enable automatic retransmission */
-	priv->write_reg(priv, C_CAN_CTRL_REG, CONTROL_ENABLE_AR);
+	priv->write_reg(priv, C_CAN_CTRL_REG, CONTROL_ENABLE_AR | CONTROL_INIT);
 
 	if ((priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) &&
 	    (priv->can.ctrlmode & CAN_CTRLMODE_LOOPBACK)) {
 		/* loopback + silent mode : useful for hot self-test */
-		priv->write_reg(priv, C_CAN_CTRL_REG, CONTROL_TEST);
+		priv->write_reg(priv, C_CAN_CTRL_REG, CONTROL_TEST | CONTROL_INIT);
 		priv->write_reg(priv, C_CAN_TEST_REG, TEST_LBACK | TEST_SILENT);
 	} else if (priv->can.ctrlmode & CAN_CTRLMODE_LOOPBACK) {
 		/* loopback mode : useful for self-test function */
-		priv->write_reg(priv, C_CAN_CTRL_REG, CONTROL_TEST);
+		priv->write_reg(priv, C_CAN_CTRL_REG, CONTROL_TEST | CONTROL_INIT);
 		priv->write_reg(priv, C_CAN_TEST_REG, TEST_LBACK);
 	} else if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) {
 		/* silent mode : bus-monitoring mode */
-		priv->write_reg(priv, C_CAN_CTRL_REG, CONTROL_TEST);
+		priv->write_reg(priv, C_CAN_CTRL_REG, CONTROL_TEST | CONTROL_INIT);
 		priv->write_reg(priv, C_CAN_TEST_REG, TEST_SILENT);
 	}
 
diff --git a/drivers/net/can/ctucanfd/ctucanfd_base.c b/drivers/net/can/ctucanfd/ctucanfd_base.c
index 0ea1ff28dfce8..07d4aa43c700a 100644
--- a/drivers/net/can/ctucanfd/ctucanfd_base.c
+++ b/drivers/net/can/ctucanfd/ctucanfd_base.c
@@ -340,8 +340,8 @@ static void ctucan_set_mode(struct ctucan_priv *priv, const struct can_ctrlmode
 			(mode_reg & ~REG_MODE_FDE);
 
 	mode_reg = (mode->flags & CAN_CTRLMODE_PRESUME_ACK) ?
-			(mode_reg | REG_MODE_ACF) :
-			(mode_reg & ~REG_MODE_ACF);
+			(mode_reg | REG_MODE_STM) :
+			(mode_reg & ~REG_MODE_STM);
 
 	mode_reg = (mode->flags & CAN_CTRLMODE_FD_NON_ISO) ?
 			(mode_reg | REG_MODE_NISOFD) :
@@ -869,7 +869,7 @@ static void ctucan_err_interrupt(struct net_device *ndev, u32 isr)
 			break;
 		case CAN_STATE_ERROR_ACTIVE:
 			if (skb) {
-				cf->can_id |= CAN_ERR_CNT;
+				cf->can_id |= CAN_ERR_CRTL | CAN_ERR_CNT;
 				cf->data[1] = CAN_ERR_CRTL_ACTIVE;
 				cf->data[6] = bec.txerr;
 				cf->data[7] = bec.rxerr;
@@ -1136,8 +1136,12 @@ static irqreturn_t ctucan_interrupt(int irq, void *dev_id)
 		/* Error interrupts */
 		if (FIELD_GET(REG_INT_STAT_EWLI, isr) ||
 		    FIELD_GET(REG_INT_STAT_FCSI, isr) ||
-		    FIELD_GET(REG_INT_STAT_ALI, isr)) {
-			icr = isr & (REG_INT_STAT_EWLI | REG_INT_STAT_FCSI | REG_INT_STAT_ALI);
+		    FIELD_GET(REG_INT_STAT_ALI, isr) ||
+		    FIELD_GET(REG_INT_STAT_BEI, isr)) {
+			icr = isr & (REG_INT_STAT_EWLI |
+				     REG_INT_STAT_FCSI |
+				     REG_INT_STAT_ALI |
+				     REG_INT_STAT_BEI);
 
 			ctucan_netdev_dbg(ndev, "some ERR interrupt: clearing 0x%08x\n", icr);
 			ctucan_write32(priv, CTUCANFD_INT_STAT, icr);
diff --git a/drivers/net/can/ctucanfd/ctucanfd_pci.c b/drivers/net/can/ctucanfd/ctucanfd_pci.c
index 625788fa89766..4b6db28f7b670 100644
--- a/drivers/net/can/ctucanfd/ctucanfd_pci.c
+++ b/drivers/net/can/ctucanfd/ctucanfd_pci.c
@@ -194,7 +194,7 @@ static int ctucan_pci_probe(struct pci_dev *pdev,
 	pci_set_drvdata(pdev, NULL);
 	kfree(bdata);
 err_pci_iounmap_bar0:
-	pci_iounmap(pdev, cra_addr);
+	pci_iounmap(pdev, bar0_base);
 err_pci_iounmap_bar1:
 	pci_iounmap(pdev, addr);
 err_release_regions:
@@ -266,6 +266,7 @@ static const struct pci_device_id ctucan_pci_tbl[] = {
 		CTUCAN_WITH_CTUCAN_ID)},
 	{},
 };
+MODULE_DEVICE_TABLE(pci, ctucan_pci_tbl);
 
 static struct pci_driver ctucan_pci_driver = {
 	.name = KBUILD_MODNAME,
diff --git a/drivers/net/can/rcar/rcar_canfd.c b/drivers/net/can/rcar/rcar_canfd.c
index eaf8cac780387..fcc37b73ed436 100644
--- a/drivers/net/can/rcar/rcar_canfd.c
+++ b/drivers/net/can/rcar/rcar_canfd.c
@@ -2003,20 +2003,12 @@ static int rcar_canfd_global_init(struct rcar_canfd_global *gpriv)
 	u32 ch, sts;
 	int err;
 
-	err = reset_control_reset(gpriv->rstc1);
-	if (err)
-		return err;
-
-	err = reset_control_reset(gpriv->rstc2);
-	if (err)
-		goto fail_reset1;
-
 	/* Enable peripheral clock for register access */
 	err = clk_prepare_enable(gpriv->clkp);
 	if (err) {
 		dev_err(dev, "failed to enable peripheral clock: %pe\n",
 			ERR_PTR(err));
-		goto fail_reset2;
+		return err;
 	}
 
 	/* Enable RAM clock */
@@ -2027,10 +2019,18 @@ static int rcar_canfd_global_init(struct rcar_canfd_global *gpriv)
 		goto fail_clk;
 	}
 
+	err = reset_control_reset(gpriv->rstc1);
+	if (err)
+		goto fail_ram_clk;
+
+	err = reset_control_reset(gpriv->rstc2);
+	if (err)
+		goto fail_reset1;
+
 	err = rcar_canfd_reset_controller(gpriv);
 	if (err) {
 		dev_err(dev, "reset controller failed: %pe\n", ERR_PTR(err));
-		goto fail_ram_clk;
+		goto fail_reset2;
 	}
 
 	/* Controller in Global reset & Channel reset mode */
@@ -2068,14 +2068,14 @@ static int rcar_canfd_global_init(struct rcar_canfd_global *gpriv)
 
 fail_mode:
 	rcar_canfd_disable_global_interrupts(gpriv);
-fail_ram_clk:
-	clk_disable_unprepare(gpriv->clk_ram);
-fail_clk:
-	clk_disable_unprepare(gpriv->clkp);
 fail_reset2:
 	reset_control_assert(gpriv->rstc2);
 fail_reset1:
 	reset_control_assert(gpriv->rstc1);
+fail_ram_clk:
+	clk_disable_unprepare(gpriv->clk_ram);
+fail_clk:
+	clk_disable_unprepare(gpriv->clkp);
 	return err;
 }
 
@@ -2090,10 +2090,10 @@ static void rcar_canfd_global_deinit(struct rcar_canfd_global *gpriv, bool full)
 		rcar_canfd_set_bit(gpriv->base, RCANFD_GCTR, RCANFD_GCTR_GSLPR);
 	}
 
-	clk_disable_unprepare(gpriv->clk_ram);
-	clk_disable_unprepare(gpriv->clkp);
 	reset_control_assert(gpriv->rstc2);
 	reset_control_assert(gpriv->rstc1);
+	clk_disable_unprepare(gpriv->clk_ram);
+	clk_disable_unprepare(gpriv->clkp);
 }
 
 static int rcar_canfd_probe(struct platform_device *pdev)
diff --git a/drivers/net/can/softing/softing_fw.c b/drivers/net/can/softing/softing_fw.c
index 721df91cdbfbc..282570daf3efe 100644
--- a/drivers/net/can/softing/softing_fw.c
+++ b/drivers/net/can/softing/softing_fw.c
@@ -91,12 +91,12 @@ int softing_bootloader_command(struct softing *card, int16_t cmd,
 	return ret;
 }
 
-static int fw_parse(const uint8_t **pmem, uint16_t *ptype, uint32_t *paddr,
-		uint16_t *plen, const uint8_t **pdat)
+static int fw_parse(const u8 **pmem, const u8 *limit, u16 *ptype,
+		    u32 *paddr, u16 *plen, const u8 **pdat)
 {
 	uint16_t checksum[2];
-	const uint8_t *mem;
-	const uint8_t *end;
+	const u8 *mem;
+	const u8 *record_end;
 
 	/*
 	 * firmware records are a binary, unaligned stream composed of:
@@ -114,14 +114,21 @@ static int fw_parse(const uint8_t **pmem, uint16_t *ptype, uint32_t *paddr,
 	 * endianness & alignment.
 	 */
 	mem = *pmem;
+	/* A record needs an 8-byte prefix and a 2-byte checksum. */
+	if (mem > limit || limit - mem < 10)
+		return -EINVAL;
+
 	*ptype = le16_to_cpup((void *)&mem[0]);
 	*paddr = le32_to_cpup((void *)&mem[2]);
 	*plen = le16_to_cpup((void *)&mem[6]);
+	if (*plen > limit - mem - 10)
+		return -EINVAL;
+
 	*pdat = &mem[8];
 	/* verify checksum */
-	end = &mem[8 + *plen];
-	checksum[0] = le16_to_cpup((void *)end);
-	for (checksum[1] = 0; mem < end; ++mem)
+	record_end = &mem[8 + *plen];
+	checksum[0] = le16_to_cpup((void *)record_end);
+	for (checksum[1] = 0; mem < record_end; ++mem)
 		checksum[1] += *mem;
 	if (checksum[0] != checksum[1])
 		return -EINVAL;
@@ -139,6 +146,7 @@ int softing_load_fw(const char *file, struct softing *card,
 	uint16_t type, len;
 	uint32_t addr;
 	uint8_t *buf = NULL, *new_buf;
+	s64 dpram_offset;
 	int buflen = 0;
 	int8_t type_end = 0;
 
@@ -153,7 +161,7 @@ int softing_load_fw(const char *file, struct softing *card,
 	mem = fw->data;
 	end = &mem[fw->size];
 	/* look for header record */
-	ret = fw_parse(&mem, &type, &addr, &len, &dat);
+	ret = fw_parse(&mem, end, &type, &addr, &len, &dat);
 	if (ret < 0)
 		goto failed;
 	if (type != 0xffff)
@@ -164,7 +172,7 @@ int softing_load_fw(const char *file, struct softing *card,
 	}
 	/* ok, we had a header */
 	while (mem < end) {
-		ret = fw_parse(&mem, &type, &addr, &len, &dat);
+		ret = fw_parse(&mem, end, &type, &addr, &len, &dat);
 		if (ret < 0)
 			goto failed;
 		if (type == 3) {
@@ -179,9 +187,13 @@ int softing_load_fw(const char *file, struct softing *card,
 			goto failed;
 		}
 
-		if ((addr + len + offset) > size)
+		dpram_offset = (s64)addr + offset;
+		if (dpram_offset < 0 || dpram_offset > size ||
+		    len > size - dpram_offset) {
+			ret = -EINVAL;
 			goto failed;
-		memcpy_toio(&dpram[addr + offset], dat, len);
+		}
+		memcpy_toio(&dpram[dpram_offset], dat, len);
 		/* be sure to flush caches from IO space */
 		mb();
 		if (len > buflen) {
@@ -195,7 +207,7 @@ int softing_load_fw(const char *file, struct softing *card,
 			buf = new_buf;
 		}
 		/* verify record data */
-		memcpy_fromio(buf, &dpram[addr + offset], len);
+		memcpy_fromio(buf, &dpram[dpram_offset], len);
 		if (memcmp(buf, dat, len)) {
 			/* is not ok */
 			dev_alert(&card->pdev->dev, "DPRAM readback failed\n");
@@ -237,7 +249,7 @@ int softing_load_app_fw(const char *file, struct softing *card)
 	mem = fw->data;
 	end = &mem[fw->size];
 	/* look for header record */
-	ret = fw_parse(&mem, &type, &addr, &len, &dat);
+	ret = fw_parse(&mem, end, &type, &addr, &len, &dat);
 	if (ret)
 		goto failed;
 	ret = -EINVAL;
@@ -253,7 +265,7 @@ int softing_load_app_fw(const char *file, struct softing *card)
 	}
 	/* ok, we had a header */
 	while (mem < end) {
-		ret = fw_parse(&mem, &type, &addr, &len, &dat);
+		ret = fw_parse(&mem, end, &type, &addr, &len, &dat);
 		if (ret)
 			goto failed;
 
@@ -279,6 +291,12 @@ int softing_load_app_fw(const char *file, struct softing *card)
 		/* work in 16bit (target) */
 		sum &= 0xffff;
 
+		if (card->pdat->app.offs > card->dpram_size ||
+		    len > card->dpram_size - card->pdat->app.offs) {
+			ret = -EINVAL;
+			goto failed;
+		}
+
 		memcpy_toio(&card->dpram[card->pdat->app.offs], dat, len);
 		iowrite32(card->pdat->app.offs + card->pdat->app.addr,
 				&card->dpram[DPRAM_COMMAND + 2]);
diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c
index 9b25dda7c1838..24cf8f651f8f1 100644
--- a/drivers/net/can/usb/ems_usb.c
+++ b/drivers/net/can/usb/ems_usb.c
@@ -409,6 +409,40 @@ static void ems_usb_rx_err(struct ems_usb *dev, struct ems_cpc_msg *msg)
 		netif_rx(skb);
 }
 
+static bool ems_usb_rx_msg_len_valid(struct ems_cpc_msg *msg)
+{
+	size_t len = msg->length;
+	size_t can_len;
+
+	switch (msg->type) {
+	case CPC_MSG_TYPE_CAN_STATE:
+		return len >= sizeof(msg->msg.can_state);
+
+	case CPC_MSG_TYPE_CAN_FRAME:
+	case CPC_MSG_TYPE_EXT_CAN_FRAME:
+	case CPC_MSG_TYPE_RTR_FRAME:
+	case CPC_MSG_TYPE_EXT_RTR_FRAME:
+		if (len < CPC_CAN_MSG_MIN_SIZE)
+			return false;
+
+		if (msg->type == CPC_MSG_TYPE_RTR_FRAME ||
+		    msg->type == CPC_MSG_TYPE_EXT_RTR_FRAME)
+			return true;
+
+		can_len = can_cc_dlc2len(msg->msg.can_msg.length & 0xf);
+		return len >= CPC_CAN_MSG_MIN_SIZE + can_len;
+
+	case CPC_MSG_TYPE_CAN_FRAME_ERROR:
+		return len >= sizeof(msg->msg.error);
+
+	case CPC_MSG_TYPE_OVERRUN:
+		return len >= sizeof(msg->msg.overrun);
+
+	default:
+		return true;
+	}
+}
+
 /*
  * callback for bulk IN urb
  */
@@ -451,6 +485,15 @@ static void ems_usb_read_bulk_callback(struct urb *urb)
 			}
 
 			msg = (struct ems_cpc_msg *)&ibuf[start];
+			if (msg->length >
+			    urb->actual_length - start - CPC_MSG_HEADER_LEN) {
+				netdev_err(netdev, "format error\n");
+				break;
+			}
+			if (!ems_usb_rx_msg_len_valid(msg)) {
+				netdev_err(netdev, "format error\n");
+				break;
+			}
 
 			switch (msg->type) {
 			case CPC_MSG_TYPE_CAN_STATE:
diff --git a/drivers/net/can/usb/etas_es58x/es58x_core.c b/drivers/net/can/usb/etas_es58x/es58x_core.c
index b259f61098083..e1724ae79c5a1 100644
--- a/drivers/net/can/usb/etas_es58x/es58x_core.c
+++ b/drivers/net/can/usb/etas_es58x/es58x_core.c
@@ -1476,7 +1476,6 @@ static void es58x_read_bulk_callback(struct urb *urb)
 		dev_err_ratelimited(dev,
 				    "Failed resubmitting read bulk urb: %pe\n",
 				    ERR_PTR(ret));
-	return;
 
  free_urb:
 	usb_free_coherent(urb->dev, urb->transfer_buffer_length,
diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
index ec9a7cbbbc696..82508a8650959 100644
--- a/drivers/net/can/usb/gs_usb.c
+++ b/drivers/net/can/usb/gs_usb.c
@@ -674,7 +674,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
 		if (hf->flags & GS_CAN_FLAG_FD) {
 			skb = alloc_canfd_skb(netdev, &cfd);
 			if (!skb)
-				return;
+				goto resubmit_urb;
 
 			cfd->can_id = le32_to_cpu(hf->can_id);
 			cfd->len = data_length;
@@ -687,7 +687,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
 		} else {
 			skb = alloc_can_skb(netdev, &cf);
 			if (!skb)
-				return;
+				goto resubmit_urb;
 
 			cf->can_id = le32_to_cpu(hf->can_id);
 			can_frame_set_cc_len(cf, hf->can_dlc, dev->can.ctrlmode);
diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c
index e09d663e362f9..efbb7bed34c9d 100644
--- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c
+++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c
@@ -1626,6 +1626,7 @@ static int kvaser_usb_hydra_get_busparams(struct kvaser_usb_net_priv *priv,
 	reinit_completion(&priv->get_busparams_comp);
 
 	err = kvaser_usb_send_cmd(dev, cmd, cmd_len);
+	kfree(cmd);
 	if (err)
 		return err;
 
diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
index df737cfc5ea0c..a876c7819b81c 100644
--- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
+++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
@@ -691,13 +691,22 @@ static int kvaser_usb_leaf_wait_cmd(const struct kvaser_usb *dev, u8 id,
 				continue;
 			}
 
-			if (pos + tmp->len > actual_len) {
+			if (tmp->len < CMD_HEADER_LEN ||
+			    tmp->len > actual_len - pos) {
 				dev_err_ratelimited(&dev->intf->dev,
 						    "Format error\n");
 				break;
 			}
 
 			if (tmp->id == id) {
+				if (tmp->len > sizeof(*cmd)) {
+					dev_err_ratelimited(&dev->intf->dev,
+							    "Received command %u too large (%u)\n",
+							    tmp->id, tmp->len);
+					err = -EIO;
+					goto end;
+				}
+
 				memcpy(cmd, tmp, tmp->len);
 				goto end;
 			}
@@ -1737,7 +1746,7 @@ static void kvaser_usb_leaf_read_bulk_callback(struct kvaser_usb *dev,
 			continue;
 		}
 
-		if (pos + cmd->len > len) {
+		if (cmd->len < CMD_HEADER_LEN || cmd->len > len - pos) {
 			dev_err_ratelimited(&dev->intf->dev, "Format error\n");
 			break;
 		}
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 c7933d1acc99a..55aad01cd8cac 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
@@ -470,7 +470,6 @@ static int peak_usb_start(struct peak_usb_device *dev)
 				netif_device_detach(dev->netdev);
 
 			usb_unanchor_urb(urb);
-			kfree(buf);
 			usb_free_urb(urb);
 			break;
 		}
diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
index ef9fd693e9bd3..0d46f4ce5dca7 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
@@ -566,6 +566,13 @@ static int pcan_usb_fd_decode_canmsg(struct pcan_usb_fd_if *usb_if,
 				     dev->can.ctrlmode);
 	}
 
+	if (!(rx_msg_flags & PUCAN_MSG_RTR) &&
+	    le16_to_cpu(rx_msg->size) - offsetof(struct pucan_rx_msg, d) <
+	    cfd->len) {
+		kfree_skb(skb);
+		return -EBADMSG;
+	}
+
 	cfd->can_id = le32_to_cpu(rm->can_id);
 
 	if (rx_msg_flags & PUCAN_MSG_EXT_ID)
@@ -714,6 +721,24 @@ static void pcan_usb_fd_decode_ts(struct pcan_usb_fd_if *usb_if,
 		peak_usb_set_ts_now(&usb_if->time_ref, le32_to_cpu(ts->ts_low));
 }
 
+static size_t pcan_usb_fd_rx_msg_min_size(u16 rx_msg_type)
+{
+	switch (rx_msg_type) {
+	case PUCAN_MSG_CAN_RX:
+		return offsetof(struct pucan_rx_msg, d);
+	case PCAN_UFD_MSG_CALIBRATION:
+		return sizeof(struct pcan_ufd_ts_msg);
+	case PUCAN_MSG_ERROR:
+		return sizeof(struct pucan_error_msg);
+	case PUCAN_MSG_STATUS:
+		return sizeof(struct pucan_status_msg);
+	case PCAN_UFD_MSG_OVERRUN:
+		return sizeof(struct pcan_ufd_ovr_msg);
+	default:
+		return sizeof(struct pucan_msg);
+	}
+}
+
 /* callback for bulk IN urb */
 static int pcan_usb_fd_decode_buf(struct peak_usb_device *dev, struct urb *urb)
 {
@@ -728,6 +753,12 @@ static int pcan_usb_fd_decode_buf(struct peak_usb_device *dev, struct urb *urb)
 	msg_end = urb->transfer_buffer + urb->actual_length;
 	for (; msg_ptr < msg_end;) {
 		u16 rx_msg_type, rx_msg_size;
+		size_t rx_msg_min_size;
+
+		if (msg_end - msg_ptr < sizeof(*rx_msg)) {
+			err = -EBADMSG;
+			break;
+		}
 
 		rx_msg = (struct pucan_msg *)msg_ptr;
 		if (!rx_msg->size) {
@@ -739,13 +770,20 @@ static int pcan_usb_fd_decode_buf(struct peak_usb_device *dev, struct urb *urb)
 		rx_msg_type = le16_to_cpu(rx_msg->type);
 
 		/* check if the record goes out of current packet */
-		if (msg_ptr + rx_msg_size > msg_end) {
+		if (rx_msg_size > msg_end - msg_ptr) {
 			netdev_err(netdev,
 				   "got frag rec: should inc usb rx buf sze\n");
 			err = -EBADMSG;
 			break;
 		}
 
+		rx_msg_min_size = pcan_usb_fd_rx_msg_min_size(rx_msg_type);
+		if (rx_msg_size < rx_msg_min_size) {
+			netdev_err(netdev, "got short rec\n");
+			err = -EBADMSG;
+			break;
+		}
+
 		switch (rx_msg_type) {
 		case PUCAN_MSG_CAN_RX:
 			err = pcan_usb_fd_decode_canmsg(usb_if, rx_msg);
diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c
index aefcded8e12a8..b6be8c19e537f 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c
@@ -534,12 +534,18 @@ static int pcan_usb_pro_handle_canmsg(struct pcan_usb_pro_interface *usb_if,
 				      struct pcan_usb_pro_rxmsg *rx)
 {
 	const unsigned int ctrl_idx = (rx->len >> 4) & 0x0f;
-	struct peak_usb_device *dev = usb_if->dev[ctrl_idx];
-	struct net_device *netdev = dev->netdev;
+	struct peak_usb_device *dev;
+	struct net_device *netdev;
 	struct can_frame *can_frame;
 	struct sk_buff *skb;
 	struct skb_shared_hwtstamps *hwts;
 
+	if (ctrl_idx >= ARRAY_SIZE(usb_if->dev))
+		return -EINVAL;
+
+	dev = usb_if->dev[ctrl_idx];
+	netdev = dev->netdev;
+
 	skb = alloc_can_skb(netdev, &can_frame);
 	if (!skb)
 		return -ENOMEM;
@@ -573,14 +579,20 @@ static int pcan_usb_pro_handle_error(struct pcan_usb_pro_interface *usb_if,
 {
 	const u16 raw_status = le16_to_cpu(er->status);
 	const unsigned int ctrl_idx = (er->channel >> 4) & 0x0f;
-	struct peak_usb_device *dev = usb_if->dev[ctrl_idx];
-	struct net_device *netdev = dev->netdev;
+	struct peak_usb_device *dev;
+	struct net_device *netdev;
 	struct can_frame *can_frame;
 	enum can_state new_state = CAN_STATE_ERROR_ACTIVE;
 	u8 err_mask = 0;
 	struct sk_buff *skb;
 	struct skb_shared_hwtstamps *hwts;
 
+	if (ctrl_idx >= ARRAY_SIZE(usb_if->dev))
+		return -EINVAL;
+
+	dev = usb_if->dev[ctrl_idx];
+	netdev = dev->netdev;
+
 	/* nothing should be sent while in BUS_OFF state */
 	if (dev->can.state == CAN_STATE_BUS_OFF)
 		return 0;
diff --git a/net/can/isotp.c b/net/can/isotp.c
index 54becaf6898f1..155530aedce2e 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -127,6 +127,15 @@ MODULE_PARM_DESC(max_pdu_size, "maximum isotp pdu size (default "
 #define ISOTP_FC_TIMEOUT 1	/* 1 sec */
 #define ISOTP_ECHO_TIMEOUT 2	/* 2 secs */
 
+/* so->tx_result[so->tx_gen % ISOTP_TX_RESULT_SLOTS] holds the packed value
+ * (err << ISOTP_TX_RESULT_GEN_BITS | gen) for each tx generation slot, so it
+ * can be handled with a single READ_ONCE()/WRITE_ONCE() access.
+ */
+#define ISOTP_TX_RESULT_SLOTS 4
+#define ISOTP_TX_RESULT_GEN_BITS 24
+#define ISOTP_TX_RESULT_GEN_MASK ((1U << ISOTP_TX_RESULT_GEN_BITS) - 1)
+#define ISOTP_TX_RESULT_ERR_MASK 0xFF
+
 enum {
 	ISOTP_IDLE = 0,
 	ISOTP_WAIT_FIRST_FC,
@@ -166,7 +175,8 @@ struct isotp_sock {
 	u32 force_tx_stmin;
 	u32 force_rx_stmin;
 	u32 cfecho; /* consecutive frame echo tag */
-	u32 tx_gen; /* generation, bumped per new tx transfer */
+	u32 tx_gen; /* transfer generation, increased per new tx transfer */
+	u32 tx_result[ISOTP_TX_RESULT_SLOTS]; /* per-generation result slots */
 	struct tpcon rx, tx;
 	struct list_head notifier;
 	wait_queue_head_t wait;
@@ -177,6 +187,65 @@ static LIST_HEAD(isotp_notifier_list);
 static DEFINE_SPINLOCK(isotp_notifier_lock);
 static struct isotp_sock *isotp_busy_notifier;
 
+/* increase (24 bit) tx generation value */
+static u32 isotp_inc_tx_gen(u32 gen)
+{
+	return (gen + 1) & ISOTP_TX_RESULT_GEN_MASK;
+}
+
+/* store 8 bit error and 24 bit tx generation values in packed u32 element */
+static u32 isotp_pack_tx_result(u32 gen, int err)
+{
+	return gen | ((u32)err << ISOTP_TX_RESULT_GEN_BITS);
+}
+
+/* get the 24 bit tx generation value from the tx result */
+static u32 isotp_get_tx_gen(u32 gen_err)
+{
+	return gen_err & ISOTP_TX_RESULT_GEN_MASK;
+}
+
+/* get the 8 bit error value from the tx result */
+static u32 isotp_get_tx_err(u32 gen_err)
+{
+	return (gen_err >> ISOTP_TX_RESULT_GEN_BITS) & ISOTP_TX_RESULT_ERR_MASK;
+}
+
+/* store transfer result in per-generation%4 so->tx_result[] slot */
+static void isotp_set_tx_result(struct isotp_sock *so, u32 gen, int err)
+{
+	WRITE_ONCE(so->tx_result[gen % ISOTP_TX_RESULT_SLOTS],
+		   isotp_pack_tx_result(gen, err));
+}
+
+/* fetch the result recorded for 'gen', as a (negative) errno (0 for success) */
+static int isotp_get_tx_result(struct isotp_sock *so, u32 gen)
+{
+	u32 result = READ_ONCE(so->tx_result[gen % ISOTP_TX_RESULT_SLOTS]);
+
+	if (isotp_get_tx_gen(result) != gen) {
+		pr_notice_once("can-isotp: tx_result[] slot reused before read\n");
+
+		/* report failure rather than risk a false success */
+		return -ECOMM;
+	}
+
+	return -(isotp_get_tx_err(result));
+}
+
+/* true if done, shut down or superseded ('gen' is no longer the active
+ * transfer). Reads tx.state first (acquire) so tx_gen/tx_result reads
+ * below see at least what that state write published (common sequence).
+ */
+static bool isotp_tx_gen_done(struct isotp_sock *so, u32 gen)
+{
+	/* read tx.state first for the common sequence */
+	u32 state = smp_load_acquire(&so->tx.state);
+
+	return state == ISOTP_IDLE || state == ISOTP_SHUTDOWN ||
+	       READ_ONCE(so->tx_gen) != gen;
+}
+
 static inline struct isotp_sock *isotp_sk(const struct sock *sk)
 {
 	return (struct isotp_sock *)sk;
@@ -199,7 +268,7 @@ static enum hrtimer_restart isotp_rx_timer_handler(struct hrtimer *hrtimer)
 					     rxtimer);
 	struct sock *sk = &so->sk;
 
-	if (so->rx.state == ISOTP_WAIT_DATA) {
+	if (READ_ONCE(so->rx.state) == ISOTP_WAIT_DATA) {
 		/* we did not get new data frames in time */
 
 		/* report 'connection timed out' */
@@ -208,7 +277,7 @@ static enum hrtimer_restart isotp_rx_timer_handler(struct hrtimer *hrtimer)
 			sk_error_report(sk);
 
 		/* reset rx state */
-		so->rx.state = ISOTP_IDLE;
+		WRITE_ONCE(so->rx.state, ISOTP_IDLE);
 	}
 
 	return HRTIMER_NORESTART;
@@ -372,20 +441,19 @@ static void isotp_send_cframe(struct isotp_sock *so);
 static int isotp_rcv_fc(struct isotp_sock *so, struct canfd_frame *cf, int ae)
 {
 	struct sock *sk = &so->sk;
+	int tx_err = EBADMSG; /* default for unknown FC status */
 
-	if (so->tx.state != ISOTP_WAIT_FC &&
-	    so->tx.state != ISOTP_WAIT_FIRST_FC)
+	if (READ_ONCE(so->tx.state) != ISOTP_WAIT_FC &&
+	    READ_ONCE(so->tx.state) != ISOTP_WAIT_FIRST_FC)
 		return 0;
 
 	hrtimer_cancel(&so->txtimer);
 
 	/* isotp_tx_timeout() may have given up on this job while
-	 * hrtimer_cancel() above waited for it to finish; so->rx_lock
-	 * (held by our caller isotp_rcv()) rules out a concurrent claim,
-	 * so a plain recheck is enough here.
+	 * hrtimer_cancel() above waited for it to finish => recheck
 	 */
-	if (so->tx.state != ISOTP_WAIT_FC &&
-	    so->tx.state != ISOTP_WAIT_FIRST_FC)
+	if (READ_ONCE(so->tx.state) != ISOTP_WAIT_FC &&
+	    READ_ONCE(so->tx.state) != ISOTP_WAIT_FIRST_FC)
 		return 1;
 
 	if ((cf->len < ae + FC_CONTENT_SZ) ||
@@ -396,13 +464,15 @@ static int isotp_rcv_fc(struct isotp_sock *so, struct canfd_frame *cf, int ae)
 		if (!sock_flag(sk, SOCK_DEAD))
 			sk_error_report(sk);
 
-		so->tx.state = ISOTP_IDLE;
+		isotp_set_tx_result(so, so->tx_gen, EBADMSG);
+		/* set to IDLE after publishing tx_result */
+		smp_store_release(&so->tx.state, ISOTP_IDLE);
 		wake_up_interruptible(&so->wait);
 		return 1;
 	}
 
 	/* get static/dynamic communication params from first/every FC frame */
-	if (so->tx.state == ISOTP_WAIT_FIRST_FC ||
+	if (READ_ONCE(so->tx.state) == ISOTP_WAIT_FIRST_FC ||
 	    so->opt.flags & CAN_ISOTP_DYN_FC_PARMS) {
 		so->txfc.bs = cf->data[ae + 1];
 		so->txfc.stmin = cf->data[ae + 2];
@@ -426,13 +496,13 @@ static int isotp_rcv_fc(struct isotp_sock *so, struct canfd_frame *cf, int ae)
 			so->tx_gap = ktime_add_ns(so->tx_gap,
 						  (so->txfc.stmin - 0xF0)
 						  * 100000);
-		so->tx.state = ISOTP_WAIT_FC;
+		WRITE_ONCE(so->tx.state, ISOTP_WAIT_FC);
 	}
 
 	switch (cf->data[ae] & 0x0F) {
 	case ISOTP_FC_CTS:
 		so->tx.bs = 0;
-		so->tx.state = ISOTP_SENDING;
+		WRITE_ONCE(so->tx.state, ISOTP_SENDING);
 		/* send CF frame and enable echo timeout handling */
 		hrtimer_start(&so->echotimer, ktime_set(ISOTP_ECHO_TIMEOUT, 0),
 			      HRTIMER_MODE_REL_SOFT);
@@ -447,14 +517,19 @@ static int isotp_rcv_fc(struct isotp_sock *so, struct canfd_frame *cf, int ae)
 
 	case ISOTP_FC_OVFLW:
 		/* overflow on receiver side - report 'message too long' */
-		sk->sk_err = EMSGSIZE;
-		if (!sock_flag(sk, SOCK_DEAD))
-			sk_error_report(sk);
+		tx_err = EMSGSIZE;
 		fallthrough;
 
 	default:
-		/* stop this tx job */
-		so->tx.state = ISOTP_IDLE;
+		/* reserved/unknown flow status (tx_err defaults to EBADMSG) */
+
+		sk->sk_err = tx_err;
+		if (!sock_flag(sk, SOCK_DEAD))
+			sk_error_report(sk);
+
+		isotp_set_tx_result(so, so->tx_gen, tx_err);
+		/* set to IDLE after publishing tx_result */
+		smp_store_release(&so->tx.state, ISOTP_IDLE);
 		wake_up_interruptible(&so->wait);
 	}
 	return 0;
@@ -467,7 +542,7 @@ static int isotp_rcv_sf(struct sock *sk, struct canfd_frame *cf, int pcilen,
 	struct sk_buff *nskb;
 
 	hrtimer_cancel(&so->rxtimer);
-	so->rx.state = ISOTP_IDLE;
+	WRITE_ONCE(so->rx.state, ISOTP_IDLE);
 
 	if (!len || len > cf->len - pcilen)
 		return 1;
@@ -501,7 +576,7 @@ static int isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae)
 	int ff_pci_sz;
 
 	hrtimer_cancel(&so->rxtimer);
-	so->rx.state = ISOTP_IDLE;
+	WRITE_ONCE(so->rx.state, ISOTP_IDLE);
 
 	/* get the used sender LL_DL from the (first) CAN frame data length */
 	so->rx.ll_dl = padlen(cf->len);
@@ -555,7 +630,7 @@ static int isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae)
 
 	/* initial setup for this pdu reception */
 	so->rx.sn = 1;
-	so->rx.state = ISOTP_WAIT_DATA;
+	WRITE_ONCE(so->rx.state, ISOTP_WAIT_DATA);
 
 	/* no creation of flow control frames */
 	if (so->opt.flags & CAN_ISOTP_LISTEN_MODE)
@@ -573,7 +648,7 @@ static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,
 	struct sk_buff *nskb;
 	int i;
 
-	if (so->rx.state != ISOTP_WAIT_DATA)
+	if (READ_ONCE(so->rx.state) != ISOTP_WAIT_DATA)
 		return 0;
 
 	/* drop if timestamp gap is less than force_rx_stmin nano secs */
@@ -588,11 +663,9 @@ static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,
 	hrtimer_cancel(&so->rxtimer);
 
 	/* isotp_rx_timer_handler() may have raced us for so->rx.state
-	 * while hrtimer_cancel() above waited for it to finish, already
-	 * reporting ETIMEDOUT and resetting the reception; don't process
-	 * this CF into a reassembly that has already been given up on.
+	 * while hrtimer_cancel() above waited for it to finish => recheck
 	 */
-	if (so->rx.state != ISOTP_WAIT_DATA)
+	if (READ_ONCE(so->rx.state) != ISOTP_WAIT_DATA)
 		return 1;
 
 	/* CFs are never longer than the FF */
@@ -613,7 +686,7 @@ static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,
 			sk_error_report(sk);
 
 		/* reset rx state */
-		so->rx.state = ISOTP_IDLE;
+		WRITE_ONCE(so->rx.state, ISOTP_IDLE);
 		return 1;
 	}
 	so->rx.sn++;
@@ -627,7 +700,7 @@ static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,
 
 	if (so->rx.idx >= so->rx.len) {
 		/* we are done */
-		so->rx.state = ISOTP_IDLE;
+		WRITE_ONCE(so->rx.state, ISOTP_IDLE);
 
 		if ((so->opt.flags & ISOTP_CHECK_PADDING) &&
 		    check_pad(so, cf, i + 1, so->opt.rxpad_content)) {
@@ -698,8 +771,10 @@ static void isotp_rcv(struct sk_buff *skb, void *data)
 
 	if (so->opt.flags & CAN_ISOTP_HALF_DUPLEX) {
 		/* check rx/tx path half duplex expectations */
-		if ((so->tx.state != ISOTP_IDLE && n_pci_type != N_PCI_FC) ||
-		    (so->rx.state != ISOTP_IDLE && n_pci_type == N_PCI_FC))
+		if ((READ_ONCE(so->tx.state) != ISOTP_IDLE &&
+		     n_pci_type != N_PCI_FC) ||
+		    (READ_ONCE(so->rx.state) != ISOTP_IDLE &&
+		     n_pci_type == N_PCI_FC))
 			goto out_unlock;
 	}
 
@@ -794,6 +869,7 @@ static void isotp_send_cframe(struct isotp_sock *so)
 	struct canfd_frame *cf;
 	int can_send_ret;
 	int ae = (so->opt.flags & CAN_ISOTP_EXTEND_ADDR) ? 1 : 0;
+	u32 old_cfecho;
 
 	dev = dev_get_by_index(sock_net(sk), so->ifindex);
 	if (!dev)
@@ -814,6 +890,9 @@ static void isotp_send_cframe(struct isotp_sock *so)
 
 	csx->can_iif = dev->ifindex;
 
+	/* set uid in tx skb to identify CF echo frames */
+	can_set_skb_uid(skb);
+
 	cf = (struct canfd_frame *)skb->data;
 	skb_put_zero(skb, so->ll.mtu);
 
@@ -830,12 +909,15 @@ static void isotp_send_cframe(struct isotp_sock *so)
 	skb->dev = dev;
 	can_skb_set_owner(skb, sk);
 
-	/* cfecho should have been zero'ed by init/isotp_rcv_echo() */
-	if (so->cfecho)
-		pr_notice_once("can-isotp: cfecho is %08X != 0\n", so->cfecho);
+	/* zero'ed by init/isotp_rcv_echo(); reached lock-free via
+	 * isotp_txfr_timer_handler() too, so use READ_ONCE()/WRITE_ONCE()
+	 */
+	old_cfecho = READ_ONCE(so->cfecho);
+	if (old_cfecho)
+		pr_notice_once("can-isotp: cfecho is %08X != 0\n", old_cfecho);
 
 	/* set consecutive frame echo tag */
-	so->cfecho = *(u32 *)cf->data;
+	WRITE_ONCE(so->cfecho, skb->hash);
 
 	/* send frame with local echo enabled */
 	can_send_ret = can_send(skb, 1);
@@ -887,7 +969,6 @@ static void isotp_rcv_echo(struct sk_buff *skb, void *data)
 {
 	struct sock *sk = (struct sock *)data;
 	struct isotp_sock *so = isotp_sk(sk);
-	struct canfd_frame *cf = (struct canfd_frame *)skb->data;
 
 	/* only handle my own local echo CF/SF skb's (no FF!) */
 	if (skb->sk != sk)
@@ -899,32 +980,35 @@ static void isotp_rcv_echo(struct sk_buff *skb, void *data)
 	spin_lock(&so->rx_lock);
 
 	/* so->cfecho may since belong to a new transfer; recheck under lock */
-	if (so->cfecho != *(u32 *)cf->data)
+	if (READ_ONCE(so->cfecho) != skb->hash)
 		goto out_unlock;
 
 	/* cancel local echo timeout */
 	hrtimer_cancel(&so->echotimer);
 
 	/* local echo skb with consecutive frame has been consumed */
-	so->cfecho = 0;
+	WRITE_ONCE(so->cfecho, 0);
 
 	/* claiming a transfer also takes so->rx_lock, so a plain recheck
 	 * is enough: so->tx.state can't have flipped to ISOTP_SENDING for
 	 * a new claim while we're still in here
 	 */
-	if (so->tx.state != ISOTP_SENDING)
+	if (READ_ONCE(so->tx.state) != ISOTP_SENDING)
 		goto out_unlock;
 
 	if (so->tx.idx >= so->tx.len) {
 		/* we are done */
-		so->tx.state = ISOTP_IDLE;
+
+		isotp_set_tx_result(so, so->tx_gen, 0);
+		/* set to IDLE after publishing tx_result */
+		smp_store_release(&so->tx.state, ISOTP_IDLE);
 		wake_up_interruptible(&so->wait);
 		goto out_unlock;
 	}
 
 	if (so->txfc.bs && so->tx.bs >= so->txfc.bs) {
 		/* stop and wait for FC with timeout */
-		so->tx.state = ISOTP_WAIT_FC;
+		WRITE_ONCE(so->tx.state, ISOTP_WAIT_FC);
 		hrtimer_start(&so->txtimer, ktime_set(ISOTP_FC_TIMEOUT, 0),
 			      HRTIMER_MODE_REL_SOFT);
 		goto out_unlock;
@@ -946,16 +1030,20 @@ static void isotp_rcv_echo(struct sk_buff *skb, void *data)
 	spin_unlock(&so->rx_lock);
 }
 
-/* shared by so->txtimer's and so->echotimer's callbacks. Both timers get
- * cancelled under so->rx_lock elsewhere, so this must stay lock-free to
- * avoid deadlocking with that; uses so->tx_gen instead to avoid tainting
- * a new transfer with an error from the one that just timed out.
+/* isotp_tx_timeout: we did not get any flow control or echo frame in time
+ *
+ * Shared by so->txtimer's and so->echotimer's callbacks. Both timers get
+ * cancelled under so->rx_lock elsewhere, so this must stay lock-free.
+ *
+ * tx.state is acquired before tx_gen. Common sequence in isotp_tx_gen_done().
+ * cmpxchg() only orders itself, not the two preceding loads.
  */
 static enum hrtimer_restart isotp_tx_timeout(struct isotp_sock *so)
 {
 	struct sock *sk = &so->sk;
+	/* read tx.state first for the common sequence */
+	u32 old_state = smp_load_acquire(&so->tx.state);
 	u32 gen = READ_ONCE(so->tx_gen);
-	u32 old_state = READ_ONCE(so->tx.state);
 
 	/* don't handle timeouts in IDLE or SHUTDOWN state */
 	if (old_state == ISOTP_IDLE || old_state == ISOTP_SHUTDOWN)
@@ -965,14 +1053,14 @@ static enum hrtimer_restart isotp_tx_timeout(struct isotp_sock *so)
 	if (cmpxchg(&so->tx.state, old_state, ISOTP_IDLE) != old_state)
 		return HRTIMER_NORESTART;
 
-	/* we did not get any flow control or echo frame in time */
+	/* detected timeout: report 'communication error on send' */
 
-	if (READ_ONCE(so->tx_gen) == gen) {
-		/* report 'communication error on send' */
-		sk->sk_err = ECOMM;
-		if (!sock_flag(sk, SOCK_DEAD))
-			sk_error_report(sk);
-	}
+	/* a stale read of this slot by a waiter still falls back to ECOMM */
+	isotp_set_tx_result(so, gen, ECOMM);
+
+	sk->sk_err = ECOMM;
+	if (!sock_flag(sk, SOCK_DEAD))
+		sk_error_report(sk);
 
 	wake_up_interruptible(&so->wait);
 
@@ -1007,7 +1095,7 @@ static enum hrtimer_restart isotp_txfr_timer_handler(struct hrtimer *hrtimer)
 		      HRTIMER_MODE_REL_SOFT);
 
 	/* cfecho should be consumed by isotp_rcv_echo() here */
-	if (so->tx.state == ISOTP_SENDING && !so->cfecho)
+	if (READ_ONCE(so->tx.state) == ISOTP_SENDING && !READ_ONCE(so->cfecho))
 		isotp_send_cframe(so);
 
 	return HRTIMER_NORESTART;
@@ -1026,10 +1114,12 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
 	s64 hrtimer_sec = ISOTP_ECHO_TIMEOUT;
 	struct hrtimer *tx_hrt = &so->echotimer;
 	u32 new_state = ISOTP_SENDING;
+	u32 my_gen;
+	u32 old_cfecho;
 	int off;
 	int err;
 
-	if (!so->bound || so->tx.state == ISOTP_SHUTDOWN)
+	if (!so->bound || READ_ONCE(so->tx.state) == ISOTP_SHUTDOWN)
 		return -EADDRNOTAVAIL;
 
 	/* claim the socket under so->rx_lock: this serializes the claim
@@ -1046,29 +1136,33 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
 		if (msg->msg_flags & MSG_DONTWAIT)
 			return -EAGAIN;
 
-		if (so->tx.state == ISOTP_SHUTDOWN)
+		if (READ_ONCE(so->tx.state) == ISOTP_SHUTDOWN)
 			return -EADDRNOTAVAIL;
 
 		/* wait for complete transmission of current pdu */
 		err = wait_event_interruptible(so->wait,
-					       so->tx.state == ISOTP_IDLE);
+					       READ_ONCE(so->tx.state) == ISOTP_IDLE ||
+					       READ_ONCE(so->tx.state) == ISOTP_SHUTDOWN);
 		if (err)
 			return err;
 	}
 
-	/* new transfer: bump so->tx_gen and drain the old one's timers,
-	 * still under the so->rx_lock we just claimed the socket with
-	 */
-	WRITE_ONCE(so->tx.state, ISOTP_SENDING);
-	WRITE_ONCE(so->tx_gen, READ_ONCE(so->tx_gen) + 1);
+	/* txfrtimer's callback re-arms echotimer lock-free: drain it first */
+	hrtimer_cancel(&so->txfrtimer);
 	hrtimer_cancel(&so->txtimer);
 	hrtimer_cancel(&so->echotimer);
-	hrtimer_cancel(&so->txfrtimer);
-	so->cfecho = 0;
+
+	/* new transfer: increment so->tx_gen and set tx.state after barrier */
+	my_gen = isotp_inc_tx_gen(READ_ONCE(so->tx_gen));
+	isotp_set_tx_result(so, my_gen, ECOMM); /* prevent stale slot matching */
+	WRITE_ONCE(so->tx_gen, my_gen);
+	smp_wmb(); /* see smp_load_acquire() in isotp_tx_[timeout|gen_done] */
+	WRITE_ONCE(so->tx.state, ISOTP_SENDING);
+	WRITE_ONCE(so->cfecho, 0);
 	spin_unlock_bh(&so->rx_lock);
 
 	/* so->bound is only checked once above - a wakeup may have
-	 * unbound/rebound the socket meanwhile, so re-validate it
+	 * unbound/rebound the socket meanwhile => recheck
 	 */
 	if (!so->bound) {
 		err = -EADDRNOTAVAIL;
@@ -1127,6 +1221,9 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
 
 	csx->can_iif = dev->ifindex;
 
+	/* set uid in tx skb to identify CF echo frames */
+	can_set_skb_uid(skb);
+
 	so->tx.len = size;
 	so->tx.idx = 0;
 
@@ -1134,8 +1231,9 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
 	skb_put_zero(skb, so->ll.mtu);
 
 	/* cfecho should have been zero'ed by init / former isotp_rcv_echo() */
-	if (so->cfecho)
-		pr_notice_once("can-isotp: uninit cfecho %08X\n", so->cfecho);
+	old_cfecho = READ_ONCE(so->cfecho);
+	if (old_cfecho)
+		pr_notice_once("can-isotp: uninit cfecho %08X\n", old_cfecho);
 
 	/* check for single frame transmission depending on TX_DL */
 	if (size <= so->tx.ll_dl - SF_PCI_SZ4 - ae - off) {
@@ -1163,7 +1261,7 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
 			cf->data[ae] |= size;
 
 		/* set CF echo tag for isotp_rcv_echo() (SF-mode) */
-		so->cfecho = *(u32 *)cf->data;
+		WRITE_ONCE(so->cfecho, skb->hash);
 	} else {
 		/* send first frame */
 
@@ -1180,7 +1278,7 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
 			so->txfc.bs = 0;
 
 			/* set CF echo tag for isotp_rcv_echo() (CF-mode) */
-			so->cfecho = *(u32 *)cf->data;
+			WRITE_ONCE(so->cfecho, skb->hash);
 		} else {
 			/* standard flow control check */
 			new_state = ISOTP_WAIT_FIRST_FC;
@@ -1190,12 +1288,12 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
 			tx_hrt = &so->txtimer;
 
 			/* no CF echo tag for isotp_rcv_echo() (FF-mode) */
-			so->cfecho = 0;
+			WRITE_ONCE(so->cfecho, 0);
 		}
 	}
 
 	spin_lock_bh(&so->rx_lock);
-	if (so->tx.state == ISOTP_SHUTDOWN) {
+	if (READ_ONCE(so->tx.state) == ISOTP_SHUTDOWN) {
 		/* isotp_release() has since taken over and already drained
 		 * our timers - don't send into a socket that's going away
 		 */
@@ -1206,7 +1304,7 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
 		return -EADDRNOTAVAIL;
 	}
 	/* WAIT_FIRST_FC for standard FF, else stays ISOTP_SENDING */
-	so->tx.state = new_state;
+	WRITE_ONCE(so->tx.state, new_state);
 	hrtimer_start(tx_hrt, ktime_set(hrtimer_sec, 0),
 		      HRTIMER_MODE_REL_SOFT);
 	spin_unlock_bh(&so->rx_lock);
@@ -1223,20 +1321,49 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
 			       __func__, ERR_PTR(err));
 
 		spin_lock_bh(&so->rx_lock);
+
+		/* new transfer already claimed by a concurrent completion,
+		 * timeout or sendmsg() while we were stuck in can_send()?
+		 */
+		if (READ_ONCE(so->tx_gen) != my_gen) {
+			/* don't touch timers and state of the new transfer */
+			spin_unlock_bh(&so->rx_lock);
+			return err;
+		}
+
 		/* no transmission -> no timeout monitoring */
 		hrtimer_cancel(tx_hrt);
 		goto err_out_drop_locked;
 	}
 
 	if (wait_tx_done) {
-		/* wait for complete transmission of current pdu */
-		err = wait_event_interruptible(so->wait, so->tx.state == ISOTP_IDLE);
+		/* wake up for:
+		 * - concurrent sendmsg() claiming a new transfer
+		 * - complete transmission of current PDU
+		 * - shutdown state change in isotp_release()
+		 * isotp_tx_gen_done() uses common tx.state/tx_gen read sequence
+		 */
+		err = wait_event_interruptible(so->wait,
+					       isotp_tx_gen_done(so, my_gen));
 		if (err)
 			goto err_event_drop;
 
-		err = sock_error(sk);
-		if (err)
-			return err;
+		/* still our claim, but isotp_release() force-shut it down */
+		if (smp_load_acquire(&so->tx.state) == ISOTP_SHUTDOWN &&
+		    READ_ONCE(so->tx_gen) == my_gen) {
+			err = -EADDRNOTAVAIL;
+			goto err_event_drop;
+		}
+
+		/* own completion, or tx_gen moved on - either way this is
+		 * what isotp_get_tx_result() recorded for my_gen
+		 */
+		err = isotp_get_tx_result(so, my_gen);
+
+		/* drain to avoid stale error for a later poll()/SO_ERROR */
+		sock_error(sk);
+
+		return err ? err : size;
 	}
 
 	return size;
@@ -1246,15 +1373,26 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
 	spin_lock_bh(&so->rx_lock);
 	goto err_out_drop_locked;
 err_event_drop:
-	/* interrupted waiting on our own transfer - drain its timers */
+	/* interrupted or shut down while waiting on our own transfer */
 	spin_lock_bh(&so->rx_lock);
+
+	/* new transfer already started by concurrent sendmsg()? */
+	if (READ_ONCE(so->tx_gen) != my_gen) {
+		/* don't touch timers and states of the new transfer */
+		spin_unlock_bh(&so->rx_lock);
+		return err;
+	}
+
 	hrtimer_cancel(&so->txfrtimer);
 	hrtimer_cancel(&so->txtimer);
 	hrtimer_cancel(&so->echotimer);
 err_out_drop_locked:
 	/* release the claim; so->rx_lock still held from above */
-	so->cfecho = 0;
-	so->tx.state = ISOTP_IDLE;
+	WRITE_ONCE(so->cfecho, 0);
+
+	/* only claim to IDLE if isotp_release() has not taken over */
+	if (READ_ONCE(so->tx.state) != ISOTP_SHUTDOWN)
+		WRITE_ONCE(so->tx.state, ISOTP_IDLE);
 	spin_unlock_bh(&so->rx_lock);
 	wake_up_interruptible(&so->wait);
 
@@ -1320,8 +1458,9 @@ static int isotp_release(struct socket *sock)
 	/* best-effort: wait for a running pdu to finish, but don't block on
 	 * it forever - give up after the first signal
 	 */
-	while (so->tx.state != ISOTP_IDLE &&
-	       wait_event_interruptible(so->wait, so->tx.state == ISOTP_IDLE) == 0)
+	while (READ_ONCE(so->tx.state) != ISOTP_IDLE &&
+	       wait_event_interruptible(so->wait,
+					READ_ONCE(so->tx.state) == ISOTP_IDLE) == 0)
 		;
 
 	/* claim the socket under so->rx_lock like sendmsg() does, so its
@@ -1329,9 +1468,12 @@ static int isotp_release(struct socket *sock)
 	 * unconditionally, even when a signal cut the wait above short
 	 */
 	spin_lock_bh(&so->rx_lock);
-	so->tx.state = ISOTP_SHUTDOWN;
+	WRITE_ONCE(so->tx.state, ISOTP_SHUTDOWN);
 	spin_unlock_bh(&so->rx_lock);
-	so->rx.state = ISOTP_IDLE;
+	WRITE_ONCE(so->rx.state, ISOTP_IDLE);
+
+	/* forced SHUTDOWN may have skipped IDLE (gave up on a signal) */
+	wake_up_interruptible(&so->wait);
 
 	spin_lock(&isotp_notifier_lock);
 	while (isotp_busy_notifier == so) {
@@ -1447,7 +1589,8 @@ static int isotp_bind(struct socket *sock, struct sockaddr_unsized *uaddr, int l
 	 * with so->bound in the same lock_sock() section above, so there is
 	 * no window in which a concurrent isotp_notify() could be missed.
 	 */
-	if (so->tx.state != ISOTP_IDLE || so->rx.state != ISOTP_IDLE) {
+	if (READ_ONCE(so->tx.state) != ISOTP_IDLE ||
+	    READ_ONCE(so->rx.state) != ISOTP_IDLE) {
 		err = -EAGAIN;
 		goto out;
 	}
@@ -1481,7 +1624,7 @@ static int isotp_bind(struct socket *sock, struct sockaddr_unsized *uaddr, int l
 				isotp_rcv, sk, "isotp", sk);
 
 	/* no consecutive frame echo skb in flight */
-	so->cfecho = 0;
+	WRITE_ONCE(so->cfecho, 0);
 
 	/* register for echo skb's */
 	can_rx_register(net, dev, tx_id, SINGLE_MASK(tx_id),
@@ -1847,7 +1990,7 @@ static __poll_t isotp_poll(struct file *file, struct socket *sock, poll_table *w
 	poll_wait(file, &so->wait, wait);
 
 	/* Check for false positives due to TX state */
-	if ((mask & EPOLLWRNORM) && (so->tx.state != ISOTP_IDLE))
+	if ((mask & EPOLLWRNORM) && (READ_ONCE(so->tx.state) != ISOTP_IDLE))
 		mask &= ~(EPOLLOUT | EPOLLWRNORM);
 
 	return mask;
@@ -1907,13 +2050,18 @@ static __init int isotp_module_init(void)
 
 	pr_info("can: isotp protocol (max_pdu_size %d)\n", max_pdu_size);
 
+	err = register_netdevice_notifier(&canisotp_notifier);
+	if (err)
+		return err;
+
 	err = can_proto_register(&isotp_can_proto);
-	if (err < 0)
+	if (err < 0) {
 		pr_err("can: registration of isotp protocol failed %pe\n", ERR_PTR(err));
-	else
-		register_netdevice_notifier(&canisotp_notifier);
+		unregister_netdevice_notifier(&canisotp_notifier);
+		return err;
+	}
 
-	return err;
+	return 0;
 }
 
 static __exit void isotp_module_exit(void)
diff --git a/net/can/j1939/bus.c b/net/can/j1939/bus.c
index dc374286eeb6e..cdc3c0a719379 100644
--- a/net/can/j1939/bus.c
+++ b/net/can/j1939/bus.c
@@ -20,6 +20,7 @@ static void __j1939_ecu_release(struct kref *kref)
 	struct j1939_priv *priv = ecu->priv;
 
 	list_del(&ecu->list);
+	netdev_put(priv->ndev, &ecu->priv_dev_tracker);
 	kfree(ecu);
 	j1939_priv_put(priv);
 }
@@ -155,6 +156,7 @@ struct j1939_ecu *j1939_ecu_create_locked(struct j1939_priv *priv, name_t name)
 	if (!ecu)
 		return ERR_PTR(-ENOMEM);
 	kref_init(&ecu->kref);
+	netdev_hold(priv->ndev, &ecu->priv_dev_tracker, gfp_any());
 	ecu->addr = J1939_IDLE_ADDR;
 	ecu->name = name;
 
diff --git a/net/can/j1939/j1939-priv.h b/net/can/j1939/j1939-priv.h
index 81f58924b4acd..cf26352d1d8ce 100644
--- a/net/can/j1939/j1939-priv.h
+++ b/net/can/j1939/j1939-priv.h
@@ -38,6 +38,7 @@ struct j1939_ecu {
 	struct hrtimer ac_timer;
 	struct kref kref;
 	struct j1939_priv *priv;
+	netdevice_tracker priv_dev_tracker;
 
 	/* count users, to help transport protocol decide for interaction */
 	int nusers;
@@ -60,6 +61,7 @@ struct j1939_priv {
 	rwlock_t lock;
 
 	struct net_device *ndev;
+	netdevice_tracker dev_tracker;
 
 	/* list of 256 ecu ptrs, that cache the claimed addresses.
 	 * also protected by the above lock
@@ -230,6 +232,7 @@ enum j1939_session_state {
 
 struct j1939_session {
 	struct j1939_priv *priv;
+	netdevice_tracker priv_dev_tracker;
 	struct list_head active_session_list_entry;
 	struct list_head sk_session_queue_entry;
 	struct kref kref;
diff --git a/net/can/j1939/main.c b/net/can/j1939/main.c
index 9937c04241bc3..5e5e6c228f225 100644
--- a/net/can/j1939/main.c
+++ b/net/can/j1939/main.c
@@ -137,7 +137,7 @@ static struct j1939_priv *j1939_priv_create(struct net_device *ndev)
 	priv->ndev = ndev;
 	kref_init(&priv->kref);
 	kref_init(&priv->rx_kref);
-	dev_hold(ndev);
+	netdev_hold(ndev, &priv->dev_tracker, GFP_KERNEL);
 
 	netdev_dbg(priv->ndev, "%s : 0x%p\n", __func__, priv);
 
@@ -163,7 +163,7 @@ static void __j1939_priv_release(struct kref *kref)
 	WARN_ON_ONCE(!list_empty(&priv->ecus));
 	WARN_ON_ONCE(!list_empty(&priv->j1939_socks));
 
-	dev_put(ndev);
+	netdev_put(ndev, &priv->dev_tracker);
 	kfree(priv);
 }
 
@@ -281,7 +281,7 @@ struct j1939_priv *j1939_netdev_start(struct net_device *ndev)
 		 */
 		kref_get(&priv_new->rx_kref);
 		mutex_unlock(&j1939_netdev_lock);
-		dev_put(ndev);
+		netdev_put(ndev, &priv->dev_tracker);
 		kfree(priv);
 		return priv_new;
 	}
@@ -298,7 +298,7 @@ struct j1939_priv *j1939_netdev_start(struct net_device *ndev)
 	j1939_priv_set(ndev, NULL);
 	mutex_unlock(&j1939_netdev_lock);
 
-	dev_put(ndev);
+	netdev_put(ndev, &priv->dev_tracker);
 	kfree(priv);
 
 	return ERR_PTR(ret);
diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c
index 8a31cb23bc76d..8fcfd13e5e6f8 100644
--- a/net/can/j1939/transport.c
+++ b/net/can/j1939/transport.c
@@ -283,6 +283,7 @@ static void j1939_session_destroy(struct j1939_session *session)
 		kfree_skb(skb);
 	}
 	__j1939_session_drop(session);
+	netdev_put(session->priv->ndev, &session->priv_dev_tracker);
 	j1939_priv_put(session->priv);
 	kfree(session);
 }
@@ -1526,6 +1527,7 @@ static struct j1939_session *j1939_session_new(struct j1939_priv *priv,
 	INIT_LIST_HEAD(&session->active_session_list_entry);
 	INIT_LIST_HEAD(&session->sk_session_queue_entry);
 	kref_init(&session->kref);
+	netdev_hold(priv->ndev, &session->priv_dev_tracker, gfp_any());
 
 	j1939_priv_get(priv);
 	session->priv = priv;
@@ -1579,7 +1581,7 @@ j1939_session *j1939_session_fresh_new(struct j1939_priv *priv,
 	}
 
 	/* alloc data area */
-	skb_put(skb, size);
+	skb_put_zero(skb, size);
 	/* skb is recounted in j1939_session_new() */
 	return session;
 }

3/2 2026/07/30 16:20 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 22951
							output: 19
							thoughts: 874
						

Thoughts:
**Analyzing the Proposed CAN Driver and Protocol Patch Series**

Okay, so I've been presented with a patch series that touches a good chunk of the CAN stack, including various drivers and the ISOTP and J1939 protocols. The question is, does this warrant fuzzing, and, if so, where should I focus my efforts?

Let's dissect this. Firstly, I'll go through the driver-specific changes. Most of these seem to be cleanups, bug fixes, and minor adjustments. Adding bounds checking, fixing unmap arguments, and handling errors in interrupt routines are important for robust drivers, but don't necessarily scream "new fuzzing surface." I need to consider functional changes that could be reached via fuzzing. For instance:

*   The `c_can_main.c` change, while a minor addition, should be analyzed.
*   The `ctucanfd` driver changes, specifically those in `ctucanfd_base.c`, adding error codes and interrupt handling, could be interesting depending on how that hardware behaves under stress.
*   The USB CAN driver modifications are more interesting, especially those related to length validation and memory management. Any USB-connected CAN drivers are potential targets for `dummy_hcd/raw-gadget` fuzzing with Syzkaller, which I should definitely explore. I need to note the ems_usb, gs_usb, kvaser_usb, and peak_usb drivers in particular.

Now, onto the big ones: ISOTP and J1939. The `net/can/isotp.c` rewrite is the standout here. A major state machine rewrite and error handling overhaul means potentially significant changes to the protocol's behavior. This is absolutely functional and definitely fuzzable. Similarly, the changes in the `net/can/j1939/` directory with `netdevice_tracker` for `ndev` references also involve new functional logic.

So, fuzzing ISOTP is a high priority. I need to identify the entry points here. I know that ISOTP is socket-based, so I'll be looking for socket operations. I need to make a note of: `isotp_bind`, `isotp_sendmsg`, `isotp_rcv`, `isotp_rcv_echo`, `isotp_tx_timeout`, `isotp_txfr_timer_handler`, `isotp_release`, and `isotp_poll`. These are the functions I'll be targetting with socket fuzzing.

Before I jump into fuzzing I need to confirm that ISOTP is enabled in the kernel config. Is it a module, or built-in? I'll check `net/can/Kconfig` or `net/can/isotp/Kconfig`. I'll run a quick search for "ISOTP" within the Kconfig files. Then I can proceed.



4/2 2026/07/30 16:21 tool grepper
0m Args:
{
  "Expression": "config CAN_ISOTP"
}

Results:
{
  "Output": "net/can/Kconfig=57=source \"net/can/j1939/Kconfig\"\nnet/can/Kconfig-58-\nnet/can/Kconfig:59:config CAN_ISOTP\nnet/can/Kconfig-60-\ttristate \"ISO 15765-2 CAN transport protocol\"\n"
}

5/2 2026/07/30 16:21 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 24553
							output: 22
							thoughts: 20
						

Thoughts:
Okay, here's my interpretation of those thoughts, tailored for an expert audience, presented in the first person:

**CAN Configuration Considerations**

Alright, let me get this straight in my head. We're dealing with the CAN bus, and specifically the initial configuration hinges around `CAN_ISOTP`. That's the baseline, the fundamental setting. But, and this is the crux of the matter, we can't stop there. What about J1939? The application has to communicate, and that's the obvious next consideration. The broader standard. What's required there? I'm already thinking about the implementation details.



6/2 2026/07/30 16:21 tool grepper
0m Args:
{
  "Expression": "config CAN_J1939"
}

Results:
{
  "Output": "net/can/j1939/Kconfig-5-\nnet/can/j1939/Kconfig:6:config CAN_J1939\nnet/can/j1939/Kconfig-7-\ttristate \"SAE J1939\"\n"
}

7/2 2026/07/30 16:21 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 24811
							output: 20
							thoughts: 38
						

Thoughts:
Okay, here's my interpretation of those thoughts, framed as a first-person expert summary:

**Considering USB CAN Driver Options**

Alright, let's see, I'm working on a project that involves CAN communication, and I'm currently thinking about the hardware interface.  The focus here is definitely on USB-based solutions. I need to make a quick inventory of the popular USB CAN driver options that are out there. I'm immediately thinking of a few of the more common ones that I typically encounter: `CAN_EMS_USB`, `CAN_GS_USB`, `CAN_KVASER_USB`, and `CAN_PEAK_USB`. Just running through those names, I'm already recalling their general capabilities, their respective API quirks, and what they're generally known for in terms of performance and supported CAN protocols. I have a feeling I'll be comparing features, cost, and availability soon enough. This quick run through gives me a good starting point for a deeper dive. Now I can move on to the next set of thoughts...



8/2 2026/07/30 16:21 tool grepper
0m Args:
{
  "Expression": "config CAN_EMS_USB"
}

Results:
{
  "Output": "drivers/net/can/usb/Kconfig=5=config CAN_8DEV_USB\n--\ndrivers/net/can/usb/Kconfig-10-\ndrivers/net/can/usb/Kconfig:11:config CAN_EMS_USB\ndrivers/net/can/usb/Kconfig-12-\ttristate \"EMS CPC-USB/ARM7 CAN/USB interface\"\n"
}

9/2 2026/07/30 16:21 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 25194
							output: 20
							thoughts: 27
						

Thoughts:
Here's the summary, assuming I'm an expert and this is part of a larger technical process:

**USB CAN Interface Verification**

Okay, time to make sure our CAN interface options are working correctly. My immediate thought is to systematically verify the key USB CAN interface configurations. I need to confirm the functionality of `CAN_GS_USB`, `CAN_KVASER_USB`, and `CAN_PEAK_USB`. This will give me a clear picture of what's supported and working. I'll need to check the drivers, the communication protocols, the initialization process, and the ability to send and receive data with each of these. No point in continuing until I know these are behaving as expected.



10/2 2026/07/30 16:21 tool grepper
0m Args:
{
  "Expression": "config CAN_GS_USB"
}

Results:
{
  "Output": "drivers/net/can/usb/Kconfig=42=config CAN_F81604\n--\ndrivers/net/can/usb/Kconfig-53-\ndrivers/net/can/usb/Kconfig:54:config CAN_GS_USB\ndrivers/net/can/usb/Kconfig-55-\ttristate \"Geschwister Schneider UG and candleLight compatible interfaces\"\n"
}

11/2 2026/07/30 16:21 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 25494
							output: 21
							thoughts: 12
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience, and delivered as a first-person summary:

**Preliminary Check: KVASER USB Configuration**

Right, let's just make absolutely sure we're starting on the right foot. Before diving into the nitty-gritty, a quick sanity check is always wise. The immediate thought is to confirm the `CAN_KVASER_USB` configuration is precisely as expected. I need to verify that the fundamental communication pathway via the Kvaser USB interface is correctly defined and enabled. This is crucial; a misconfiguration here would send us down a rabbit hole of debugging that has nothing to do with the core problem. So, before even considering deeper diagnostics, I’ll take a moment to confirm that the connection to the physical hardware is established, configured properly and recognized. That will ensure that any issues found are a result of our code and not a simple setup problem.



12/2 2026/07/30 16:21 tool grepper
0m Args:
{
  "Expression": "config CAN_KVASER_USB"
}

Results:
{
  "Output": "drivers/net/can/usb/Kconfig=54=config CAN_GS_USB\n--\ndrivers/net/can/usb/Kconfig-66-\ndrivers/net/can/usb/Kconfig:67:config CAN_KVASER_USB\ndrivers/net/can/usb/Kconfig-68-\ttristate \"Kvaser CAN/USB interface\"\n"
}

13/2 2026/07/30 16:21 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 25823
							output: 21
							thoughts: 12
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Checking the CAN_PEAK_USB Integration**

Alright, let's zero in on this `CAN_PEAK_USB` integration. My initial thought process revolves around confirming its status and functionality. I'm immediately running through a mental checklist: What's the current state of this specific hardware or software element? Has it been properly initialized? Are there any reported errors or warnings associated with it in recent logs? Is it communicating as expected with the CAN bus? I need to be sure the fundamental interaction between the CAN interface and the rest of the system is intact. The reliability of `CAN_PEAK_USB` is critical for data acquisition, control, or whatever the primary application is. I want to check for any obvious red flags, such as driver issues, connection problems, or configuration errors that could impact overall performance or even lead to data corruption. I am going to see it is operational before continuing with any other tests.



14/2 2026/07/30 16:21 tool grepper
0m Args:
{
  "Expression": "config CAN_PEAK_USB"
}

Results:
{
  "Output": "drivers/net/can/usb/Kconfig=137=config CAN_NCT6694\n--\ndrivers/net/can/usb/Kconfig-147-\ndrivers/net/can/usb/Kconfig:148:config CAN_PEAK_USB\ndrivers/net/can/usb/Kconfig-149-\ttristate \"PEAK PCAN-USB/USB Pro interfaces for CAN 2.0b/CAN-FD\"\n"
}

15/2 2026/07/30 16:21 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 26188
							output: 19
							thoughts: 10
						

Thoughts:
Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:

**Initial Checkpoint: CAN_SOFTING**

Alright, the first thing that jumps to mind is a quick verification of `CAN_SOFTING`. My experience tells me that this is likely a critical control or flag within the system. Before diving into anything else, I need to confirm its current state and configuration. Is it enabled? Disabled? What are the implications of its setting on the subsequent execution flow? I'm thinking, this could be a pre-flight check, a security measure, or something related to resource allocation. I need to know where we stand with it. It's the logical starting point before digging deeper. Let's see.



16/2 2026/07/30 16:21 tool grepper
0m Args:
{
  "Expression": "config CAN_SOFTING"
}

Results:
{
  "Output": "drivers/net/can/softing/Kconfig-1-# SPDX-License-Identifier: GPL-2.0-only\ndrivers/net/can/softing/Kconfig:2:config CAN_SOFTING\ndrivers/net/can/softing/Kconfig-3-\ttristate \"Softing Gmbh CAN generic support\"\n--\ndrivers/net/can/softing/Kconfig-18-\ndrivers/net/can/softing/Kconfig:19:config CAN_SOFTING_CS\ndrivers/net/can/softing/Kconfig-20-\ttristate \"Softing Gmbh CAN pcmcia cards\"\n"
}

17/2 2026/07/30 16:21 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 26538
							output: 23
							thoughts: 14
						

Thoughts:
Okay, here's my interpretation of that thought process, assuming I'm an expert in this field, rendered in the first person:

**Quick Check: PCI Configuration**

Alright, time to get to it. My initial thought is to immediately zoom in on the `CAN_CTUCANFD_PCI` setup. This likely points to a critical component related to my work, and it's something I need to understand completely and rapidly. My brain is already starting to pull up the mental schematic, running through the possibilities this identifier could be referencing: Is this a configuration parameter? A module name? A piece of hardware? Either way, I'm already mentally cross-referencing this with my knowledge of relevant CAN controllers, PCI bus interfaces, and the overall system architecture. It's a key piece of the puzzle, and I need to dive in!



18/2 2026/07/30 16:21 tool grepper
0m Args:
{
  "Expression": "config CAN_CTUCANFD_PCI"
}

Results:
{
  "Output": "drivers/net/can/ctucanfd/Kconfig=1=config CAN_CTUCANFD\n--\ndrivers/net/can/ctucanfd/Kconfig-13-\ndrivers/net/can/ctucanfd/Kconfig:14:config CAN_CTUCANFD_PCI\ndrivers/net/can/ctucanfd/Kconfig-15-\ttristate \"CTU CAN-FD IP core PCI/PCIe driver\"\n"
}

19/2 2026/07/30 16:21 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 26872
							output: 19
							thoughts: 292
						

Thoughts:
**Analyzing the Isotp.c Patch**

Okay, so this patch is clearly making some significant changes within `net/can/isotp.c`. My initial focus needs to be on these specific functions: `isotp_bind`, `isotp_sendmsg`, `isotp_rcv`, `isotp_rcv_echo`, `isotp_tx_timeout`, `isotp_txfr_timer_handler`, `isotp_release`, and `isotp_poll`. I need to understand exactly what modifications have been applied to them and, importantly, how they interact within the larger CAN framework.

A quick check for static declarations is essential here. Alright, `isotp_bind`, `isotp_sendmsg`, `isotp_release`, and `isotp_poll` are indeed static, but since they're part of `proto_ops` they're not inlined. That's good; it means I can trace their usage more directly. `isotp_rcv` and `isotp_rcv_echo` are also static, registered through `can_rx_register`, so I'll need to remember that. `isotp_tx_timeout` and `isotp_txfr_timer_handler` are static as well. This makes sense from a scoping perspective within the module, but I want to be certain about the inlining implications.

Wait, with these static functions, if they were inlined, I might not be able to directly call them by name. However, since the functions `isotp_bind`, `isotp_sendmsg`, `isotp_release`, and `isotp_poll` are passed as function pointers, they're definitely not inlined. That simplifies things, but I still need to be sure. I'll need to go back and examine `net/can/isotp.c` directly to confirm my assumptions and get a more complete picture of how these changes fit together. This static declaration might be misleading, I need more context.



20/2 2026/07/30 16:21 tool grepper
0m Args:
{
  "Expression": "isotp_sendmsg"
}

Results:
{
  "Output": "net/can/isotp.c=1088=static enum hrtimer_restart isotp_txfr_timer_handler(struct hrtimer *hrtimer)\n--\nnet/can/isotp.c-1103-\nnet/can/isotp.c:1104:static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)\nnet/can/isotp.c-1105-{\n--\nnet/can/isotp.c=2006=static const struct proto_ops isotp_ops = {\n--\nnet/can/isotp.c-2020-\t.getsockopt = isotp_getsockopt,\nnet/can/isotp.c:2021:\t.sendmsg = isotp_sendmsg,\nnet/can/isotp.c-2022-\t.recvmsg = isotp_recvmsg,\n"
}

21/2 2026/07/30 16:22 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 27844
							output: 24
							thoughts: 186
						

Thoughts:
**Analyzing the Function Pointers**

Okay, so the functions are static, but they're being utilized as function pointers. That's good to keep in mind for context. Let's make a list of the specific functions we need to focus on for this analysis. They are:

*   `isotp_sendmsg`
*   `isotp_rcv`
*   `isotp_rcv_echo`
*   `isotp_release`
*   `isotp_bind`
*   `isotp_poll`
*   `j1939_session_new`
*   `j1939_session_destroy`
*   `pcan_usb_fd_decode_buf`
*   `kvaser_usb_leaf_read_bulk_callback`
*   `ems_usb_read_bulk_callback`
*   `gs_usb_receive_bulk_callback`

To start, let's dive into `pcan_usb_fd_decode_buf` to get a better understanding. I'll need to check the file `drivers/net/can/usb/peak_usb/pcan_usb_fd.c` for this function.



22/2 2026/07/30 16:22 tool grepper
0m Args:
{
  "Expression": "pcan_usb_fd_decode_buf"
}

Results:
{
  "Output": "drivers/net/can/usb/peak_usb/pcan_usb_fd.c=724=static size_t pcan_usb_fd_rx_msg_min_size(u16 rx_msg_type)\n--\ndrivers/net/can/usb/peak_usb/pcan_usb_fd.c-742-/* callback for bulk IN urb */\ndrivers/net/can/usb/peak_usb/pcan_usb_fd.c:743:static int pcan_usb_fd_decode_buf(struct peak_usb_device *dev, struct urb *urb)\ndrivers/net/can/usb/peak_usb/pcan_usb_fd.c-744-{\n--\ndrivers/net/can/usb/peak_usb/pcan_usb_fd.c=1197=const struct peak_usb_adapter pcan_usb_fd = {\n--\ndrivers/net/can/usb/peak_usb/pcan_usb_fd.c-1238-\t.dev_set_can_channel_id = pcan_usb_fd_set_can_channel_id,\ndrivers/net/can/usb/peak_usb/pcan_usb_fd.c:1239:\t.dev_decode_buf = pcan_usb_fd_decode_buf,\ndrivers/net/can/usb/peak_usb/pcan_usb_fd.c-1240-\t.dev_start = pcan_usb_fd_start,\n--\ndrivers/net/can/usb/peak_usb/pcan_usb_fd.c=1273=const struct peak_usb_adapter pcan_usb_chip = {\n--\ndrivers/net/can/usb/peak_usb/pcan_usb_fd.c-1314-\t.dev_set_can_channel_id = pcan_usb_fd_set_can_channel_id,\ndrivers/net/can/usb/peak_usb/pcan_usb_fd.c:1315:\t.dev_decode_buf = pcan_usb_fd_decode_buf,\ndrivers/net/can/usb/peak_usb/pcan_usb_fd.c-1316-\t.dev_start = pcan_usb_fd_start,\n--\ndrivers/net/can/usb/peak_usb/pcan_usb_fd.c=1349=const struct peak_usb_adapter pcan_usb_pro_fd = {\n--\ndrivers/net/can/usb/peak_usb/pcan_usb_fd.c-1390-\t.dev_set_can_channel_id = pcan_usb_fd_set_can_channel_id,\ndrivers/net/can/usb/peak_usb/pcan_usb_fd.c:1391:\t.dev_decode_buf = pcan_usb_fd_decode_buf,\ndrivers/net/can/usb/peak_usb/pcan_usb_fd.c-1392-\t.dev_start = pcan_usb_fd_start,\n--\ndrivers/net/can/usb/peak_usb/pcan_usb_fd.c=1425=const struct peak_usb_adapter pcan_usb_x6 = {\n--\ndrivers/net/can/usb/peak_usb/pcan_usb_fd.c-1466-\t.dev_set_can_channel_id = pcan_usb_fd_set_can_channel_id,\ndrivers/net/can/usb/peak_usb/pcan_usb_fd.c:1467:\t.dev_decode_buf = pcan_usb_fd_decode_buf,\ndrivers/net/can/usb/peak_usb/pcan_usb_fd.c-1468-\t.dev_start = pcan_usb_fd_start,\n"
}

23/2 2026/07/30 16:22 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 29258
							output: 27
							thoughts: 19
						

Thoughts:
Okay, let's dive into this. Here's my understanding, presented as my own mental processing, focusing on how I'd approach this as an expert:

**Investigating `kvaser_usb_leaf_read_bulk_callback`**

Right, let's zero in on `kvaser_usb_leaf_read_bulk_callback`. I immediately see this as a key function in handling data coming from a Kvaser USB Leaf device, likely in a bulk transfer context. Given my experience, I'm already anticipating certain aspects:

*   **Callback Context:** This is a callback function, meaning it's likely triggered asynchronously in response to an event, almost certainly related to the completion of a bulk transfer initiated earlier. I need to understand what triggers this specifically. Is it a successful read? An error? The completion of a timeout?
*   **Bulk Transfer Implication:** The "bulk" suggests that the data transfer isn't critical real-time data but more of a buffered, potentially large amount of data. This impacts how I think about buffering, data integrity checks, and error handling. I need to consider potential for data loss and ensure my implementation addresses it effectively.
*   **Function's Purpose:** My immediate question is: what is the primary role of this callback? Is it responsible for processing the raw data received, parsing it, validating it, making it available to the rest of the application, or a combination of these things? Is this function also responsible for re-queuing another read? Or does a separate thread do that?
*   **Potential Bottlenecks:** I have to watch out for potential bottlenecks. If the data processing within this callback is slow, it could block the USB transfer, leading to data overrun. I'll need to consider performance implications like the amount of data processed per call, whether it needs to do deep copies, and other performance impacts. I'd watch out for how much time is spent on this to be sure it does not become a bottleneck.
*   **Error Handling and Safety:** Critically, I have to assume the worst. I need to immediately understand what error conditions this callback gracefully handles. USB communication is notorious for intermittent errors. Are there retries? Timeout mechanisms? How are errors signaled to the application? This will likely be key to stability.
*   **Data Structure Assumptions:** I need to figure out the expected data format. Does this callback deal with raw byte streams, or are there assumed headers/footers or specific message structures? Understanding this format is fundamental to correctly interpreting and acting on the data.
*   **Multi-threaded Considerations:** If this is a multi-threaded application (which is highly likely in a USB context), this callback might be running in a separate thread. This means I'll need to pay close attention to any shared data, mutexes, and thread safety mechanisms used to prevent race conditions. Is this callback thread-safe? Or is there some external thread safety protocol?
*   **Documentation and Design:** I'd immediately look for relevant documentation. Does it outline the expected data structures, error codes, and the function's intended behavior? Also, I need to understand the larger system design – how this callback fits into the overall data flow. How is the initial read request initiated?

Basically, my expert perspective is to anticipate the core problems, and mentally "test" the code against those conditions, to make sure this critical path functions properly, and that it addresses corner cases.



24/2 2026/07/30 16:22 tool grepper
0m Args:
{
  "Expression": "kvaser_usb_leaf_read_bulk_callback"
}

Results:
{
  "Output": "drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c=1720=warn:\t\tdev_warn(\u0026dev-\u003eintf-\u003edev, \"Unhandled command (%d)\\n\", cmd-\u003eid);\n--\ndrivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c-1724-\ndrivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c:1725:static void kvaser_usb_leaf_read_bulk_callback(struct kvaser_usb *dev,\ndrivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c-1726-\t\t\t\t\t       void *buf, int len)\n--\ndrivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c=1983=const struct kvaser_usb_dev_ops kvaser_usb_leaf_dev_ops = {\n--\ndrivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c-2003-\t.dev_flush_queue = kvaser_usb_leaf_flush_queue,\ndrivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c:2004:\t.dev_read_bulk_callback = kvaser_usb_leaf_read_bulk_callback,\ndrivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c-2005-\t.dev_frame_to_cmd = kvaser_usb_leaf_frame_to_cmd,\n"
}

25/2 2026/07/30 16:22 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 30440
							output: 23
							thoughts: 15
						

Thoughts:
Okay, let's dive into this. Here's my take on those thoughts, as if they're my own:

**Analyzing the `ems_usb_read_bulk_callback`**

Right, so we're looking at `ems_usb_read_bulk_callback`. My initial thought is to zero in on this function because it’s the callback for bulk reads on the USB side, and with my expertise, I know this is a critical spot. This is where we'll be handling the data we're receiving and likely interacting with buffering or other crucial processes. Understanding its operation is fundamental to how this whole system works. Let's see how it’s implemented and where it's being used within the larger context, so I can start forming a clear picture of how it all ties together.



26/2 2026/07/30 16:22 tool grepper
0m Args:
{
  "Expression": "ems_usb_read_bulk_callback"
}

Results:
{
  "Output": "drivers/net/can/usb/ems_usb.c=412=static bool ems_usb_rx_msg_len_valid(struct ems_cpc_msg *msg)\n--\ndrivers/net/can/usb/ems_usb.c-448- */\ndrivers/net/can/usb/ems_usb.c:449:static void ems_usb_read_bulk_callback(struct urb *urb)\ndrivers/net/can/usb/ems_usb.c-450-{\n--\ndrivers/net/can/usb/ems_usb.c-534-\t\t\t  urb-\u003etransfer_buffer, RX_BUFFER_SIZE,\ndrivers/net/can/usb/ems_usb.c:535:\t\t\t  ems_usb_read_bulk_callback, dev);\ndrivers/net/can/usb/ems_usb.c-536-\n--\ndrivers/net/can/usb/ems_usb.c=641=static int ems_usb_start(struct ems_usb *dev)\n--\ndrivers/net/can/usb/ems_usb.c-673-\t\t\t\t  buf, RX_BUFFER_SIZE,\ndrivers/net/can/usb/ems_usb.c:674:\t\t\t\t  ems_usb_read_bulk_callback, dev);\ndrivers/net/can/usb/ems_usb.c-675-\t\turb-\u003etransfer_flags |= URB_NO_TRANSFER_DMA_MAP;\n"
}

27/2 2026/07/30 16:22 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 31011
							output: 23
							thoughts: 15
						

Thoughts:
Okay, let's dive into this. Here's my thought process on dissecting the `gs_usb_receive_bulk_callback`:

**Dissecting the `gs_usb_receive_bulk_callback`**

Right, so I need to understand this callback function. It's obviously critical for receiving data from the USB bus, specifically in a bulk transfer context, which is common for CAN interfaces. My initial thought is to identify its role in the data flow. Is it the end-point of data reception? Does it process, store, or forward data to another part of the system? I'm expecting it probably handles the data received from the USB device, meaning it is where the USB data meets the CAN data. I need to figure out the hand-off. The immediate questions I'm asking myself are about its parameters. What are the inputs, and what do they represent? Likely it will receive a pointer to a buffer, the data length, and perhaps a descriptor for context. Then, I need to check the data content, and whether it has to manage errors and retries. Is the function responsible for reassembly if the message is fragmented? I'll probably start by looking at the data structures it uses, particularly any CAN-specific structures or packet formats involved. Is there a "done" signal, so it can inform the driver/other part that the process is finished? I'll have to see how it manages potential race conditions or concurrency issues – are there locks, mutexes, or other synchronization primitives involved? Ultimately, the goal is to understand how efficiently and reliably the driver translates USB data into CAN frames and vice versa. Let's dig in and see exactly how it's implemented.



28/2 2026/07/30 16:22 tool grepper
0m Args:
{
  "Expression": "gs_usb_receive_bulk_callback"
}

Results:
{
  "Output": "drivers/net/can/usb/gs_usb.c=579=gs_usb_get_minimum_rx_length(const struct gs_can *dev, const struct gs_host_frame *hf,\n--\ndrivers/net/can/usb/gs_usb.c-608-\ndrivers/net/can/usb/gs_usb.c:609:static void gs_usb_receive_bulk_callback(struct urb *urb)\ndrivers/net/can/usb/gs_usb.c-610-{\n--\ndrivers/net/can/usb/gs_usb.c-751-\t\t\t  hf, parent-\u003ehf_size_rx,\ndrivers/net/can/usb/gs_usb.c:752:\t\t\t  gs_usb_receive_bulk_callback, parent);\ndrivers/net/can/usb/gs_usb.c-753-\n--\ndrivers/net/can/usb/gs_usb.c=951=static int gs_can_open(struct net_device *netdev)\n--\ndrivers/net/can/usb/gs_usb.c-1010-\t\t\t\t\t  dev-\u003eparent-\u003ehf_size_rx,\ndrivers/net/can/usb/gs_usb.c:1011:\t\t\t\t\t  gs_usb_receive_bulk_callback, parent);\ndrivers/net/can/usb/gs_usb.c-1012-\t\t\turb-\u003etransfer_flags |= URB_FREE_BUFFER;\n"
}

29/2 2026/07/30 16:22 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 31767
							output: 22
							thoughts: 398
						

Thoughts:
**My Fuzzing Strategy: Prioritizing Network and USB**

Okay, so I've confirmed that the USB CAN drivers are operational, which is great news. The ISOTP and J1939 changes are also looking good, especially with the reference tracking in J1939.

Now, for configuring what to enable, I need to list the necessary configurations: `CAN_ISOTP`, `CAN_J1939`, `CAN_EMS_USB`, `CAN_GS_USB`, `CAN_KVASER_USB`, `CAN_PEAK_USB`, `CAN_CTUCANFD_PCI`, and `CAN_SOFTING`.

Wait a minute, `CAN_CTUCANFD_PCI` is a PCI driver, so I need to check if it's going to cause issues. If it's dependent on specific hardware, it might not be easy to fuzz. I better double-check. Okay, looking at `drivers/net/can/ctucanfd/ctucanfd_pci.c`, I see a `ctucan_pci_tbl` with a vendor ID of `17ce` and a device ID of `0300`. Yep, that's pretty specific.

But, syzkaller *can* fuzz PCI devices, either by emulating them using `syz_pci_device` or similar, or just through probing. I remember the prompt mentioning certain vendor-specific PCIe switch, SmartNIC, or GPU drivers like mlxsw, pds_core, qed, ionic, and amdgpu that *require* physical hardware. However, this is a CAN controller, not a SmartNIC or GPU, so there's a good chance it will work as long as PCI fuzzing is enabled.

Still, the main thrust of my fuzzing effort should be on the network protocols (ISOTP, J1939), and the USB drivers because these are more easily fuzzed.

I'll also keep `CAN_RCAR_CANFD` in mind as an additional target to check.



30/2 2026/07/30 16:22 tool grepper
0m Args:
{
  "Expression": "config CAN_RCAR_CANFD"
}

Results:
{
  "Output": "drivers/net/can/rcar/Kconfig=2=config CAN_RCAR\n--\ndrivers/net/can/rcar/Kconfig-11-\ndrivers/net/can/rcar/Kconfig:12:config CAN_RCAR_CANFD\ndrivers/net/can/rcar/Kconfig-13-\ttristate \"Renesas R-Car CAN FD controller\"\n"
}

31/2 2026/07/30 16:22 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 32736
							output: 20
							thoughts: 37
						

Thoughts:
**R-Car Platform Fuzzing Considerations**

Okay, so the R-Car platform. Generally, we don't bother fuzzing it unless there's a specific reason, like we have DT overlays or are specifically targeting platform device fuzzing. But, just to be thorough, I should probably check that `CAN_C_CAN` module and see if it's relevant to the current work.



32/2 2026/07/30 16:22 tool grepper
0m Args:
{
  "Expression": "config CAN_C_CAN"
}

Results:
{
  "Output": "drivers/net/can/c_can/Kconfig-1-# SPDX-License-Identifier: GPL-2.0-only\ndrivers/net/can/c_can/Kconfig:2:menuconfig CAN_C_CAN\ndrivers/net/can/c_can/Kconfig-3-\ttristate \"Bosch C_CAN/D_CAN devices\"\n--\ndrivers/net/can/c_can/Kconfig=6=if CAN_C_CAN\ndrivers/net/can/c_can/Kconfig-7-\ndrivers/net/can/c_can/Kconfig:8:config CAN_C_CAN_PLATFORM\ndrivers/net/can/c_can/Kconfig-9-\ttristate \"Generic Platform Bus based C_CAN/D_CAN driver\"\n--\ndrivers/net/can/c_can/Kconfig-17-\ndrivers/net/can/c_can/Kconfig:18:config CAN_C_CAN_PCI\ndrivers/net/can/c_can/Kconfig-19-\ttristate \"Generic PCI Bus based C_CAN/D_CAN driver\"\n"
}

33/2 2026/07/30 16:22 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 33152
							output: 19
							thoughts: 67
						

Thoughts:
Okay, here's my take on those thoughts, framed as my own mental processing as an expert:

**Reflecting on CAN Bus Options**

Alright, let's get down to brass tacks. I need to be comprehensive, so I'll be sure to consider a range of CAN interface possibilities. Specifically, I'll keep the following in mind as potential candidates: `CAN_ISOTP`, `CAN_J1939`, `CAN_EMS_USB`, `CAN_GS_USB`, `CAN_KVASER_USB`, `CAN_PEAK_USB`, and `CAN_SOFTING`. Each has its strengths and weaknesses, of course, depending on the application.

Given my extensive experience, my immediate concern is often the dependencies, and it's smart to start with `CAN_SOFTING`, as it can vary. I need to examine its software, drivers, and underlying APIs. I will investigate compatibility concerns, especially if I have other hardware integrated.



34/2 2026/07/30 16:22 tool grepper
0m Args:
{
  "Expression": "config CAN_SOFTING"
}

Results:
{
  "Output": "drivers/net/can/softing/Kconfig-1-# SPDX-License-Identifier: GPL-2.0-only\ndrivers/net/can/softing/Kconfig:2:config CAN_SOFTING\ndrivers/net/can/softing/Kconfig-3-\ttristate \"Softing Gmbh CAN generic support\"\n--\ndrivers/net/can/softing/Kconfig-18-\ndrivers/net/can/softing/Kconfig:19:config CAN_SOFTING_CS\ndrivers/net/can/softing/Kconfig-20-\ttristate \"Softing Gmbh CAN pcmcia cards\"\n"
}

35/2 2026/07/30 16:22 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 33604
							output: 37
							thoughts: 17
						

Thoughts:
Here's my take on the thought process, as if it were my own:

**Diving into the CAN Software Landscape**

Okay, so I need to get my bearings, huh? Let's start with a foundational piece of the puzzle. I'm thinking I should start digging around in the kernel's CAN driver structure – specifically, the `drivers/net/can/softing/Kconfig` file. This is the configuration file for the Softing CAN driver, right? So it should give me a high-level overview of the options, dependencies, and ultimately, how this particular driver integrates into the larger CAN subsystem within the kernel. I'm expecting to see things like: hardware platform support, various features that can be enabled or disabled, and maybe even some basic information on which kernel versions this driver is compatible with. This is the best place to get a clear picture of the design choices and the breadth of what this driver offers. From here, I can trace dependencies, understand configuration variables, and build a mental map of its functionality. This is where the exploration begins.



36/2 2026/07/30 16:22 tool read-file
0m Args:
{
  "File": "drivers/net/can/softing/Kconfig",
  "FirstLine": 1,
  "LineCount": 20
}

Results:
{
  "Contents": "   1:\t# SPDX-License-Identifier: GPL-2.0-only\n   2:\tconfig CAN_SOFTING\n   3:\t\ttristate \"Softing Gmbh CAN generic support\"\n   4:\t\tdepends on HAS_IOMEM\n   5:\t\thelp\n   6:\t\t  Support for CAN cards from Softing Gmbh \u0026 some cards\n   7:\t\t  from Vector Gmbh.\n   8:\t\t  Softing Gmbh CAN cards come with 1 or 2 physical buses.\n   9:\t\t  Those cards typically use Dual Port RAM to communicate\n  10:\t\t  with the host CPU. The interface is then identical for PCI\n  11:\t\t  and PCMCIA cards. This driver operates on a platform device,\n  12:\t\t  which has been created by softing_cs or softing_pci driver.\n  13:\t\t  Warning:\n  14:\t\t  The API of the card does not allow fine control per bus, but\n  15:\t\t  controls the 2 buses on the card together.\n  16:\t\t  As such, some actions (start/stop/busoff recovery) on 1 bus\n  17:\t\t  must bring down the other bus too temporarily.\n  18:\t\n  19:\tconfig CAN_SOFTING_CS\n  20:\t\ttristate \"Softing Gmbh CAN pcmcia cards\"\n"
}

37/2 2026/07/30 16:22 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 34217
							output: 25
							thoughts: 350
						

Thoughts:
**Analyzing J1939 Function Scope**

Okay, so I'm dealing with `SOFTING` - I'm assuming that's related to either PCMCIA or PCI, so I'll be sure to include the `CAN_SOFTING` identifier in my analysis. I'm focusing on the J1939 functions now. I need to get a clear picture of their scope and intended use.

First, let's take a look at the functions I'm working with: `j1939_session_new`, `j1939_session_destroy`, `j1939_session_fresh_new`, `j1939_ecu_create_locked`, `j1939_ecu_release`, `j1939_priv_create`, `j1939_priv_release`, `j1939_netdev_start`, and `j1939_netdev_stop`.

Now, I need to check which of these are declared as static. This affects their visibility and how they're intended to be used. I've found that `j1939_session_new` is indeed static. `j1939_session_destroy` is also static, which makes sense. I see that `j1939_session_fresh_new` is *not* static, so I'll need to pay closer attention to how it's being accessed. `j1939_ecu_create_locked` is also not static. `j1939_ecu_release` is static, which is interesting, but `j1939_ecu_put` (which I assume is related) is not, so I'll need to note the distinction. `j1939_priv_create` and `j1939_priv_release` are both static, which is consistent. Finally, `j1939_netdev_start` and `j1939_netdev_stop` are not static.

I want to dive deeper into `j1939_session_fresh_new` specifically, so I'll open up `net/can/j1939/transport.c` to examine its implementation and see how it interacts with the non-static functions.



38/2 2026/07/30 16:23 tool grepper
0m Args:
{
  "Expression": "j1939_session_fresh_new"
}

Results:
{
  "Output": "net/can/j1939/transport.c=1552=static struct\nnet/can/j1939/transport.c:1553:j1939_session *j1939_session_fresh_new(struct j1939_priv *priv,\nnet/can/j1939/transport.c-1554-\t\t\t\t       int size,\n--\nnet/can/j1939/transport.c=1622=j1939_session *j1939_xtp_rx_rts_session_new(struct j1939_priv *priv,\n--\nnet/can/j1939/transport.c-1663-\nnet/can/j1939/transport.c:1664:\tsession = j1939_session_fresh_new(priv, len, \u0026skcb);\nnet/can/j1939/transport.c-1665-\tif (!session) {\n"
}

39/2 2026/07/30 16:23 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 35361
							output: 23
							thoughts: 75
						

Thoughts:
Here's my summary, as the expert:

**Investigating a Potential Static Variable in CAN Communication Code**

Okay, so I'm looking at this `j1939_session_fresh_new` variable. My initial thought was that it was likely a static variable. The grep output definitely seems to confirm this, showing `static struct j1939_session *j1939_session_fresh_new`. Given that it's static, I immediately need to understand its scope and lifespan within the larger system, and how that impacts communication. I need to know where it's being used to determine how it's being handled. My next step will be to dive into `j1939_tp_send` and `j1939_tp_recv` to get the context of this variable. The Transport Protocol (TP) functions are logical places to start. I'm expecting to find calls to the variable in these functions.



40/2 2026/07/30 16:23 tool grepper
0m Args:
{
  "Expression": "j1939_tp_send"
}

Results:
{
  "Output": "net/can/j1939/j1939-priv.h=192=void j1939_sk_queue_activate_next(struct j1939_session *session);\n--\nnet/can/j1939/j1939-priv.h-194-/* stack entries */\nnet/can/j1939/j1939-priv.h:195:struct j1939_session *j1939_tp_send(struct j1939_priv *priv,\nnet/can/j1939/j1939-priv.h-196-\t\t\t\t    struct sk_buff *skb, size_t size);\n--\nnet/can/j1939/socket.c=1135=static int j1939_sk_send_loop(struct j1939_priv *priv,  struct sock *sk,\n--\nnet/can/j1939/socket.c-1171-\t\t\tskcb-\u003eoffset = 0;\nnet/can/j1939/socket.c:1172:\t\t\tsession = j1939_tp_send(priv, skb, size);\nnet/can/j1939/socket.c-1173-\t\t\tif (IS_ERR(session)) {\n--\nnet/can/j1939/transport.c=1984=static void j1939_xtp_rx_dat(struct j1939_priv *priv, struct sk_buff *skb)\n--\nnet/can/j1939/transport.c-2019-/* j1939 main intf */\nnet/can/j1939/transport.c:2020:struct j1939_session *j1939_tp_send(struct j1939_priv *priv,\nnet/can/j1939/transport.c-2021-\t\t\t\t    struct sk_buff *skb, size_t size)\n"
}

41/2 2026/07/30 16:23 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 36181
							output: 23
							thoughts: 30
						

Thoughts:
Okay, here's my take on those thoughts, framed as my own:

**J1939 TP Conundrums**

Hmm, so `j1939_tp_send` isn't static. Alright, that's noted. Now, that raises the immediate question – and it's a critical one in considering the bigger picture – what's the deal with `j1939_tp_recv`? The implication that `j1939_tp_send` isn't static demands that I examine the reciprocal nature of the transport protocol. Are they both dynamic? Is the dynamism linked, or independent? What are the implications for state management, buffer allocation, and potential race conditions in a multi-threaded or interrupt-driven environment? I need to understand the nuances of the receiver's behavior to fully grasp the complexities of the sender's non-static nature. This immediately brings to mind issues related to message fragmentation and reassembly at both ends. I need to dig deeper into the code and the specifications to understand this interplay. This could open up a host of issues, or it could be a simple matter of a pre-allocated structure. Let's see.



42/2 2026/07/30 16:23 tool grepper
0m Args:
{
  "Expression": "j1939_tp_recv"
}

Results:
{
  "Output": "net/can/j1939/j1939-priv.h=195=struct j1939_session *j1939_tp_send(struct j1939_priv *priv,\nnet/can/j1939/j1939-priv.h-196-\t\t\t\t    struct sk_buff *skb, size_t size);\nnet/can/j1939/j1939-priv.h:197:int j1939_tp_recv(struct j1939_priv *priv, struct sk_buff *skb);\nnet/can/j1939/j1939-priv.h-198-int j1939_ac_fixup(struct j1939_priv *priv, struct sk_buff *skb);\n--\nnet/can/j1939/main.c=34=static void j1939_can_recv(struct sk_buff *iskb, void *data)\n--\nnet/can/j1939/main.c-107-\nnet/can/j1939/main.c:108:\tif (j1939_tp_recv(priv, skb))\nnet/can/j1939/main.c-109-\t\t/* this means the transport layer processed the message */\n--\nnet/can/j1939/transport.c=2083=static void j1939_tp_cmd_recv(struct j1939_priv *priv, struct sk_buff *skb)\n--\nnet/can/j1939/transport.c-2178-\nnet/can/j1939/transport.c:2179:int j1939_tp_recv(struct j1939_priv *priv, struct sk_buff *skb)\nnet/can/j1939/transport.c-2180-{\n"
}

43/2 2026/07/30 16:23 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 36983
							output: 21
							thoughts: 531
						

Thoughts:
**Focus Symbol Analysis**

Okay, so I'm diving into symbol analysis and need to be precise here. I see that `j1939_tp_recv` is dynamic, so it's a clear candidate for focus symbols, and I'll add `j1939_tp_send` to that list as well.

Now, for ISOTP, I initially thought `isotp_sendmsg` and `isotp_bind` were static. But wait, they are part of `isotp_ops`, and the key is if they are inlined. The guidance specifies, and I agree, that non-static, non-inlined API entrypoints are preferred. Aha! `isotp_sendmsg` *is* static but is a function pointer within `proto_ops`. That means the compiler won't inline it. Excellent, it has a distinct address and is perfectly acceptable to use. The same goes for `isotp_bind`, `isotp_release`, and `isotp_poll`. `isotp_rcv` is another one, it's also passed as a function pointer to `can_rx_register`. So, they all are good.

Moving on, I need to check others. `pcan_usb_fd_decode_buf` is passed as a function pointer to `peak_usb_adapter` – fine. `kvaser_usb_leaf_read_bulk_callback` is part of `kvaser_usb_dev_ops` (again, function pointer), so it's good to go. The same pattern continues: `ems_usb_read_bulk_callback` is passed to `usb_fill_bulk_urb`, and `gs_usb_receive_bulk_callback` is passed to `usb_fill_bulk_urb` – they are all eligible.

So, I've confirmed that these aren't inlined and have distinct addresses.

Okay, let's make a complete list of these functions, I need to have a good overview.

Here are the functions I'm listing:
`isotp_sendmsg`
`isotp_rcv`
`isotp_rcv_echo`
`isotp_release`
`isotp_bind`
`isotp_poll`
`j1939_tp_send`
`j1939_tp_recv`
`j1939_netdev_start`
`pcan_usb_fd_decode_buf`
`kvaser_usb_leaf_read_bulk_callback`
`ems_usb_read_bulk_callback`
`gs_usb_receive_bulk_callback`

Let me quickly verify that `isotp_rcv_echo` is passed as a function pointer to be sure.



44/2 2026/07/30 16:23 tool grepper
0m Args:
{
  "Expression": "isotp_rcv_echo"
}

Results:
{
  "Output": "net/can/isotp.c=863=static void isotp_send_cframe(struct isotp_sock *so)\n--\nnet/can/isotp.c-911-\nnet/can/isotp.c:912:\t/* zero'ed by init/isotp_rcv_echo(); reached lock-free via\nnet/can/isotp.c-913-\t * isotp_txfr_timer_handler() too, so use READ_ONCE()/WRITE_ONCE()\n--\nnet/can/isotp.c=933=static void isotp_create_fframe(struct canfd_frame *cf, struct isotp_sock *so,\n--\nnet/can/isotp.c-967-\nnet/can/isotp.c:968:static void isotp_rcv_echo(struct sk_buff *skb, void *data)\nnet/can/isotp.c-969-{\n--\nnet/can/isotp.c=1088=static enum hrtimer_restart isotp_txfr_timer_handler(struct hrtimer *hrtimer)\n--\nnet/can/isotp.c-1096-\nnet/can/isotp.c:1097:\t/* cfecho should be consumed by isotp_rcv_echo() here */\nnet/can/isotp.c-1098-\tif (READ_ONCE(so-\u003etx.state) == ISOTP_SENDING \u0026\u0026 !READ_ONCE(so-\u003ecfecho))\n--\nnet/can/isotp.c=1104=static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)\n--\nnet/can/isotp.c-1232-\nnet/can/isotp.c:1233:\t/* cfecho should have been zero'ed by init / former isotp_rcv_echo() */\nnet/can/isotp.c-1234-\told_cfecho = READ_ONCE(so-\u003ecfecho);\n--\nnet/can/isotp.c-1262-\nnet/can/isotp.c:1263:\t\t/* set CF echo tag for isotp_rcv_echo() (SF-mode) */\nnet/can/isotp.c-1264-\t\tWRITE_ONCE(so-\u003ecfecho, skb-\u003ehash);\n--\nnet/can/isotp.c-1279-\nnet/can/isotp.c:1280:\t\t\t/* set CF echo tag for isotp_rcv_echo() (CF-mode) */\nnet/can/isotp.c-1281-\t\t\tWRITE_ONCE(so-\u003ecfecho, skb-\u003ehash);\n--\nnet/can/isotp.c-1289-\nnet/can/isotp.c:1290:\t\t\t/* no CF echo tag for isotp_rcv_echo() (FF-mode) */\nnet/can/isotp.c-1291-\t\t\tWRITE_ONCE(so-\u003ecfecho, 0);\n--\nnet/can/isotp.c=1446=static int isotp_release(struct socket *sock)\n--\nnet/can/isotp.c-1500-\t\t\t\t  SINGLE_MASK(so-\u003etxid),\nnet/can/isotp.c:1501:\t\t\t\t  isotp_rcv_echo, sk);\nnet/can/isotp.c-1502-\t\tnetdev_put(so-\u003edev, \u0026so-\u003edev_tracker);\n--\nnet/can/isotp.c=1534=static int isotp_bind(struct socket *sock, struct sockaddr_unsized *uaddr, int len)\n--\nnet/can/isotp.c-1630-\tcan_rx_register(net, dev, tx_id, SINGLE_MASK(tx_id),\nnet/can/isotp.c:1631:\t\t\tisotp_rcv_echo, sk, \"isotpe\", sk);\nnet/can/isotp.c-1632-\n--\nnet/can/isotp.c=1846=static void isotp_notify(struct isotp_sock *so, unsigned long msg,\n--\nnet/can/isotp.c-1868-\t\t\t\t\t  SINGLE_MASK(so-\u003etxid),\nnet/can/isotp.c:1869:\t\t\t\t\t  isotp_rcv_echo, sk);\nnet/can/isotp.c-1870-\t\t\tnetdev_put(so-\u003edev, \u0026so-\u003edev_tracker);\n"
}

45/2 2026/07/30 16:23 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 39270
							output: 20
							thoughts: 90
						

Thoughts:
Okay, here's my take on those thoughts, framed as an expert's internal monologue:

**Checking the ISOTP Timer Setup**

Alright, so `isotp_rcv_echo` gets registered with the CAN receive path via `can_rx_register`, as expected. Now, let's drill down into the timer mechanisms. I need to make sure the transmission timeouts and re-transmission timers are properly initialized. I see that `isotp_tx_timeout` and `isotp_txfr_timer_handler` are both passed to `hrtimer_init`. Good, that means the high-resolution timer infrastructure is being leveraged, which is the right approach for these real-time requirements. I’m satisfied that is an appropriate choice. Okay, now let's see how they are called. `isotp_tx_timeout` is called from `isotp_tx_timer_handler` and `isotp_echo_timer_handler`. This looks right; the timeout function needs to be triggered either by a transmission timer or when an echo is requested. The `echo` handler gives me pause for a moment... is the echo handler really required? I'll probably want to double-check that this is being used correctly, especially considering the potential for race conditions in ISOTP implementations. But, so far, so good. Everything looks fundamentally correct for ISOTP timing management.



46/2 2026/07/30 16:23 tool grepper
0m Args:
{
  "Expression": "isotp_tx_timeout"
}

Results:
{
  "Output": "net/can/isotp.c=441=static int isotp_rcv_fc(struct isotp_sock *so, struct canfd_frame *cf, int ae)\n--\nnet/can/isotp.c-451-\nnet/can/isotp.c:452:\t/* isotp_tx_timeout() may have given up on this job while\nnet/can/isotp.c-453-\t * hrtimer_cancel() above waited for it to finish =\u003e recheck\n--\nnet/can/isotp.c=968=static void isotp_rcv_echo(struct sk_buff *skb, void *data)\n--\nnet/can/isotp.c-1032-\nnet/can/isotp.c:1033:/* isotp_tx_timeout: we did not get any flow control or echo frame in time\nnet/can/isotp.c-1034- *\n--\nnet/can/isotp.c-1040- */\nnet/can/isotp.c:1041:static enum hrtimer_restart isotp_tx_timeout(struct isotp_sock *so)\nnet/can/isotp.c-1042-{\n--\nnet/can/isotp.c=1071=static enum hrtimer_restart isotp_tx_timer_handler(struct hrtimer *hrtimer)\n--\nnet/can/isotp.c-1075-\nnet/can/isotp.c:1076:\treturn isotp_tx_timeout(so);\nnet/can/isotp.c-1077-}\n--\nnet/can/isotp.c=1080=static enum hrtimer_restart isotp_echo_timer_handler(struct hrtimer *hrtimer)\n--\nnet/can/isotp.c-1084-\nnet/can/isotp.c:1085:\treturn isotp_tx_timeout(so);\nnet/can/isotp.c-1086-}\n"
}

47/2 2026/07/30 16:23 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 40178
							output: 25
							thoughts: 200
						

Thoughts:
**Examining the Timer and J1939 Functions**

Okay, so I'm focusing on the timer handlers right now. It looks like `isotp_tx_timer_handler` and `isotp_echo_timer_handler` are the ones that are currently being initialized with `hrtimer_init`. My next step is definitely to incorporate `isotp_txfr_timer_handler` into that list as well. Need to get all those in order.

Now, let's switch gears and investigate those J1939 functions. I need to make sure everything's behaving as expected. Let's see... I have `j1939_tp_send`, `j1939_tp_recv`, then there's `j1939_netdev_start` and `j1939_netdev_stop` for network device management, and socket-related stuff with `j1939_sk_send_loop`, `j1939_sk_recvmsg`, `j1939_sk_bind`, and `j1939_sk_release`. Okay, looks like a good overview of the core functionality. I'll need to dig into these in detail.

The first one to drill into, right now, is `j1939_sk_send_loop`. I'll start with that function.



48/2 2026/07/30 16:23 tool grepper
0m Args:
{
  "Expression": "j1939_sk_send_loop"
}

Results:
{
  "Output": "net/can/j1939/j1939-priv.h=187=bool j1939_sk_recv_match(struct j1939_priv *priv,\nnet/can/j1939/j1939-priv.h-188-\t\t\t struct j1939_sk_buff_cb *skcb);\nnet/can/j1939/j1939-priv.h:189:void j1939_sk_send_loop_abort(struct sock *sk, int err);\nnet/can/j1939/j1939-priv.h-190-void j1939_sk_errqueue(struct j1939_session *session,\n--\nnet/can/j1939/socket.c=1102=void j1939_sk_errqueue(struct j1939_session *session,\n--\nnet/can/j1939/socket.c-1122-\nnet/can/j1939/socket.c:1123:void j1939_sk_send_loop_abort(struct sock *sk, int err)\nnet/can/j1939/socket.c-1124-{\n--\nnet/can/j1939/socket.c-1134-\nnet/can/j1939/socket.c:1135:static int j1939_sk_send_loop(struct j1939_priv *priv,  struct sock *sk,\nnet/can/j1939/socket.c-1136-\t\t\t      struct msghdr *msg, size_t size)\n--\nnet/can/j1939/socket.c=1229=static int j1939_sk_sendmsg(struct socket *sock, struct msghdr *msg,\n--\nnet/can/j1939/socket.c-1294-\nnet/can/j1939/socket.c:1295:\tret = j1939_sk_send_loop(priv, sk, msg, size);\nnet/can/j1939/socket.c-1296-\n--\nnet/can/j1939/transport.c=1140=static void __j1939_session_cancel(struct j1939_session *session,\n--\nnet/can/j1939/transport.c-1157-\tif (session-\u003esk)\nnet/can/j1939/transport.c:1158:\t\tj1939_sk_send_loop_abort(session-\u003esk, session-\u003eerr);\nnet/can/j1939/transport.c-1159-}\n--\nnet/can/j1939/transport.c=1355=static void j1939_xtp_rx_abort_one(struct j1939_priv *priv, struct sk_buff *skb,\n--\nnet/can/j1939/transport.c-1376-\tif (session-\u003esk)\nnet/can/j1939/transport.c:1377:\t\tj1939_sk_send_loop_abort(session-\u003esk, session-\u003eerr);\nnet/can/j1939/transport.c-1378-\telse\n"
}

49/2 2026/07/30 16:23 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 41564
							output: 24
							thoughts: 68
						

Thoughts:
Here's my take on the process, considering I'm the one architecting this:

**Initial J1939 Socket Layer Implementation**

Okay, so we're starting to build out the J1939 socket layer. The entry point, as I've decided, is going to be `j1939_sk_sendmsg`. That's where all outgoing messages will originate. Now, to make this useful, we need a complete set of socket operations. I need to implement `j1939_sk_recvmsg` for receiving data, obviously. Then, we need `j1939_sk_bind` to allow sockets to be associated with specific addresses or groups, and finally, `j1939_sk_release` to handle the graceful teardown and freeing of resources when a socket is closed. This provides the fundamental building blocks for a functional J1939 socket interface. That should cover the core socket operations.



50/2 2026/07/30 16:23 tool grepper
0m Args:
{
  "Expression": "j1939_sk_sendmsg"
}

Results:
{
  "Output": "net/can/j1939/socket.c=1135=static int j1939_sk_send_loop(struct j1939_priv *priv,  struct sock *sk,\n--\nnet/can/j1939/socket.c-1228-\nnet/can/j1939/socket.c:1229:static int j1939_sk_sendmsg(struct socket *sock, struct msghdr *msg,\nnet/can/j1939/socket.c-1230-\t\t\t    size_t size)\n--\nnet/can/j1939/socket.c=1375=static const struct proto_ops j1939_ops = {\n--\nnet/can/j1939/socket.c-1388-\t.getsockopt = j1939_sk_getsockopt,\nnet/can/j1939/socket.c:1389:\t.sendmsg = j1939_sk_sendmsg,\nnet/can/j1939/socket.c-1390-\t.recvmsg = j1939_sk_recvmsg,\n"
}

51/2 2026/07/30 16:23 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 42170
							output: 24
							thoughts: 38
						

Thoughts:
Okay, here's my interpretation of those thoughts, framed as an expert's inner monologue:

**Adding Key CAN J1939 Socket Functions**

Alright, the next logical step here is to flesh out the J1939 socket implementation. I'm thinking we need to add a few crucial functions to handle the lifecycle of these sockets, specifically around receiving messages and managing their connection.

First, let's implement the `j1939_sk_recvmsg` function. This is critical because it's the core of how we'll pull data from the J1939 network. This function will be responsible for receiving J1939 frames from the socket, handling addressing, filtering based on our configured masks, and delivering the relevant data to the application. I need to make sure this is robust and efficient, handling potential errors and fragmentation correctly. Think about the details.

Then, the `j1939_sk_bind` function is essential. It's the mechanism for linking the socket to a specific J1939 node and its associated parameters. It will handle the binding of the socket to the chosen source address, destination address, and other critical parameters necessary to facilitate receiving the J1939 messages, and filter incoming traffic.

And finally, to maintain the socket and release its resources, we'll need `j1939_sk_release`. This is crucial for properly cleaning up after the socket is no longer needed. It will need to handle freeing allocated memory, closing the underlying network connection, and generally ensuring a clean shutdown, preventing resource leaks. This is vital to prevent memory leaks and ensure the system behaves reliably. So, I need to make sure this is properly integrated with the socket cleanup process.



52/2 2026/07/30 16:24 tool grepper
0m Args:
{
  "Expression": "j1939_sk_recvmsg"
}

Results:
{
  "Output": "net/can/j1939/socket.c=769=static int j1939_sk_getsockopt(struct socket *sock, int level, int optname,\n--\nnet/can/j1939/socket.c-819-\nnet/can/j1939/socket.c:820:static int j1939_sk_recvmsg(struct socket *sock, struct msghdr *msg,\nnet/can/j1939/socket.c-821-\t\t\t    size_t size, int flags)\n--\nnet/can/j1939/socket.c=1375=static const struct proto_ops j1939_ops = {\n--\nnet/can/j1939/socket.c-1389-\t.sendmsg = j1939_sk_sendmsg,\nnet/can/j1939/socket.c:1390:\t.recvmsg = j1939_sk_recvmsg,\nnet/can/j1939/socket.c-1391-\t.mmap = sock_no_mmap,\n"
}

53/2 2026/07/30 16:24 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 42896
							output: 23
							thoughts: 26
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Adding SocketCAN Binding/Release for J1939**

Alright, so the task at hand is crystal clear. We need to integrate `j1939_sk_bind` and `j1939_sk_release` into the system. This seems like a critical step in enabling proper J1939 functionality on our SocketCAN interface. Essentially, we're talking about managing the SocketCAN binding and releasing process *specifically* for J1939 traffic. Thinking it through, this implies a few things we need to consider.

First, the `j1939_sk_bind` function will have to handle the necessary SocketCAN calls for binding to the CAN interface, potentially with specific J1939 filters or address configurations. We need to make sure this is done in a clean and efficient manner, not just calling the system bind but handling all the CAN related nuances. Are we dealing with standard or extended CAN IDs, and how will we handle the different J1939 addressing schemes? What error handling needs to be in place if the binding fails, and how can we provide useful feedback to the caller?

Then, the `j1939_sk_release` function is just as important. We need to ensure that the SocketCAN socket is properly unbound and all associated resources are freed. This prevents resource leaks and potential conflicts with other processes that might want to use the CAN interface. We have to be very careful to avoid race conditions or leaving the interface in an inconsistent state. Are we planning on any graceful shutdown procedures, or is this just a clean unbind?

The interaction between these two functions will be crucial. We need a robust mechanism to pair binds and releases, and to handle any exceptions or unexpected scenarios. The choice of how to do this, perhaps using reference counters, or an explicit pair of bind and release calls, will be important for overall robustness. Also, what implications will this have on existing J1939 interfaces? Are we creating a new abstraction, or modifying existing ones?

Ultimately, the goal is a reliable and well-defined mechanism for controlling J1939 traffic within the SocketCAN environment, and this addition is a step toward that. It's a fundamental piece that sets the stage for everything else.



54/2 2026/07/30 16:24 tool grepper
0m Args:
{
  "Expression": "j1939_sk_bind"
}

Results:
{
  "Output": "net/can/j1939/socket.c=428=static int j1939_sk_sanity_check(struct sockaddr_can *addr, int len)\n--\nnet/can/j1939/socket.c-444-\nnet/can/j1939/socket.c:445:static int j1939_sk_bind(struct socket *sock, struct sockaddr_unsized *uaddr, int len)\nnet/can/j1939/socket.c-446-{\n--\nnet/can/j1939/socket.c=1319=void j1939_sk_netdev_event_unregister(struct j1939_priv *priv)\n--\nnet/can/j1939/socket.c-1334-\t\t/* Check if j1939_jsk_del() is not yet called on this socket after holding\nnet/can/j1939/socket.c:1335:\t\t * socket's lock, for both j1939_sk_bind() and j1939_sk_release() call\nnet/can/j1939/socket.c-1336-\t\t * j1939_jsk_del() with socket's lock held.\n--\nnet/can/j1939/socket.c-1339-\t\tif (jsk-\u003estate \u0026 J1939_SOCK_BOUND) {\nnet/can/j1939/socket.c:1340:\t\t\t/* Neither j1939_sk_bind() nor j1939_sk_release() called j1939_jsk_del().\nnet/can/j1939/socket.c:1341:\t\t\t * Make this socket no longer bound, by pretending as if j1939_sk_bind()\nnet/can/j1939/socket.c-1342-\t\t\t * dropped old references but did not get new references.\n--\nnet/can/j1939/socket.c=1375=static const struct proto_ops j1939_ops = {\n--\nnet/can/j1939/socket.c-1377-\t.release = j1939_sk_release,\nnet/can/j1939/socket.c:1378:\t.bind = j1939_sk_bind,\nnet/can/j1939/socket.c-1379-\t.connect = j1939_sk_connect,\n"
}

55/2 2026/07/30 16:24 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 44078
							output: 23
							thoughts: 15
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience, presented in the first person:

**Adding `j1939_sk_release`**

Alright, so the task at hand is to add `j1939_sk_release` – immediately, my mind starts sifting through the implications. I assume this likely involves a specific function, library, or module related to J1939 protocol implementation, potentially targeting a *specific* release or version of software. I start mentally mapping out where this should fit within the existing project architecture. Is this a new component, a modification to an existing one, or a refactoring effort? The naming convention immediately prompts me to consider version control and release management strategies. Will this be a completely separate branch, a specific tag, or something else entirely?

I'm thinking about the potential dependencies now. What other modules or libraries does `j1939_sk_release` rely on? Are there external libraries, hardware drivers, or operating system interfaces involved? I need to quickly determine if there are any compatibility issues with existing code or if updates are needed. Performance is always a concern, especially with real-time systems like J1939. I'm wondering if this release involves any optimizations or performance-critical changes. What's the expected throughput or latency for this new component?

Security is paramount, too. If this relates to network communication, I'm already mentally checking for potential vulnerabilities like spoofing or tampering. Are there any encryption or authentication considerations? I need to be sure any changes adhere to industry best practices and standards.

Finally, I'm considering testing. What's the best way to thoroughly test this new component? Unit tests, integration tests, end-to-end tests... I'll need to define a comprehensive test plan to ensure this release is stable and performs as expected. Code coverage and static analysis will be crucial.



56/2 2026/07/30 16:24 tool grepper
0m Args:
{
  "Expression": "j1939_sk_release"
}

Results:
{
  "Output": "net/can/j1939/socket.c=613=static int j1939_sk_getname(struct socket *sock, struct sockaddr *uaddr,\n--\nnet/can/j1939/socket.c-636-\nnet/can/j1939/socket.c:637:static int j1939_sk_release(struct socket *sock)\nnet/can/j1939/socket.c-638-{\n--\nnet/can/j1939/socket.c=1319=void j1939_sk_netdev_event_unregister(struct j1939_priv *priv)\n--\nnet/can/j1939/socket.c-1334-\t\t/* Check if j1939_jsk_del() is not yet called on this socket after holding\nnet/can/j1939/socket.c:1335:\t\t * socket's lock, for both j1939_sk_bind() and j1939_sk_release() call\nnet/can/j1939/socket.c-1336-\t\t * j1939_jsk_del() with socket's lock held.\n--\nnet/can/j1939/socket.c-1339-\t\tif (jsk-\u003estate \u0026 J1939_SOCK_BOUND) {\nnet/can/j1939/socket.c:1340:\t\t\t/* Neither j1939_sk_bind() nor j1939_sk_release() called j1939_jsk_del().\nnet/can/j1939/socket.c-1341-\t\t\t * Make this socket no longer bound, by pretending as if j1939_sk_bind()\n--\nnet/can/j1939/socket.c=1375=static const struct proto_ops j1939_ops = {\nnet/can/j1939/socket.c-1376-\t.family = PF_CAN,\nnet/can/j1939/socket.c:1377:\t.release = j1939_sk_release,\nnet/can/j1939/socket.c-1378-\t.bind = j1939_sk_bind,\n"
}

57/2 2026/07/30 16:24 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 45106
							output: 24
							thoughts: 508
						

Thoughts:
**Identifying Key Entry Points for CAN Bus Analysis**

Okay, let's get down to brass tacks. I need to pinpoint the critical functions for dissecting this CAN bus implementation. My initial focus is on the core interaction points for the various CAN protocols.

First, for J1939, the key functions I'm zeroing in on are `j1939_sk_sendmsg`, `j1939_sk_recvmsg`, `j1939_sk_bind`, `j1939_sk_release`, `j1939_tp_send`, `j1939_tp_recv`, and especially `j1939_netdev_start`. That last one looks promising as a starting point.

Next, for ISOTP, I'll be looking closely at `isotp_sendmsg`, `isotp_rcv`, `isotp_rcv_echo`, `isotp_release`, `isotp_bind`, and `isotp_poll`.

Now for the USB CAN adapter side, I've got a list. I'm going to carefully scrutinize the USB-specific functions. I think `pcan_usb_fd_decode_buf` looks like it might be an entry point. `kvaser_usb_leaf_read_bulk_callback` is another candidate. Same goes for `ems_usb_read_bulk_callback` and `gs_usb_receive_bulk_callback`. I need to figure out where the data is read and translated.

Let's do a quick sanity check to see if I'm on the right track. Right, `j1939_netdev_start` is called when a J1939 socket is bound to a netdev. That confirms it. A perfect entry point.

`pcan_usb_fd_decode_buf` is passed as a function pointer to `peak_usb_adapter`. That's another win.

`kvaser_usb_leaf_read_bulk_callback` is passed as a function pointer to `kvaser_usb_dev_ops`. Excellent. I'm on the right track.

`ems_usb_read_bulk_callback` is called via `usb_fill_bulk_urb` and the same applies to `gs_usb_receive_bulk_callback`. Confirmed. Both are solid entry points.

I'll also keep `es58x_read_bulk_callback` from the ETAS driver in mind, as it's likely a similar function to the others.



58/2 2026/07/30 16:24 tool grepper
0m Args:
{
  "Expression": "es58x_read_bulk_callback"
}

Results:
{
  "Output": "drivers/net/can/usb/etas_es58x/es58x_core.c=1355=static signed int es58x_split_urb(struct es58x_device *es58x_dev,\n--\ndrivers/net/can/usb/etas_es58x/es58x_core.c-1400-/**\ndrivers/net/can/usb/etas_es58x/es58x_core.c:1401: * es58x_read_bulk_callback() - Callback for reading data from device.\ndrivers/net/can/usb/etas_es58x/es58x_core.c-1402- * @urb: last urb buffer received.\n--\ndrivers/net/can/usb/etas_es58x/es58x_core.c-1409- */\ndrivers/net/can/usb/etas_es58x/es58x_core.c:1410:static void es58x_read_bulk_callback(struct urb *urb)\ndrivers/net/can/usb/etas_es58x/es58x_core.c-1411-{\n--\ndrivers/net/can/usb/etas_es58x/es58x_core.c=1705=static int es58x_alloc_rx_urbs(struct es58x_device *es58x_dev)\n--\ndrivers/net/can/usb/etas_es58x/es58x_core.c-1721-\t\tusb_fill_bulk_urb(urb, es58x_dev-\u003eudev, es58x_dev-\u003erx_pipe,\ndrivers/net/can/usb/etas_es58x/es58x_core.c:1722:\t\t\t\t  buf, rx_buf_len, es58x_read_bulk_callback,\ndrivers/net/can/usb/etas_es58x/es58x_core.c-1723-\t\t\t\t  es58x_dev);\n"
}

59/2 2026/07/30 16:24 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 46711
							output: 20
							thoughts: 62
						

Thoughts:
Okay, here's my interpretation of those thoughts, tailored for an expert audience, as if they were my own:

**Initial Assessment of Firmware Update Entry Point**

Right, `es58x_read_bulk_callback`... yes, that looks like a sound starting point for investigating the firmware update process. Seems like a logical entry point for handling data coming back from the hardware.

Now, let's dive into the `drivers/net/can/softing/softing_fw.c` file. Specifically, I need to take a look at the `softing_load_fw` and `softing_load_app_fw` functions. That's where the actual firmware loading and application likely takes place, or at least where the relevant control functions are called, and I want to see how that callback is integrated. I want to see how it's integrated to understand the data flow. Let's see how that's implemented.



60/2 2026/07/30 16:24 tool grepper
0m Args:
{
  "Expression": "softing_load_fw"
}

Results:
{
  "Output": "drivers/net/can/softing/softing.h=81=int softing_bootloader_command(struct softing *card, int16_t cmd,\n--\ndrivers/net/can/softing/softing.h-84-/* Load firmware after reset */\ndrivers/net/can/softing/softing.h:85:int softing_load_fw(const char *file, struct softing *card,\ndrivers/net/can/softing/softing.h-86-\t\t    __iomem uint8_t *virt, unsigned int size, int offset);\n--\ndrivers/net/can/softing/softing_fw.c=94=static int fw_parse(const u8 **pmem, const u8 *limit, u16 *ptype,\n--\ndrivers/net/can/softing/softing_fw.c-139-\ndrivers/net/can/softing/softing_fw.c:140:int softing_load_fw(const char *file, struct softing *card,\ndrivers/net/can/softing/softing_fw.c-141-\t\t__iomem uint8_t *dpram, unsigned int size, int offset)\n--\ndrivers/net/can/softing/softing_main.c=471=static int softing_card_boot(struct softing *card)\n--\ndrivers/net/can/softing/softing_main.c-507-\t/* load boot firmware */\ndrivers/net/can/softing/softing_main.c:508:\tret = softing_load_fw(card-\u003epdat-\u003eboot.fw, card, card-\u003edpram,\ndrivers/net/can/softing/softing_main.c-509-\t\t\t\tcard-\u003edpram_size,\n--\ndrivers/net/can/softing/softing_main.c-513-\t/* load loader firmware */\ndrivers/net/can/softing/softing_main.c:514:\tret = softing_load_fw(card-\u003epdat-\u003eload.fw, card, card-\u003edpram,\ndrivers/net/can/softing/softing_main.c-515-\t\t\t\tcard-\u003edpram_size,\n"
}

61/2 2026/07/30 16:24 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 47553
							output: 23
							thoughts: 108
						

Thoughts:
**Adding Firmware Load Functions to the Target List**

Okay, so I'm thinking about how to broaden my fuzzing coverage. I've realized that `softing_load_fw` and `softing_load_app_fw` are key functions during device initialization. They aren't directly exposed via syscalls for fuzzing, which means I haven't been targeting them directly, which is a gap. These functions get executed during device probing or when it’s brought up, so I should definitely add them to the fuzzing target list. That feels like a clear win for increasing the potential surface area.

Now, to see if there are other initialization functions I could consider, I should check `rcar_canfd_global_init` in `drivers/net/can/rcar/rcar_canfd.c`. Maybe there are similar initialization functions in this file I can add to the list.



62/2 2026/07/30 16:24 tool grepper
0m Args:
{
  "Expression": "rcar_canfd_global_init"
}

Results:
{
  "Output": "drivers/net/can/rcar/rcar_canfd.c=1988=static void rcar_canfd_channel_remove(struct rcar_canfd_global *gpriv, u32 ch)\n--\ndrivers/net/can/rcar/rcar_canfd.c-1998-\ndrivers/net/can/rcar/rcar_canfd.c:1999:static int rcar_canfd_global_init(struct rcar_canfd_global *gpriv)\ndrivers/net/can/rcar/rcar_canfd.c-2000-{\n--\ndrivers/net/can/rcar/rcar_canfd.c=2099=static int rcar_canfd_probe(struct platform_device *pdev)\n--\ndrivers/net/can/rcar/rcar_canfd.c-2256-\ndrivers/net/can/rcar/rcar_canfd.c:2257:\terr = rcar_canfd_global_init(gpriv);\ndrivers/net/can/rcar/rcar_canfd.c-2258-\tif (err)\n--\ndrivers/net/can/rcar/rcar_canfd.c=2327=static int rcar_canfd_resume(struct device *dev)\n--\ndrivers/net/can/rcar/rcar_canfd.c-2332-\ndrivers/net/can/rcar/rcar_canfd.c:2333:\terr = rcar_canfd_global_init(gpriv);\ndrivers/net/can/rcar/rcar_canfd.c-2334-\tif (err) {\ndrivers/net/can/rcar/rcar_canfd.c:2335:\t\tdev_err(dev, \"rcar_canfd_global_init() failed %pe\\n\", ERR_PTR(err));\ndrivers/net/can/rcar/rcar_canfd.c-2336-\t\treturn err;\n"
}

63/2 2026/07/30 16:24 llm patch-evaluator
1m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 48384
							output: 21
							thoughts: 36
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Analyzing the Call Context**

Right, so we're looking at a function that's invoked during probe and resume operations. My initial instinct is that this context is somewhat limited for direct fuzzing, but that doesn't mean it's entirely useless. I can definitely see some potential for leveraging this, even if it's not the primary entry point. We'll have to assess the possibilities later.

First though, before I proceed with any more complex assessment, let's turn our attention to `c_can_chip_config`. I need to understand how the chip configuration affects the operation and if any configurations will expose new or relevant parameters. I suspect that there might be some interaction there. That's the logical next step.



64/2 2026/07/30 16:25 tool grepper
0m Args:
{
  "Expression": "c_can_chip_config"
}

Results:
{
  "Output": "drivers/net/can/c_can/c_can_main.c=564=static int c_can_software_reset(struct net_device *dev)\n--\ndrivers/net/can/c_can/c_can_main.c-588- */\ndrivers/net/can/c_can/c_can_main.c:589:static int c_can_chip_config(struct net_device *dev)\ndrivers/net/can/c_can/c_can_main.c-590-{\n--\ndrivers/net/can/c_can/c_can_main.c=632=static int c_can_start(struct net_device *dev)\n--\ndrivers/net/can/c_can/c_can_main.c-638-\t/* basic c_can configuration */\ndrivers/net/can/c_can/c_can_main.c:639:\terr = c_can_chip_config(dev);\ndrivers/net/can/c_can/c_can_main.c-640-\tif (err)\n"
}

65/2 2026/07/30 16:25 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 48892
							output: 21
							thoughts: 33
						

Thoughts:
Okay, here's my interpretation of those thoughts, summarized from a first-person expert perspective:

**Initial Assessment: CAN Interface Activation**

Alright, so I'm in the `c_can_start` context. This is the crucial point where the CAN interface is being brought online. My immediate concern, as always, is whether the hardware is being configured correctly. Specifically, I need to verify how the `ctucan_set_mode` function is behaving during this interface initialization sequence. Are the underlying registers being set as expected? Is the mode transition smooth and predictable? This is my primary point of focus. This is a critical point in the start up sequence. Any issue here and the system will not work.



66/2 2026/07/30 16:25 tool grepper
0m Args:
{
  "Expression": "ctucan_set_mode"
}

Results:
{
  "Output": "drivers/net/can/ctucanfd/ctucanfd_base.c=290=static int ctucan_set_secondary_sample_point(struct net_device *ndev)\n--\ndrivers/net/can/ctucanfd/ctucanfd_base.c-321-/**\ndrivers/net/can/ctucanfd/ctucanfd_base.c:322: * ctucan_set_mode() - Sets CTU CAN FDs mode\ndrivers/net/can/ctucanfd/ctucanfd_base.c-323- * @priv:\tPointer to private data\n--\ndrivers/net/can/ctucanfd/ctucanfd_base.c-325- */\ndrivers/net/can/ctucanfd/ctucanfd_base.c:326:static void ctucan_set_mode(struct ctucan_priv *priv, const struct can_ctrlmode *mode)\ndrivers/net/can/ctucanfd/ctucanfd_base.c-327-{\n--\ndrivers/net/can/ctucanfd/ctucanfd_base.c=375=static int ctucan_chip_start(struct net_device *ndev)\n--\ndrivers/net/can/ctucanfd/ctucanfd_base.c-403-\tmode.mask = 0xFFFFFFFF;\ndrivers/net/can/ctucanfd/ctucanfd_base.c:404:\tctucan_set_mode(priv, \u0026mode);\ndrivers/net/can/ctucanfd/ctucanfd_base.c-405-\n"
}

67/2 2026/07/30 16:25 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 49511
							output: 24
							thoughts: 532
						

Thoughts:
**Fuzzing Focus: Network Protocols and USB Drivers**

Okay, so I'm in `ctucan_chip_start`. Time to get down to brass tacks. Given the patch series, I'm going to focus my fuzzing efforts on the network protocols – ISOTP and J1939 – and the USB drivers. It's pretty clear that these areas will have the most complex logic changes and offer the best bang for my buck in terms of fuzzing potential.

I've already scoped out some key symbols to target: `isotp_sendmsg`, `isotp_rcv`, `isotp_rcv_echo`, `isotp_release`, `isotp_bind`, `isotp_poll`, `j1939_sk_sendmsg`, `j1939_sk_recvmsg`, `j1939_sk_bind`, `j1939_sk_release`, `j1939_tp_send`, `j1939_tp_recv`, `j1939_netdev_start`, and the callback functions for the USB drivers, namely, `pcan_usb_fd_decode_buf`, `kvaser_usb_leaf_read_bulk_callback`, `ems_usb_read_bulk_callback`, `gs_usb_receive_bulk_callback`, and `es58x_read_bulk_callback`. These should give me a good handle on where the interesting code is.

Now, I need to nail down the configurations I'll be targeting. I had to go through them: `CAN_ISOTP`, `CAN_J1939`, `CAN_EMS_USB`, `CAN_GS_USB`, `CAN_KVASER_USB`, `CAN_PEAK_USB`, `CAN_SOFTING`, `CAN_CTUCANFD_PCI`, and `CAN_RCAR_CANFD`. I made a quick note on `CAN_C_CAN`. `CAN_C_CAN` has `CAN_C_CAN_PLATFORM` and `CAN_C_CAN_PCI`, so I'll include `CAN_C_CAN_PCI`.

Alright, I'm refining the configs to: `CAN_ISOTP`, `CAN_J1939`, `CAN_EMS_USB`, `CAN_GS_USB`, `CAN_KVASER_USB`, `CAN_PEAK_USB`, `CAN_SOFTING`, `CAN_CTUCANFD_PCI`, and `CAN_C_CAN_PCI`.

Time to check `CAN_ETAS_ES58X`. Let's see what we have...



68/2 2026/07/30 16:26 tool grepper
0m Args:
{
  "Expression": "config CAN_ETAS_ES58X"
}

Results:
{
  "Output": "drivers/net/can/usb/Kconfig=17=config CAN_ESD_USB\n--\ndrivers/net/can/usb/Kconfig-30-\ndrivers/net/can/usb/Kconfig:31:config CAN_ETAS_ES58X\ndrivers/net/can/usb/Kconfig-32-\ttristate \"ETAS ES58X CAN/USB interfaces\"\n"
}

69/2 2026/07/30 16:26 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 50751
							output: 468
							thoughts: 922
						

Thoughts:
**Analyzing CAN Driver and Protocol Changes**

Okay, let's get this organized. I need to incorporate the new `CAN_ETAS_ES58X` driver. I'll also add `CAN_SOFTING`, as `CAN_SOFTING` seems to provide generic support, and I should make sure that the more specific `CAN_SOFTING_CS` is correctly included.

Now, let's do a quick review of the focus symbols to confirm they're all in order. I've got a comprehensive list here: `isotp_sendmsg`, `isotp_rcv`, `isotp_rcv_echo`, `isotp_release`, `isotp_bind`, `isotp_poll`, `j1939_sk_sendmsg`, `j1939_sk_recvmsg`, `j1939_sk_bind`, `j1939_sk_release`, `j1939_tp_send`, `j1939_tp_recv`, `j1939_netdev_start`, `pcan_usb_fd_decode_buf`, `kvaser_usb_leaf_read_bulk_callback`, `ems_usb_read_bulk_callback`, `gs_usb_receive_bulk_callback`, and `es58x_read_bulk_callback`. Looks good, all the relevant functions are accounted for.

Next, I need to verify how these are being used, particularly if they're static and/or passed as function pointers. Let's step through them one by one. `isotp_rcv` is indeed static and passed to `can_rx_register`. Good. `isotp_release` is static and passed to `proto_ops`. Check. `j1939_sk_sendmsg` is also static and part of `proto_ops`. Confirmed. `j1939_tp_send` is *not* static, and that's expected. `j1939_netdev_start` is also *not* static, again, as expected.

Now the USB drivers. `pcan_usb_fd_decode_buf` is static and passed to `peak_usb_adapter`. Correct. `kvaser_usb_leaf_read_bulk_callback` is static and passed to `kvaser_usb_dev_ops`. Excellent. `ems_usb_read_bulk_callback`, `gs_usb_receive_bulk_callback`, and `es58x_read_bulk_callback` are all static and passed to `usb_fill_bulk_urb`. This confirms the expected usage patterns.

Essentially, these modifications are touching critical areas, including a major overhaul of the ISOTP TX state machine and error handling to address race conditions, plus reference tracking for J1939 netdevs. They also introduce length validation and bounds checking, particularly in the USB CAN drivers (ems_usb, gs_usb, kvaser_usb, peak_usb, and now etas_es58x). There are also minor fixes in other CAN drivers, like c_can, ctucanfd, rcar_canfd, and softing. It's important to keep these factors in mind when configuring these systems. The implications mean that these changes are definitely reachable via sockets and USB fuzzing. That new ISOTP state machine and the added validation logic need a thorough fuzzing campaign to ensure they're robust.

Given this analysis, I will set up the associated configurations. They are: `CAN_ISOTP`, `CAN_J1939`, `CAN_EMS_USB`, `CAN_GS_USB`, `CAN_KVASER_USB`, `CAN_PEAK_USB`, `CAN_ETAS_ES58X`, `CAN_SOFTING`, `CAN_CTUCANFD_PCI`, and `CAN_C_CAN_PCI`.

Alright, I'm ready to proceed. I'll call `set-results` now.



70/2 2026/07/30 16:26 tool set-results
0m Args:
{
  "EnableConfigs": [
    "CAN_ISOTP",
    "CAN_J1939",
    "CAN_EMS_USB",
    "CAN_GS_USB",
    "CAN_KVASER_USB",
    "CAN_PEAK_USB",
    "CAN_ETAS_ES58X",
    "CAN_SOFTING",
    "CAN_CTUCANFD_PCI",
    "CAN_C_CAN_PCI"
  ],
  "FocusSymbols": [
    "isotp_sendmsg",
    "isotp_rcv",
    "isotp_rcv_echo",
    "isotp_release",
    "isotp_bind",
    "isotp_poll",
    "j1939_sk_sendmsg",
    "j1939_sk_recvmsg",
    "j1939_sk_bind",
    "j1939_sk_release",
    "j1939_tp_send",
    "j1939_tp_recv",
    "j1939_netdev_start",
    "pcan_usb_fd_decode_buf",
    "kvaser_usb_leaf_read_bulk_callback",
    "ems_usb_read_bulk_callback",
    "gs_usb_receive_bulk_callback",
    "es58x_read_bulk_callback"
  ],
  "Reasoning": "The patch series introduces functional changes to the CAN ISOTP and J1939 protocols, including a major rewrite of the ISOTP tx state machine and error handling to fix race conditions, and reference tracking for J1939 netdevs. It also adds length validation and bounds checking to several USB CAN drivers (ems_usb, gs_usb, kvaser_usb, peak_usb, etas_es58x) and fixes minor issues in other CAN drivers (c_can, ctucanfd, rcar_canfd, softing). These changes are reachable via sockets and USB fuzzing, and should be heavily fuzzed to ensure the new state machine and validation logic are correct.",
  "WorthFuzzing": true
}

Results:
{
  "EnableConfigs": [
    "CAN_ISOTP",
    "CAN_J1939",
    "CAN_EMS_USB",
    "CAN_GS_USB",
    "CAN_KVASER_USB",
    "CAN_PEAK_USB",
    "CAN_ETAS_ES58X",
    "CAN_SOFTING",
    "CAN_CTUCANFD_PCI",
    "CAN_C_CAN_PCI"
  ],
  "FocusSymbols": [
    "isotp_sendmsg",
    "isotp_rcv",
    "isotp_rcv_echo",
    "isotp_release",
    "isotp_bind",
    "isotp_poll",
    "j1939_sk_sendmsg",
    "j1939_sk_recvmsg",
    "j1939_sk_bind",
    "j1939_sk_release",
    "j1939_tp_send",
    "j1939_tp_recv",
    "j1939_netdev_start",
    "pcan_usb_fd_decode_buf",
    "kvaser_usb_leaf_read_bulk_callback",
    "ems_usb_read_bulk_callback",
    "gs_usb_receive_bulk_callback",
    "es58x_read_bulk_callback"
  ],
  "Reasoning": "The patch series introduces functional changes to the CAN ISOTP and J1939 protocols, including a major rewrite of the ISOTP tx state machine and error handling to fix race conditions, and reference tracking for J1939 netdevs. It also adds length validation and bounds checking to several USB CAN drivers (ems_usb, gs_usb, kvaser_usb, peak_usb, etas_es58x) and fixes minor issues in other CAN drivers (c_can, ctucanfd, rcar_canfd, softing). These changes are reachable via sockets and USB fuzzing, and should be heavily fuzzed to ensure the new state machine and validation logic are correct.",
  "WorthFuzzing": true
}

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)