Linux wireless drivers development
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Dmitry Antipov' <dmantipov@yandex.ru>,
	Larry Finger <Larry.Finger@lwfinger.net>
Cc: "linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>,
	"Kalle Valo" <kvalo@kernel.org>,
	Jonas Gorski <jonas.gorski@gmail.com>,
	"lvc-project@linuxtesting.org" <lvc-project@linuxtesting.org>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: RE: [PATCH] [v2] wifi: b43: fix cordic arithmetic
Date: Wed, 28 Jun 2023 08:24:55 +0000	[thread overview]
Message-ID: <d0825edd2a3c4bbba72685340f547c9e@AcuMS.aculab.com> (raw)
In-Reply-To: <20230627151411.92749-1-dmantipov@yandex.ru>

From: Dmitry Antipov
> Sent: 27 June 2023 16:14
> 
> In 'lpphy_start_tx_tone()', 'CORDIC_FLOAT((sample.i * max) & 0xFF)'
> is invalid because it is (<32-bit> & 0xff) shifted right by 15 bits
> and so always evaluates to zero. Looking through brcmsmac's
> 'wlc_lcnphy_start_tx_tone()', the result should be masked instead,
> i. e. 'CORDIC_FLOAT(sample[i].max) & 0xFF'.
> 
> Fixes: 6f98e62a9f1b ("b43: update cordic code to match current specs")
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Cc: stable@vger.kernel.org
> Suggested-by: Jonas Gorski <jonas.gorski@gmail.com>
> Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
> ---
> v2: add Cc: stable and Fixes: (Larry Finger)
> ---
>  drivers/net/wireless/broadcom/b43/phy_lp.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/wireless/broadcom/b43/phy_lp.c b/drivers/net/wireless/broadcom/b43/phy_lp.c
> index 0e5c076e7544..e8ef04e509aa 100644
> --- a/drivers/net/wireless/broadcom/b43/phy_lp.c
> +++ b/drivers/net/wireless/broadcom/b43/phy_lp.c
> @@ -1788,8 +1788,8 @@ static void lpphy_start_tx_tone(struct b43_wldev *dev, s32 freq, u16 max)
>  	for (i = 0; i < samples; i++) {
>  		sample = cordic_calc_iq(CORDIC_FIXED(theta));
>  		theta += rotation;
> -		buf[i] = CORDIC_FLOAT((sample.i * max) & 0xFF) << 8;
> -		buf[i] |= CORDIC_FLOAT((sample.q * max) & 0xFF);
> +		buf[i] = (u16)((CORDIC_FLOAT(sample.i * max) & 0xFF) << 8);
> +		buf[i] |= (u16)(CORDIC_FLOAT(sample.q * max) & 0xFF);

What are the (u16) casts for?
This code is actually called exactly once with max == 100.
The .i and .q are the sine and cosine << 16 (signed).
The CORDIC_FLOAT() is basically >> 16 (not 15) so the result should
be between -100 and +100.
The & 0xFF is there to strip the sign.
The sin+cos are then packed into a short[] then unpacked to be
written to the hardware later.

>  	}
> 
>  	b43_lptab_write_bulk(dev, B43_LPTAB16(5, 0), samples, buf);

Don't open the bag of worms that contains the above :-)

	David

> --
> 2.41.0

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


  reply	other threads:[~2023-06-28  8:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-27 13:00 [PATCH] wifi: b43: fix cordic arithmetic Dmitry Antipov
2023-06-27 14:38 ` Larry Finger
2023-06-27 15:13   ` [PATCH] [v2] " Dmitry Antipov
2023-06-28  8:24     ` David Laight [this message]
2023-06-28 10:45       ` Dmitry Antipov
2023-06-28 13:19         ` David Laight

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=d0825edd2a3c4bbba72685340f547c9e@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=Larry.Finger@lwfinger.net \
    --cc=dmantipov@yandex.ru \
    --cc=jonas.gorski@gmail.com \
    --cc=kvalo@kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=stable@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox