staging: pi433: Fix validation of rf69_get_modulation value

Checking of modulation in rf69_set_modulation_shaping is done by
if-else and since else part covers OOK and UNDEF values it possible to
set modulation shaping for undefined modulation type.
To fix this validation should be done by switch clause and in case of
undefined modulation error returned.

Signed-off-by: Marcin Ciupak <marcin.s.ciupak@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Marcin Ciupak 2017-12-08 15:31:54 +00:00 committed by Greg Kroah-Hartman
parent 1c12da3576
commit 84f1e4b089
1 changed files with 6 additions and 2 deletions

View File

@ -128,7 +128,8 @@ int rf69_set_modulation_shaping(struct spi_device *spi,
dev_dbg(&spi->dev, "set: mod shaping");
#endif
if (rf69_get_modulation(spi) == FSK) {
switch (rf69_get_modulation(spi)) {
case FSK:
switch (mod_shaping) {
case SHAPING_OFF: return rf69_read_mod_write(spi, REG_DATAMODUL, MASK_DATAMODUL_MODULATION_SHAPE, DATAMODUL_MODULATION_SHAPE_NONE);
case SHAPING_1_0: return rf69_read_mod_write(spi, REG_DATAMODUL, MASK_DATAMODUL_MODULATION_SHAPE, DATAMODUL_MODULATION_SHAPE_1_0);
@ -138,7 +139,7 @@ int rf69_set_modulation_shaping(struct spi_device *spi,
dev_dbg(&spi->dev, "set: illegal input param");
return -EINVAL;
}
} else {
case OOK:
switch (mod_shaping) {
case SHAPING_OFF: return rf69_read_mod_write(spi, REG_DATAMODUL, MASK_DATAMODUL_MODULATION_SHAPE, DATAMODUL_MODULATION_SHAPE_NONE);
case SHAPING_BR: return rf69_read_mod_write(spi, REG_DATAMODUL, MASK_DATAMODUL_MODULATION_SHAPE, DATAMODUL_MODULATION_SHAPE_BR);
@ -147,6 +148,9 @@ int rf69_set_modulation_shaping(struct spi_device *spi,
dev_dbg(&spi->dev, "set: illegal input param");
return -EINVAL;
}
default:
dev_dbg(&spi->dev, "set: modulation undefined");
return -EINVAL;
}
}