Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp877115rwi; Wed, 19 Oct 2022 04:12:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7jPDIx3QJu2LB+uWAQHJy13MNnCXL5+AEjzosbReAUqKp8dqkf/P0MiQHkV+chqwWYHk1B X-Received: by 2002:a05:6a00:234d:b0:561:ec04:e77e with SMTP id j13-20020a056a00234d00b00561ec04e77emr8170629pfj.14.1666177953896; Wed, 19 Oct 2022 04:12:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666177953; cv=none; d=google.com; s=arc-20160816; b=Ug0tumLPbzkQ9fhpfmmkRQtDD5r5VIgxPHsvXQkWYwkWe9AXJsPkPLhTApA7/9dm6+ kkdZbNISEtKvSZAkSCnRoQC/QsQmhIxJIki8xWItJnccUuABVSdeoCs8UoTAbrZfXf4l sBFpUj0eFng6Xz/vLQROzwV4QvGOPjFBxVn9OySCDOAFgUKAvuyODaOYuCcDvZ/4jaGc TzrmeL9PBk/U0guNbKZ83fIbm49IoQrX/aMEesguKNm5lcZvjKI+z0GJboi2sGceFB18 NyPfaOwd75A1mFulh4wzXh5TvSBrOw9CV6ujHaKr8QjidhEuao/cfTs0Yu8Nk1vxAdVt Fd3w== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CTeRUvJWkfXGble7UiMc6/n6FoijzHVjA4Q+mFTyZ/0=; b=OwE9rA/mmJA0vRTId1rlU52XbjET7AHlw5r2x8GHTt1Y+dBsJJFakSNvoTM53rQGoy xXhZpaFLdeuSaWmS274wlRPUB7+RkXgAgIhJrn2NrLh21YvSrDx84F3di9Gjt7lQ1SDj NAyR1f/9hI/01wiMNW5P2YOkxn2/1jHKCUCATeyEB7j/dwvRL10jXCPyf8wZ0oRMsckD rte3ojN/85vmVDZvZCm6o4nEBbVY4gleaANENSrZJbvpy6avgSvYr7/LCldMuZjlpBLM 9sjk7FAAu0L1NDUm5Y1iSsjerYiYPDJtjRbRA+FjsSkXE8ELWERPQ73wcI0a4iTPRFRe U2wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IDTwW+07; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x6-20020a170902ec8600b0017535568d5dsi21191960plg.256.2022.10.19.04.12.20; Wed, 19 Oct 2022 04:12:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IDTwW+07; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234702AbiJSK5h (ORCPT + 99 others); Wed, 19 Oct 2022 06:57:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234711AbiJSK4a (ORCPT ); Wed, 19 Oct 2022 06:56:30 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8A47D2CD5; Wed, 19 Oct 2022 03:27:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DF064B824A8; Wed, 19 Oct 2022 09:08:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B83CC433D6; Wed, 19 Oct 2022 09:08:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170504; bh=xtM5s+f3529j7nQlyo4YPIfMABIDOHknGrVRtsueMpY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IDTwW+07U3G+7kEbANJmwQ5E8u1Bg6O5yL5UpcH1ZMjS3VjdVMivFdP4Y4lOsAAXr 1b8QQm6WM9//uOpXhWjI52uyJN1vv4Wc4KhV5o10bLHP8oOkLfNzjtzdHRM2aVd/G3 yf5qUo/Idnkp6F+ZkvM3EM+QoKTFZY00gznAjWHI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zong-Zhe Yang , Ping-Ke Shih , Kalle Valo , Sasha Levin Subject: [PATCH 6.0 681/862] wifi: rtw88: phy: fix warning of possible buffer overflow Date: Wed, 19 Oct 2022 10:32:48 +0200 Message-Id: <20221019083320.063888989@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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-kernel@vger.kernel.org From: Zong-Zhe Yang [ Upstream commit 86331c7e0cd819bf0c1d0dcf895e0c90b0aa9a6f ] reported by smatch phy.c:854 rtw_phy_linear_2_db() error: buffer overflow 'db_invert_table[i]' 8 <= 8 (assuming for loop doesn't break) However, it seems to be a false alarm because we prevent it originally via if (linear >= db_invert_table[11][7]) return 96; /* maximum 96 dB */ Still, we adjust the code to be more readable and avoid smatch warning. Signed-off-by: Zong-Zhe Yang Signed-off-by: Ping-Ke Shih Signed-off-by: Kalle Valo Link: https://lore.kernel.org/r/20220727065003.28340-5-pkshih@realtek.com Signed-off-by: Sasha Levin --- drivers/net/wireless/realtek/rtw88/phy.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw88/phy.c b/drivers/net/wireless/realtek/rtw88/phy.c index 8982e0c98dac..da1efec0aa85 100644 --- a/drivers/net/wireless/realtek/rtw88/phy.c +++ b/drivers/net/wireless/realtek/rtw88/phy.c @@ -816,23 +816,18 @@ static u8 rtw_phy_linear_2_db(u64 linear) u8 j; u32 dB; - if (linear >= db_invert_table[11][7]) - return 96; /* maximum 96 dB */ - for (i = 0; i < 12; i++) { - if (i <= 2 && (linear << FRAC_BITS) <= db_invert_table[i][7]) - break; - else if (i > 2 && linear <= db_invert_table[i][7]) - break; + for (j = 0; j < 8; j++) { + if (i <= 2 && (linear << FRAC_BITS) <= db_invert_table[i][j]) + goto cnt; + else if (i > 2 && linear <= db_invert_table[i][j]) + goto cnt; + } } - for (j = 0; j < 8; j++) { - if (i <= 2 && (linear << FRAC_BITS) <= db_invert_table[i][j]) - break; - else if (i > 2 && linear <= db_invert_table[i][j]) - break; - } + return 96; /* maximum 96 dB */ +cnt: if (j == 0 && i == 0) goto end; -- 2.35.1