public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC] staging: vt6656: Add formula to the vnt_rf_addpower function
@ 2020-04-13 14:02 Oscar Carter
  2020-04-14 13:12 ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Oscar Carter @ 2020-04-13 14:02 UTC (permalink / raw)
  To: Forest Bond, Greg Kroah-Hartman
  Cc: Quentin Deslandes, Oscar Carter, Malcolm Priestley, devel,
	linux-kernel

Use a formula to calculate the return value of the vnt_rf_addpower
function instead of the "if" statement with literal values for every
case.

Signed-off-by: Oscar Carter <oscar.carter@gmx.com>
---
What is the better approach for this function ? Leave it as is or use
a formula although it is less clear.

I prefer the formula as it is a more compact function.
What do you think ? Feedback wellcome.

Thanks,
Oscar Carter

 drivers/staging/vt6656/rf.c | 20 +++-----------------
 1 file changed, 3 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/vt6656/rf.c b/drivers/staging/vt6656/rf.c
index 4f9aba0f21b0..3b200d7290a5 100644
--- a/drivers/staging/vt6656/rf.c
+++ b/drivers/staging/vt6656/rf.c
@@ -575,28 +575,14 @@ int vnt_rf_setpower(struct vnt_private *priv, u32 rate, u32 channel)

 static u8 vnt_rf_addpower(struct vnt_private *priv)
 {
+	s32 base;
 	s32 rssi = -priv->current_rssi;

 	if (!rssi)
 		return 7;

-	if (priv->rf_type == RF_VT3226D0) {
-		if (rssi < -70)
-			return 9;
-		else if (rssi < -65)
-			return 7;
-		else if (rssi < -60)
-			return 5;
-	} else {
-		if (rssi < -80)
-			return 9;
-		else if (rssi < -75)
-			return 7;
-		else if (rssi < -70)
-			return 5;
-	}
-
-	return 0;
+	base = (priv->rf_type == RF_VT3226D0) ? -60 : -70;
+	return (rssi < base--) ? ((rssi - base) / -5) * 2 + 5 : 0;
 }

 /* Set Tx power by power level and rate */
--
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-04-20 16:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-13 14:02 [RFC] staging: vt6656: Add formula to the vnt_rf_addpower function Oscar Carter
2020-04-14 13:12 ` Dan Carpenter
2020-04-15 16:25   ` Oscar Carter
2020-04-20 16:18     ` Oscar Carter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox