Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp18860042rwd; Wed, 28 Jun 2023 01:28:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5PNYVUmSAVUhGRU3z/djQbqKnQTEOvBPOrEkE7k+ULJaztMq5jEVdyx9XXPwk8AbR5hfL2 X-Received: by 2002:a17:907:94c9:b0:989:3e0d:89fb with SMTP id dn9-20020a17090794c900b009893e0d89fbmr21340918ejc.45.1687940892611; Wed, 28 Jun 2023 01:28:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687940892; cv=none; d=google.com; s=arc-20160816; b=zny/CLXnJNak+CUugq5svPyhZ4AEY8hsX2IfRW0ZbjZjsmO0RM3BKmLdbiS0kcKMc2 jXjI4XEMBxksZ64uk0+1ygldBlx5z4VMRl48KzAtMomLUK1ylvbH35VPBsotkdOvRhwj xoIfyCtrrSuOIIUdGgxGpSil0FyTiVx+D38CZavKECiqmblTvWCPZlDldAwIqPOZOcQE A9i8fREmRNmSYBfKeZpj3CEZTcQ6ioxI0xJr+95bmzSGDH8ko0MREmSYqnUk6uxBdNWF CkaIjUao5yg82h/c/5sNyER5wUYTEoqz1EY3Mk+d6zSiSfMtzGcHCsLlGrARWwBB3JY9 AdaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=efDP95Izz7SORE2TUC/J6rZwcZ1El42ZOIqFFL+BuCY=; fh=H0332++GGX5cSgAulEjJ/S9eA9QMKKX31QrCC++KK1A=; b=qHYIiF5lFNXAmnwz5dGyJ9xAlsOnLjePJYPF0Xm4WCW0bQdeMpot7EzY4jF0lQrHfL yAAjT7Jah7Bk+/b4Hs6ZYRS0RvAXuJWWDOU78KwDrfIVOhj2VvsEIb04t4W5Rpk5Q/nG mrrvGstwsWsZ0cYT2qd7/v06SVQJLDa4s32BTK/PiKAhDRGgXxgYR27KiaAPY/bIdZN4 PFRS25t4ixD55wrKLJTgFv2Pq6XQhqhaJrq0e+WOFKYG1gr/OnFR0s9XTAz82XqfbDFX I5tMdIJ2E2H5AmxpHjbb6/i9teh/vwGegLtYHJSHovZ7/I0E6xcBdNCT3CFbwsKeBSK6 /a/Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l22-20020a170906079600b0098eb8b70f32si3990212ejc.213.2023.06.28.01.27.57; Wed, 28 Jun 2023 01:28:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234031AbjF1I1I convert rfc822-to-8bit (ORCPT + 58 others); Wed, 28 Jun 2023 04:27:08 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([185.58.85.151]:23422 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234027AbjF1IZA (ORCPT ); Wed, 28 Jun 2023 04:25:00 -0400 Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-128-vlZ0-3KkNdaZvqYiTvu37Q-1; Wed, 28 Jun 2023 09:24:56 +0100 X-MC-Unique: vlZ0-3KkNdaZvqYiTvu37Q-1 Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Wed, 28 Jun 2023 09:24:55 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Wed, 28 Jun 2023 09:24:55 +0100 From: David Laight To: 'Dmitry Antipov' , Larry Finger CC: "linux-wireless@vger.kernel.org" , "Kalle Valo" , Jonas Gorski , "lvc-project@linuxtesting.org" , "stable@vger.kernel.org" Subject: RE: [PATCH] [v2] wifi: b43: fix cordic arithmetic Thread-Topic: [PATCH] [v2] wifi: b43: fix cordic arithmetic Thread-Index: AQHZqQsGGmQjvdKBv0W33H1tLjOZ1K+f3QLw Date: Wed, 28 Jun 2023 08:24:55 +0000 Message-ID: References: <20230627151411.92749-1-dmantipov@yandex.ru> In-Reply-To: <20230627151411.92749-1-dmantipov@yandex.ru> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org 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 > Signed-off-by: Dmitry Antipov > --- > 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)