Skip to content

Commit 6d5ef04

Browse files
feat(PeriphDrivers): Avoid div-by-zero in SPI SetFrequency calls (#1552)
Signed-off-by: Pete Johanson <pete.johanson@analog.com>
1 parent 3f60df5 commit 6d5ef04

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

Libraries/PeriphDrivers/Source/SPI/spi_reva1.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ int MXC_SPI_RevA1_SetFrequency(mxc_spi_reva_regs_t *spi, unsigned int hz)
190190
int hi_clk, lo_clk, scale;
191191
uint32_t freq_div;
192192

193+
if (!hz) {
194+
return E_BAD_PARAM;
195+
}
196+
193197
// Check if frequency is too high
194198
if (hz > PeripheralClock) {
195199
return E_BAD_PARAM;

Libraries/PeriphDrivers/Source/SPI/spi_reva2.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,10 @@ int MXC_SPI_RevA2_SetFrequency(mxc_spi_reva_regs_t *spi, uint32_t freq)
581581
int hi_clk, lo_clk, scale;
582582
uint32_t freq_div;
583583

584+
if (!freq) {
585+
return E_BAD_PARAM;
586+
}
587+
584588
// Check if frequency is too high
585589
if (freq > PeripheralClock) {
586590
return E_BAD_PARAM;

0 commit comments

Comments
 (0)