All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Oscar Carter <oscar.carter@gmx.com>
Cc: Forest Bond <forest@alittletooquiet.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Malcolm Priestley <tvboxspy@gmail.com>,
	devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC] staging: vt6656: Add formula to the vnt_rf_addpower function
Date: Tue, 14 Apr 2020 16:12:14 +0300	[thread overview]
Message-ID: <20200414131214.GI1163@kadam> (raw)
In-Reply-To: <20200413140209.4520-1-oscar.carter@gmx.com>

On Mon, Apr 13, 2020 at 04:02:09PM +0200, Oscar Carter wrote:
> 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;

Just use "int".  s32 is for when signed 32 bit is specified in the
hardware.  I realize that it's done in this file, but if all your
friends jumped off a bridge doesn't mean you should drink their kool-aid.

>  	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;
                       ^^^^^^
I quite hate this postop.  It would have been cleaner to write it like:

	return (rssi < base) ? ((rssi - (base - 1)) / -5) * 2 + 5 : 0

I'm sorry, I'm not clever enough to figure out the potential values of
"rssi".  How did you work out this formula?  It feels like it came from
a standard or something?  Do we not have a function already which
implements the standard?

regards,
dan carpenter


  reply	other threads:[~2020-04-14 13:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2020-04-15 16:25   ` Oscar Carter
2020-04-20 16:18     ` Oscar Carter

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=20200414131214.GI1163@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=forest@alittletooquiet.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oscar.carter@gmx.com \
    --cc=tvboxspy@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.