linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] staging: vt6656: Add formula to the vnt_rf_addpower function
@ 2020-04-23 17:05 Oscar Carter
  2020-04-25 10:57 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Oscar Carter @ 2020-04-23 17:05 UTC (permalink / raw)
  To: Forest Bond, Greg Kroah-Hartman
  Cc: Dan Carpenter, Oscar Carter, Malcolm Priestley,
	Quentin Deslandes, 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>
---
Changelog v1 -> v2
- Change the type of "base" variable from s32 to int as Dan Carpenter
  suggested.
- Remove the "--" postoperator and replace with (base - 1) as Dan
  Carpenter suggested. Also, as this expression has a minus before the
  parenthesis, remove it an apply the minus operator changing the sign of
  "base" and literal "1".

 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 06fa8867cfa3..612fd4a59f8a 100644
--- a/drivers/staging/vt6656/rf.c
+++ b/drivers/staging/vt6656/rf.c
@@ -538,28 +538,14 @@ int vnt_rf_write_embedded(struct vnt_private *priv, u32 data)

 static u8 vnt_rf_addpower(struct vnt_private *priv)
 {
+	int 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 + 1) / -5) * 2 + 5 : 0;
 }

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


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

* Re: [PATCH v2] staging: vt6656: Add formula to the vnt_rf_addpower function
  2020-04-23 17:05 [PATCH v2] staging: vt6656: Add formula to the vnt_rf_addpower function Oscar Carter
@ 2020-04-25 10:57 ` Greg Kroah-Hartman
  2020-04-25 14:02   ` Oscar Carter
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2020-04-25 10:57 UTC (permalink / raw)
  To: Oscar Carter
  Cc: Forest Bond, devel, Malcolm Priestley, linux-kernel, Dan Carpenter

On Thu, Apr 23, 2020 at 07:05:57PM +0200, Oscar Carter wrote:
> 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>
> ---
> Changelog v1 -> v2
> - Change the type of "base" variable from s32 to int as Dan Carpenter
>   suggested.
> - Remove the "--" postoperator and replace with (base - 1) as Dan
>   Carpenter suggested. Also, as this expression has a minus before the
>   parenthesis, remove it an apply the minus operator changing the sign of
>   "base" and literal "1".
> 
>  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 06fa8867cfa3..612fd4a59f8a 100644
> --- a/drivers/staging/vt6656/rf.c
> +++ b/drivers/staging/vt6656/rf.c
> @@ -538,28 +538,14 @@ int vnt_rf_write_embedded(struct vnt_private *priv, u32 data)
> 
>  static u8 vnt_rf_addpower(struct vnt_private *priv)
>  {
> +	int 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 + 1) / -5) * 2 + 5 : 0;

I _hate_ ? : functions, just spell this out please as a real if()
statement.

thanks,

greg k-h

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

* Re: [PATCH v2] staging: vt6656: Add formula to the vnt_rf_addpower function
  2020-04-25 10:57 ` Greg Kroah-Hartman
@ 2020-04-25 14:02   ` Oscar Carter
  0 siblings, 0 replies; 3+ messages in thread
From: Oscar Carter @ 2020-04-25 14:02 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Oscar Carter, Forest Bond, devel, Malcolm Priestley,
	linux-kernel, Dan Carpenter

On Sat, Apr 25, 2020 at 12:57:14PM +0200, Greg Kroah-Hartman wrote:
> On Thu, Apr 23, 2020 at 07:05:57PM +0200, Oscar Carter wrote:
> > 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>
> > ---
> > Changelog v1 -> v2
> > - Change the type of "base" variable from s32 to int as Dan Carpenter
> >   suggested.
> > - Remove the "--" postoperator and replace with (base - 1) as Dan
> >   Carpenter suggested. Also, as this expression has a minus before the
> >   parenthesis, remove it an apply the minus operator changing the sign of
> >   "base" and literal "1".
> >
> >  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 06fa8867cfa3..612fd4a59f8a 100644
> > --- a/drivers/staging/vt6656/rf.c
> > +++ b/drivers/staging/vt6656/rf.c
> > @@ -538,28 +538,14 @@ int vnt_rf_write_embedded(struct vnt_private *priv, u32 data)
> >
> >  static u8 vnt_rf_addpower(struct vnt_private *priv)
> >  {
> > +	int 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 + 1) / -5) * 2 + 5 : 0;
>
> I _hate_ ? : functions, just spell this out please as a real if()
> statement.
>
Ok, I will do the modification and I will resend a new version patch.

> thanks,
>
> greg k-h

thanks,

oscar carter

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

end of thread, other threads:[~2020-04-25 14:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-23 17:05 [PATCH v2] staging: vt6656: Add formula to the vnt_rf_addpower function Oscar Carter
2020-04-25 10:57 ` Greg Kroah-Hartman
2020-04-25 14:02   ` Oscar Carter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).