Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp2719316rdh; Sun, 26 Nov 2023 17:14:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IHw7cNhDV0AWHz2OXOge0BGsHSxC1pXqiFjh7vb62NcI/AvwR7y4K1fAMWvHDRDGSRXcbVY X-Received: by 2002:a81:8083:0:b0:5cd:ad4:16dd with SMTP id q125-20020a818083000000b005cd0ad416ddmr10575329ywf.45.1701047675275; Sun, 26 Nov 2023 17:14:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701047675; cv=none; d=google.com; s=arc-20160816; b=X8FUUOPMser+7koQmSWfIhL1nOKf0/eLDKV1xKtYX0yfvmsn72AzlbD43iVmTuErJd XpxXtFm9vkBBWNBcjeDYtcYFxEsFtsNOqZhlxXXerEiAXpf7RzzWWP0GEtCheMlrhaYE cmXYlqNQjuQ9ZyD4QN3aVlf/J9YTHLyUJCzZAqZdmmpXrCxKVkUmEW9qMdJJJ9CeU7bN imRM70lHMM9e2oCxAqbwCA1owhroC9VDroALiluXEuF/2ksYlBTaPDD49/4YsvE3U6Wc EwpVFRcpM6NVAgG06eZmp3WjpaJkfIjYgrM1EvJm6N5kOdF8xPQNNM7J8cPsfJFbFmk1 tWAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:cc:to:content-language :subject:user-agent:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:date:message-id; bh=eKBvU1fVswAvtosToOJ010hP4f5xZO2fxTYVWzNixUY=; fh=9Y9PX8PWlAixMlUSf1IsHttp3KvJQXfjPGDPuRp0xOg=; b=knTyouyeMQL4KX6vPq9pFzykWLrftb6QqSuH4wt3tBJlK7me3BSAE+ECTqsO80SUz6 e3SBwRnJMDfVq+AajuVLMWffKQhsR4LW7xZMKSWRqaVWRpmfJ8WpB/Vo2ds2SoYmGBnZ J5fUrBqifyqkkvK74hnbb/eZ3ux4r2gKFdKnl/3bnA2bvwe1DRFyTjjX58cS2dX8YzKg LgPh40SVnJrxc4oIhVy5KKwxbxndX2TMZSzDtD7ShOUWcq+2rPzJUH4QZDt/lU2U1lm/ x0JBL4Sqnk/cnDLC0PycLiKe7PiUAa+Cru7JlW/QDaeg/HRUV0gmoDkQVSd+6p22/RjP ctAw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless+bounces-85-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-wireless+bounces-85-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id f6-20020a0cc306000000b0067a0713166bsi3247957qvi.323.2023.11.26.17.14.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 17:14:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless+bounces-85-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless+bounces-85-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-wireless+bounces-85-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id EDF681C20839 for ; Mon, 27 Nov 2023 01:14:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BD461EBD; Mon, 27 Nov 2023 01:14:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=none X-Original-To: linux-wireless@vger.kernel.org Received: from mail.nfschina.com (unknown [42.101.60.195]) by lindbergh.monkeyblade.net (Postfix) with SMTP id CCC2710F; Sun, 26 Nov 2023 17:14:27 -0800 (PST) Received: from [172.30.11.106] (unknown [180.167.10.98]) by mail.nfschina.com (Maildata Gateway V2.8.8) with ESMTPSA id 8DFB16018B8D8; Mon, 27 Nov 2023 09:13:41 +0800 (CST) Message-ID: <1bec6c93-aac4-eb95-f4f6-7b8fac65d967@nfschina.com> Date: Mon, 27 Nov 2023 09:13:09 +0800 Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH v2 2/2] wifi: rtlwifi: rtl8821ae: phy: fix an undefined bitwise shift behavior Content-Language: en-US To: Ping-Ke Shih , "kvalo@kernel.org" , "nathan@kernel.org" , "ndesaulniers@google.com" , "dan.carpenter@linaro.org" , "trix@redhat.com" Cc: "linux-wireless@vger.kernel.org" , "kernel-janitors@vger.kernel.org" , "Larry.Finger@lwfinger.net" , "llvm@lists.linux.dev" , "linville@tuxdriver.com" , "linux-kernel@vger.kernel.org" , "lizetao1@huawei.com" X-MD-Sfrom: suhui@nfschina.com X-MD-SrcIP: 180.167.10.98 From: Su Hui In-Reply-To: <02f0a505b3a02a3c5e29ac1e327acd1fc946188c.camel@realtek.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2023/11/24 19:19, Ping-Ke Shih wrote: > On Fri, 2023-11-24 at 18:06 +0800, Su Hui wrote: >> On 2023/11/24 16:51, Ping-Ke Shih wrote: >>> Subject: [PATCH v2 2/2] wifi: rtlwifi: rtl8821ae: phy: fix an undefined bitwise shift behavior >>> >>> [...] >>>> diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c >>>> b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c >>>> index 6df270e29e66..52ab1b0761c0 100644 >>>> --- a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c >>>> +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c >>>> @@ -31,7 +31,12 @@ static u32 _rtl8821ae_phy_calculate_bit_shift(u32 bitmask) >>>> { >>>> u32 i = ffs(bitmask); >>>> >>>> - return i ? i - 1 : 32; >>>> + if (!i) { >>>> + WARN_ON_ONCE(1); >>>> + return 0; >>>> + } >>>> + >>>> + return i - 1; >>>> } >>> Personally, I prefer to use __ffs(), because in normal case no need additional '-1', >>> and abnormal cases should not happen. >> Hi, Ping-Ke >> >> Replace _rtl8821ae_phy_calculate_bit_shift() by __ffs(bitmask) is better, >> but I'm not sure what callers should do when callers check bitmask is 0 before calling. >> Maybe this check is useless? >> >> I can send a v3 patch if using __ffs(bitmask) and no check for bitmask is fine. >> Or could you send this patch if you have a better idea? >> Thanks for your suggestion! >> > Can this work to you? Looks good to me, briefer and better! I will send v3 soon. > static u32 _rtl8821ae_phy_calculate_bit_shift(u32 bitmask) > { > if (WARN_ON_ONCE(!bitmask)) > return 0; > > return __ffs(bitmask); > }