Skip to content

Commit 20d4c75

Browse files
kaabiajhedberg
authored andcommitted
fix(can): mcp2515: Guard TX interrupt handling for multi-buffer configs
The MCP2515 driver can be configured with 1, 2, or 3 transmit buffers via the `MCP2515_TX_CNT` constant. The interrupt handler checks for transmit complete interrupts for `TXB1` and `TXB2`. However, the code for these checks was not guarded by preprocessor conditionals. This meant the code would be compiled even if the driver was configured to use only one transmit buffer (`MCP2515_TX_CNT=1`), which is the default. This change adds the appropriate `#if MCP2515_TX_CNT > 1` and `#if MCP2515_TX_CNT > 2` guards around the interrupt handling logic for the second and third transmit buffers, respectively. This ensures that the code is only included when the corresponding buffers are actually configured, improving code clarity and preventing compilation of unused logic. Signed-off-by: Badr Bacem KAABIA <badrbacemkaabia@gmail.com>
1 parent 039013f commit 20d4c75

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/can/can_mcp2515.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,13 +831,17 @@ static void mcp2515_handle_interrupts(const struct device *dev)
831831
mcp2515_tx_done(dev, 0, 0);
832832
}
833833

834+
#if MCP2515_TX_CNT > 1
834835
if (canintf & MCP2515_CANINTF_TX1IF) {
835836
mcp2515_tx_done(dev, 1, 0);
836837
}
838+
#endif /* MCP2515_TX_CNT > 1 */
837839

840+
#if MCP2515_TX_CNT > 2
838841
if (canintf & MCP2515_CANINTF_TX2IF) {
839842
mcp2515_tx_done(dev, 2, 0);
840843
}
844+
#endif /* MCP2515_TX_CNT > 2 */
841845

842846
if (canintf & MCP2515_CANINTF_ERRIF) {
843847
mcp2515_handle_errors(dev);

0 commit comments

Comments
 (0)