Skip to content

drivers: can: sja1000: k_sleep() called in interrupt context #63712

@henrikbrixandersen

Description

@henrikbrixandersen

Describe the bug
When built with CONFIG_CAN_AUTO_BUS_OFF_RECOVERY=y, the SJA1000 CAN controller driver backend attempts to recover from a bus-off event by calling can_sja1000_leave_reset_mode() in can_sja1000_handle_error_warning_irq(), which is called in interrupt context.

The can_sja1000_leave_reset_mode() functions attempts to bring the controller out of reset mode and polls the MOD register to wait for this to happen, with calls to k_sleep() in between each poll. This behaviour is intended for all other use-cases of the function, but fails horribly when called in interrupt context.

To Reproduce
Steps to reproduce the behavior:

  1. Short CAN_H and CAN_L on a supported ESP32 board (e.g. olimex_esp32_evb).
  2. Build and flash an application with CONFIG_CAN_SHELL=y and CONFIG_CAN_AUTO_BUS_OFF_RECOVERY=y to the board.
  3. Using the CAN shell module, issue can start can@3ff6b000 followed by can send can@3ff6b000 010.
  4. See error:
[00:00:12.577,000] <err> os:  ** FATAL EXCEPTION
[00:00:12.577,000] <err> os:  ** CPU 0 EXCCAUSE 63 (zephyr exception)
[00:00:12.577,000] <err> os:  **  PC 0x40080edb VADDR 0
[00:00:12.577,000] <err> os:  **  PS 0x60a20
[00:00:12.577,000] <err> os:  **    (INTLEVEL:0 EXCM: 0 UM:1 RING:0 WOE:1 OWB:10 CALLINC:2)
[00:00:12.577,000] <err> os:  **  A0 0x800d1bc8  SP 0x3ffe64b0  A2 0x4  A3 0x3ffe64c0
[00:00:12.577,000] <err> os:  **  A4 0x3ffe64a0  A5 0x4  A6 0  A7 0xffffff8e
[00:00:12.577,000] <err> os:  **  A8 0x80086041  A9 0x3ffe6410 A10 0x3f404e5b A11 0x3ffe64c0
[00:00:12.577,000] <err> os:  ** A12 0x3ffe64a0 A13 0x4 A14 0xffe03fff A15 0x3ffe69e0
[00:00:12.577,000] <err> os:  ** LBEG 0x4000c2e0 LEND 0x4000c2f6 LCOUNT 0xffffffff
[00:00:12.577,000] <err> os:  ** SAR 0x4

Ba0x40080ed8:0x30x400d1bc5:0x30x40083b20:0x30x400d8b66:0x30x400d93f2:0x30x40080c9d:0x30x400815b5:0x30x40080fd3:0x30x40080fbe:0x30x40082476:0x30x400d1677:0x3

[00:00:12.577,000] <err> os: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0
[00:00:12.577,000] <err> os: Current thread: 0x3ffb27e8 (idle)
[00:00:12.756,000] <err> os: Halting system

Expected behavior
The can_sja1000_handle_error_warning_irq() function should only attempt to start bus-off recovery, but not wait for the result.

Impact
SJA1000 based drivers fail to automatically recover from bus-off, crashing the CPU.

Environment (please complete the following information):

  • OS: Linux
  • Toolchain: Zephyr SDK
  • Commit SHA: 68365d5

Metadata

Metadata

Labels

area: CANbugThe issue is a bug, or the PR is fixing a bugpriority: lowLow impact/importance bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions