All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paulo Miguel Almeida <paulo.miguel.almeida.rodenas@gmail.com>
To: gregkh@linuxfoundation.org,
	paulo.miguel.almeida.rodenas@gmail.com, realwakka@gmail.com
Cc: linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH v2 3/3] staging: pi433: validate max bit_rate based on modulation used
Date: Mon, 17 Jan 2022 19:02:20 +1300	[thread overview]
Message-ID: <20220117060220.GA11202@mail.google.com> (raw)
In-Reply-To: <20220117055849.GA10644@mail.google.com>

Max bit rate is dependent on which modulation is used. Previous
validation routine only took into consideration min bit rate which can
lead a misconfiguration of the rf69 chip causing the packets not to be
sent/read.

This patch enhances that input check in set_bit_rate to account for
modulation values and their respective max bit rate

Signed-off-by: Paulo Miguel Almeida <paulo.miguel.almeida.rodenas@gmail.com>
---
Meta-comments:

In the patchset v1 I kept bit_rate argument's original type as I thought that
changing it to accomodate values as high as 300kbps couldn't be part of this
patchset and therefore it should be a separate patchset. 

Given that kernel test bot compilation/test process 'complained' about the 
argument's type, I decided to send the v2 patch that addresses the data type
problem while I work on the patch that will change bit_rate type across
tx_cfg and rx_cfg as this will require a bit more work.

Please let me know if anyone dislikes the approach and wants me to deal with it
in a different way.
---
 drivers/staging/pi433/rf69.c | 14 ++++++++++++--
 drivers/staging/pi433/rf69.h |  2 +-
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/pi433/rf69.c b/drivers/staging/pi433/rf69.c
index f4ac17adcd83..adba69b8365e 100644
--- a/drivers/staging/pi433/rf69.c
+++ b/drivers/staging/pi433/rf69.c
@@ -223,15 +223,25 @@ int rf69_set_modulation_shaping(struct spi_device *spi,
 	}
 }
 
-int rf69_set_bit_rate(struct spi_device *spi, u16 bit_rate)
+int rf69_set_bit_rate(struct spi_device *spi, u32 bit_rate)
 {
 	int retval;
 	u32 bit_rate_reg;
 	u8 msb;
 	u8 lsb;
+	enum modulation mod;
+
+	// check if modulation is configured
+	mod = rf69_get_modulation(spi);
+	if (mod == UNDEF) {
+		dev_dbg(&spi->dev, "setBitRate: modulation is undefined");
+		return -EINVAL;
+	}
 
 	// check input value
-	if (bit_rate < 1200) {
+	if (bit_rate < 1200 ||
+	    (mod == FSK && bit_rate > 300000) ||
+	    (mod == OOK && bit_rate > 32768)) {
 		dev_dbg(&spi->dev, "setBitRate: illegal input param");
 		return -EINVAL;
 	}
diff --git a/drivers/staging/pi433/rf69.h b/drivers/staging/pi433/rf69.h
index c25942f142a6..3b8184155326 100644
--- a/drivers/staging/pi433/rf69.h
+++ b/drivers/staging/pi433/rf69.h
@@ -23,7 +23,7 @@ int rf69_set_data_mode(struct spi_device *spi, u8 data_mode);
 int rf69_set_modulation(struct spi_device *spi, enum modulation modulation);
 int rf69_set_modulation_shaping(struct spi_device *spi,
 				enum mod_shaping mod_shaping);
-int rf69_set_bit_rate(struct spi_device *spi, u16 bit_rate);
+int rf69_set_bit_rate(struct spi_device *spi, u32 bit_rate);
 int rf69_set_deviation(struct spi_device *spi, u32 deviation);
 int rf69_set_frequency(struct spi_device *spi, u32 frequency);
 int rf69_enable_amplifier(struct spi_device *spi, u8 amplifier_mask);
-- 
2.25.4


  parent reply	other threads:[~2022-01-17  6:02 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-16  0:17 [PATCH 0/3] staging: pi433: validate min/max bit rate settings Paulo Miguel Almeida
2022-01-16  0:21 ` [PATCH 1/3] staging: pi433: fix validation for min bit rate supported by the device Paulo Miguel Almeida
2022-01-16  0:22 ` [PATCH 2/3] staging: pi433: change order in which driver config the rf69 chip Paulo Miguel Almeida
2022-01-16  0:23 ` [PATCH 3/3] staging: pi433: validate max bit_rate based on modulation used Paulo Miguel Almeida
2022-01-16 14:06   ` kernel test robot
2022-01-16 14:06     ` kernel test robot
2022-01-17  5:58     ` [PATCH v2 0/3] staging: pi433: validate min/max bit rate settings Paulo Miguel Almeida
2022-01-17  6:00       ` [PATCH v2 1/3] staging: pi433: fix validation for min bit rate supported by the device Paulo Miguel Almeida
2022-01-17  6:01       ` [PATCH v2 2/3] staging: pi433: change order in which driver config the rf69 chip Paulo Miguel Almeida
2022-01-17  6:02       ` Paulo Miguel Almeida [this message]
2022-01-18 13:59         ` [PATCH v2 3/3] staging: pi433: validate max bit_rate based on modulation used Dan Carpenter
2022-01-18 19:34           ` Paulo Miguel Almeida
2022-01-18 23:03             ` [PATCH v3 0/3] staging: pi433: validate min/max bit rate settings Paulo Miguel Almeida
2022-01-18 23:04               ` [PATCH v3 1/3] staging: pi433: fix validation for min bit rate supported by the device Paulo Miguel Almeida
2022-01-18 23:05               ` [PATCH v3 2/3] staging: pi433: change order in which driver config the rf69 chip Paulo Miguel Almeida
2022-01-18 23:05               ` [PATCH v3 3/3] staging: pi433: validate max bit_rate based on modulation used Paulo Miguel Almeida
2022-01-19  6:04               ` [PATCH v3 0/3] staging: pi433: validate min/max bit rate settings Dan Carpenter
2022-01-23  7:43                 ` Paulo Miguel Almeida
2022-01-24  8:53                   ` Dan Carpenter
2022-01-19  5:34             ` [PATCH v2 3/3] staging: pi433: validate max bit_rate based on modulation used Dan Carpenter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220117060220.GA11202@mail.google.com \
    --to=paulo.miguel.almeida.rodenas@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=realwakka@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.