Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2767943rwb; Mon, 7 Nov 2022 18:10:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf5g/0OAb6zpOE7KF2Bi5e5MahxJFn9Unj6D1ZAzjvh0QcXFSbxleHiS7GJPa8Uj5pN2RYF3 X-Received: by 2002:a05:6402:11c7:b0:462:549d:fbbe with SMTP id j7-20020a05640211c700b00462549dfbbemr12727792edw.199.1667873399842; Mon, 07 Nov 2022 18:09:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667873399; cv=none; d=google.com; s=arc-20160816; b=qxb8lMTdXcNlJC9nhhBqSklyHdb+boArEvuuGOvw1d/TaMyDTCYYos2tmbEj9HKc49 bPM6RMJbJy31f3GQ0Zqr82I978ZKF0fNLho24HFKx0fobFuNnZEf5ZktiFv1uRViBDY2 pixcC/xMpXp5ujJ4Q4VcGifso5nz8pG5UcQjcElvddrmEdsw7w7JYA1AE7hpPgYPA6As SP4b9zUz9xMKypLKtr07Jm+g1uZ1Qu52huo57+PKu+37TOO1akKpvA7WSfvGAmXarwPo 1ePNSd4p+XwhJvaiy5sZerJeqiLeNMAkU9rZjyYJbhOG7I5fUz1AFgIwDgXuVoQjvaQK rbHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:authenticated-by; bh=zulNw6D+yzJVhVov6pFgcB6f+pZU37UH6Ok+m4DpFQE=; b=PLcL2/QsiLUAKivmjZS2YgrKGOP+5s2K0YpTQPzjZokC8NELnfTt4R9pxbcX3l67C+ 8lQ/7UzD3RWwj4L8DQXQMKToDRCwDbotXVKxuJOYCqUsUosFFJJ4KLwb0im0CDJWNVHj RRanA6uSV99UQv0L8P4HvD5W8DhwBqMmvV7XWb7jRzznUTMy9LHHxqlHo4hqGBZGI0Hq qA/EHqYhgDwZhLPHIPWUKg1gSWhKX/a4vJxzUtKKVhlDbXzWliLOzOiS/qHSHaFmobmZ s2lSE8F86LCyHqANXEunkn08EQs0E3M1Ns2O5HHvdiOSmkw5/cTLju92wQqLsKreVJ3I RzOA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r9-20020a05640251c900b0045c97ee2b01si13163715edd.616.2022.11.07.18.09.42; Mon, 07 Nov 2022 18:09:59 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233352AbiKHBjl (ORCPT + 67 others); Mon, 7 Nov 2022 20:39:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229534AbiKHBjk (ORCPT ); Mon, 7 Nov 2022 20:39:40 -0500 Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id ED47D193CC for ; Mon, 7 Nov 2022 17:39:39 -0800 (PST) Authenticated-By: X-SpamFilter-By: ArmorX SpamTrap 5.77 with qID 2A81cs7lB005686, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (rtexh36505.realtek.com.tw[172.21.6.25]) by rtits2.realtek.com.tw (8.15.2/2.81/5.90) with ESMTPS id 2A81cs7lB005686 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=FAIL); Tue, 8 Nov 2022 09:38:54 +0800 Received: from RTEXMBS04.realtek.com.tw (172.21.6.97) by RTEXH36505.realtek.com.tw (172.21.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.32; Tue, 8 Nov 2022 09:39:32 +0800 Received: from localhost (172.21.69.188) by RTEXMBS04.realtek.com.tw (172.21.6.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Tue, 8 Nov 2022 09:39:31 +0800 From: Ping-Ke Shih To: CC: Subject: [PATCH v2] wifi: rtw89: use u32_encode_bits() to fill MAC quota value Date: Tue, 8 Nov 2022 09:38:58 +0800 Message-ID: <20221108013858.10806-1-pkshih@realtek.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [172.21.69.188] X-ClientProxiedBy: RTEXMBS02.realtek.com.tw (172.21.6.95) To RTEXMBS04.realtek.com.tw (172.21.6.97) X-KSE-ServerInfo: RTEXMBS04.realtek.com.tw, 9 X-KSE-AntiSpam-Interceptor-Info: trusted connection X-KSE-Antiphishing-Info: Clean X-KSE-Antiphishing-ScanningType: Deterministic X-KSE-Antiphishing-Method: None X-KSE-Antiphishing-Bases: 11/08/2022 01:08:00 X-KSE-AttachmentFiltering-Interceptor-Info: no applicable attachment filtering rules found X-KSE-Antivirus-Interceptor-Info: scan successful X-KSE-Antivirus-Info: =?big5?B?Q2xlYW4sIGJhc2VzOiAyMDIyLzExLzcgpFWkyCAxMDo1MDowMA==?= X-KSE-BulkMessagesFiltering-Scan-Result: protection disabled X-KSE-ServerInfo: RTEXH36505.realtek.com.tw, 9 X-KSE-Attachment-Filter-Triggered-Rules: Clean X-KSE-Attachment-Filter-Triggered-Filters: Clean X-KSE-BulkMessagesFiltering-Scan-Result: protection disabled X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Coverity reported shift 16 bits could cause sign extension and might get an unexpected value. Since the input values are predefined and no this kind of case, original code is safe so far. But, still changing them to use u32_encode_bits() will be more clear and prevent mistakes in the future. The original message of Coverity is: Suspicious implicit sign extension: "max_cfg->cma0_dma" with type "u16" (16 bits, unsigned) is promoted in "max_cfg->cma0_dma << 16" to type "int" (32 bits, signed), then sign-extended to type "unsigned long" (64 bits, unsigned). If "max_cfg->cma0_dma << 16" is greater than 0x7FFFFFFF, the upper bits of the result will all be 1." Reported-by: coverity-bot Addresses-Coverity-ID: 1527095 ("Integer handling issues") Fixes: e3ec7017f6a2 ("rtw89: add Realtek 802.11ax driver") Signed-off-by: Ping-Ke Shih --- drivers/net/wireless/realtek/rtw89/mac.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/mac.c b/drivers/net/wireless/realtek/rtw89/mac.c index bb49033b587d2..814ca4bc22587 100644 --- a/drivers/net/wireless/realtek/rtw89/mac.c +++ b/drivers/net/wireless/realtek/rtw89/mac.c @@ -1487,10 +1487,8 @@ static int dle_mix_cfg(struct rtw89_dev *rtwdev, const struct rtw89_dle_mem *cfg #define INVALID_QT_WCPU U16_MAX #define SET_QUOTA_VAL(_min_x, _max_x, _module, _idx) \ do { \ - val = ((_min_x) & \ - B_AX_ ## _module ## _MIN_SIZE_MASK) | \ - (((_max_x) << 16) & \ - B_AX_ ## _module ## _MAX_SIZE_MASK); \ + val = u32_encode_bits(_min_x, B_AX_ ## _module ## _MIN_SIZE_MASK) | \ + u32_encode_bits(_max_x, B_AX_ ## _module ## _MAX_SIZE_MASK); \ rtw89_write32(rtwdev, \ R_AX_ ## _module ## _QTA ## _idx ## _CFG, \ val); \ -- 2.25.1