Skip to content

fix(max7456): silence static-analysis warning on intentional SPI RX-drain read (DR register) #1110

@coderabbitai

Description

@coderabbitai

Summary

In src/main/drivers/max7456.c inside max7456_dma_irq_handler(), the STM32 SPI RX buffer is drained after DMA transmission by reading the DR register in a bare expression:

// Empty RX buffer. RX DMA takes care of it if enabled.
// This should be done after transmission finish!!!
while (SPI_I2S_GetFlagStatus(busdev->busType_u.spi.instance, SPI_I2S_FLAG_RXNE) == SET) {
    busdev->busType_u.spi.instance->DR;   // line 310
}

The read of DR is intentional — on STM32, reading the SPI DR register is the only way to clear the RXNE flag and discard the buffered received byte. However, because the value is never stored in a variable, static-analysis tools (Codacy / cppcheck) flag it as a "Redundant code: Found unused member access." (MINOR / Code style).

Suggested fix

Make the intentional side-effect explicit to satisfy static analysers:

while (SPI_I2S_GetFlagStatus(busdev->busType_u.spi.instance, SPI_I2S_FLAG_RXNE) == SET) {
    (void)busdev->busType_u.spi.instance->DR;
}

Notes

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions