Skip to content

Commit

Permalink
drivers/nrf24l01p: fix potentially undefined return value
Browse files Browse the repository at this point in the history
  • Loading branch information
aabadie committed Oct 27, 2019
1 parent 7072696 commit 283a906
Showing 1 changed file with 3 additions and 20 deletions.
23 changes: 3 additions & 20 deletions drivers/nrf24l01p/nrf24l01p.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,30 +618,13 @@ int nrf24l01p_set_power(const nrf24l01p_t *dev, int pwr)
return nrf24l01p_write_reg(dev, REG_RF_SETUP, rf_setup);
}

static const int _nrf24l01p_power_map[4] = { -18, -12, -6, 0 };

int nrf24l01p_get_power(const nrf24l01p_t *dev)
{
char rf_setup;
int pwr;

nrf24l01p_read_reg(dev, REG_RF_SETUP, &rf_setup);

if ((rf_setup & 0x6) == 0) {
pwr = -18;
}

if ((rf_setup & 0x6) == 2) {
pwr = -12;
}

if ((rf_setup & 0x6) == 4) {
pwr = -6;
}

if ((rf_setup & 0x6) == 6) {
pwr = 0;
}

return pwr;
return _nrf24l01p_power_map[(rf_setup & 0x6) >> 1];
}


Expand Down

0 comments on commit 283a906

Please # to comment.