Skip to contentSkip to conversation

drivers/staging/pi433: Change data type of bit_rate to be u32

PATCH In review Gautam Menghani 3 participants 3 messages Oct 20, 2022 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers/staging/pi433: Change data type of bit_rate to be u32

A TODO asks to convert the bit_rate variable to be a u32 so that bit rates up to 300kbps can be supported as per the spec.

---
Please note that this patch is only compile tested.

 drivers/staging/pi433/TODO       | 2 --
 drivers/staging/pi433/pi433_if.h | 4 ++--
 drivers/staging/pi433/rf69.c     | 2 +-
 drivers/staging/pi433/rf69.h     | 2 +-
 4 files changed, 4 insertions(+), 6 deletions(-)
drivers/staging/pi433/TODO +0 -2
index 5cf3fd99d521..8530bbe61d70 100644
@@ -1,5 +1,3 @@
 * currently the code introduces new IOCTLs. I'm afraid this is a bad idea.
   -> Replace this with another interface, hints are welcome!
 * Some missing data (marked with ###) needs to be added in the documentation
-* Change (struct pi433_tx_cfg)->bit_rate to be a u32 so that we can support
-    bit rates up to 300kbps per the spec.
drivers/staging/pi433/pi433_if.h +2 -2
index 25ee0b77a32c..c958dcfa9f96 100644
@@ -51,7 +51,7 @@ enum option_on_off {
 #define PI433_TX_CFG_IOCTL_NR	0
 struct pi433_tx_cfg {
 	__u32			frequency;
-	__u16			bit_rate;
+	__u32			bit_rate;
 	__u32			dev_frequency;
 	enum modulation		modulation;
 	enum mod_shaping	mod_shaping;
@@ -99,7 +99,7 @@ struct pi433_tx_cfg {
 #define PI433_RX_CFG_IOCTL_NR	1
 struct pi433_rx_cfg {
 	__u32			frequency;
-	__u16			bit_rate;
+	__u32			bit_rate;
 	__u32			dev_frequency;
 
 	enum modulation		modulation;
drivers/staging/pi433/rf69.c +1 -1
index 8c7fab6a46bb..7e754a3aef5f 100644
@@ -185,7 +185,7 @@ 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;
drivers/staging/pi433/rf69.h +1 -1
index 78fa0b8bab8b..46a1fb2d5329 100644
@@ -24,7 +24,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);
Signature · 1 line
2.34.1
#1 lore raw
Quoted 3 lines · Gautam Menghani

A TODO asks to convert the bit_rate variable to be a u32 so that bit rates up to 300kbps can be supported as per the spec.

Thanks for sending this patch. Comments added in-line.

Quoted 14 lines
drivers/staging/pi433/pi433_if.h +1 -1
index 25ee0b77a32c..c958dcfa9f96 100644
@@ -51,7 +51,7 @@ enum option_on_off {
 #define PI433_TX_CFG_IOCTL_NR	0
 struct pi433_tx_cfg {
 	__u32			frequency;
-	__u16			bit_rate;
+	__u32			bit_rate;
 	__u32			dev_frequency;
 	enum modulation		modulation;
 	enum mod_shaping	mod_shaping;

drivers/staging/pi433/pi433_if.h struct pi433_tx_cfg { · line 105

Quoted 8 lines
drivers/staging/pi433/pi433_if.h +1 -1
@@ -99,7 +99,7 @@ struct pi433_tx_cfg {
 #define PI433_RX_CFG_IOCTL_NR	1
 struct pi433_rx_cfg {
 	__u32			frequency;
-	__u16			bit_rate;
+	__u32			bit_rate;
 	__u32			dev_frequency;
 
 	enum modulation		modulation;

Cutting a long story short, you won't be able to change bit_rate's type before addressing the fact that both pi433_tx_cfg ans pi433_rx_cfg are part of the UAPI.

Usually there are 2 approaches that most people go for when talking about changes in drivers:

1) Add changes in a backwards compatible way, so whether users are using the bitrate member as u32 or u64, it would simply work. But that leads to sometimes hard-to-read code.... but this is still a card up your sleeve.

One suggestion given by Dan Carpenter was to leave the IOCTL impl alone and start a sysfs implementation. That way you could have a u64 bit_rate synthetic file.

https://lore.kernel.org/all/20220119053410.GW1978@kadam/

2) Change the tools that make use of this driver at the same time as you change the UAPI. This can be tricky. There is a thread I started in the kernelnewbies mailing list on the subject which I think might be relevant for you to read.

https://lore.kernel.org/all/YjHvLFSV06w%[email protected]/

Happy coding :-)

Paulo A.

#2 lore raw
In reply to Gautam Menghani
Quoted 74 lines · Gautam Menghani

A TODO asks to convert the bit_rate variable to be a u32 so that bit rates up to 300kbps can be supported as per the spec.

---
Please note that this patch is only compile tested.

 drivers/staging/pi433/TODO       | 2 --
 drivers/staging/pi433/pi433_if.h | 4 ++--
 drivers/staging/pi433/rf69.c     | 2 +-
 drivers/staging/pi433/rf69.h     | 2 +-
 4 files changed, 4 insertions(+), 6 deletions(-)
drivers/staging/pi433/TODO +0 -2
index 5cf3fd99d521..8530bbe61d70 100644
@@ -1,5 +1,3 @@
 * currently the code introduces new IOCTLs. I'm afraid this is a bad idea.
   -> Replace this with another interface, hints are welcome!
 * Some missing data (marked with ###) needs to be added in the documentation
-* Change (struct pi433_tx_cfg)->bit_rate to be a u32 so that we can support
-    bit rates up to 300kbps per the spec.
drivers/staging/pi433/pi433_if.h +2 -2
index 25ee0b77a32c..c958dcfa9f96 100644
@@ -51,7 +51,7 @@ enum option_on_off {
 #define PI433_TX_CFG_IOCTL_NR	0
 struct pi433_tx_cfg {
 	__u32			frequency;
-	__u16			bit_rate;
+	__u32			bit_rate;
 	__u32			dev_frequency;
 	enum modulation		modulation;
 	enum mod_shaping	mod_shaping;
@@ -99,7 +99,7 @@ struct pi433_tx_cfg {
 #define PI433_RX_CFG_IOCTL_NR	1
 struct pi433_rx_cfg {
 	__u32			frequency;
-	__u16			bit_rate;
+	__u32			bit_rate;
 	__u32			dev_frequency;
 
 	enum modulation		modulation;
drivers/staging/pi433/rf69.c +1 -1
index 8c7fab6a46bb..7e754a3aef5f 100644
@@ -185,7 +185,7 @@ 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;
drivers/staging/pi433/rf69.h +1 -1
index 78fa0b8bab8b..46a1fb2d5329 100644
@@ -24,7 +24,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);
Signature · 1 line
2.34.1

I sent (almost) the exact same patch a while ago. I received a reply saying that doing this is not possible. That conversation can still be found here:
https://lore.kernel.org/linux-staging/[email protected]/t/#u

Best regards,
Nam