[PATCH 2/2] staging: pi433: Fix validation of rf69_get_modulation value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 drivers/staging/pi433/rf69.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/pi433/rf69.c b/drivers/staging/pi433/rf69.c
index 3b73a3a02879..a66db795d7df 100644
--- a/drivers/staging/pi433/rf69.c
+++ b/drivers/staging/pi433/rf69.c
@@ -129,7 +129,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);
@@ -139,7 +140,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);
@@ -148,6 +149,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;
 	}
 }
 
-- 
2.15.0

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux