Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp963272rdh; Fri, 24 Nov 2023 02:06:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IGCyTDDepc/kVxHP1j7Xuf3hhvTw1IqKtRXQ0bo3ophUHsjWMfbvpaKVH33icK5y19s5riQ X-Received: by 2002:a05:622a:5:b0:423:74c4:2cc0 with SMTP id x5-20020a05622a000500b0042374c42cc0mr2474387qtw.59.1700820384893; Fri, 24 Nov 2023 02:06:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700820384; cv=none; d=google.com; s=arc-20160816; b=plUMy/4I4sQueyznllVzMDfSEbDEEBRvd01ihyIQ7bPdZAv3tb1BfsGtx+jrlFIzTx CCtktjzYg57HacaoYuEWmzk81AYIiKKvg2VjofG02CqndzjrhS2o9kxzB4lPQJcTMOSt cxJbuFHJHEJ3vZx/DiYX47jFra8Oc2jkFN3y1BuObhkG/m71pNi+iHx1WWhts2i3PLzd L/rCBbgzkIgwpnrNDY5IIiONlR8/oRaYZpCPvyDaZfcoAQmBcOcJ0X7dX7AJPJpkUxkI RHK420UTsX7pNCNasvabbU6UL9O9zMNfhit3pFM5+1eoxUR6CFHaFYA9RtmKgznHkpFR R1wQ== 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=ktE7BjSjny4rmvbFmN+8OF31/5wZYBQsjMufwLcJEto=; fh=DHV+PtXc9qOXNf2I9cjdP4/g1CflmWq1XJfIlLkxomY=; b=drhIm8H6uLACoxv/Me6fvFfVyj/NaTtZzn79DIoPvUbR9o0StuyJnUfbWzBoz1FLwT gC1BnkB64iHljdV4KWlI75Lt4GKKp0sKv8+nxdzccJ2cFjIcQiz67pqctQyj9f/5DODK uxF7GX3H609DuChk1gxKDpg6/DIHs2yKoWPvQXP+aQ1stFd0BT2RWk+RbNQ0czl5Bk+V JqliBa8NuujR7TWzvThSeBrrVmHKiETAiSJqpeZbybPbG/41mEfeRomsh56g3AHac7nO crX1PKyQTU36/06TjUlFOBewoO9OdJhNKN4w/f8Y18PrURARBqlsISw7qDTHsJwldeMI uHHg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless+bounces-47-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-wireless+bounces-47-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id cc13-20020a05622a410d00b004239007a0ebsi2500240qtb.119.2023.11.24.02.06.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 02:06:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless+bounces-47-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless+bounces-47-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-wireless+bounces-47-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 A54FC1C20A13 for ; Fri, 24 Nov 2023 10:06:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2C48A1803D; Fri, 24 Nov 2023 10:06:21 +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 05156D73; Fri, 24 Nov 2023 02:06:15 -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 35883613FF940; Fri, 24 Nov 2023 18:06:12 +0800 (CST) Message-ID: Date: Fri, 24 Nov 2023 18:06:11 +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 , "dan.carpenter@linaro.org" , "kvalo@kernel.org" , "nathan@kernel.org" , "ndesaulniers@google.com" , "trix@redhat.com" Cc: "lizetao1@huawei.com" , "linville@tuxdriver.com" , "Larry.Finger@lwfinger.net" , "linux-wireless@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "llvm@lists.linux.dev" , "kernel-janitors@vger.kernel.org" X-MD-Sfrom: suhui@nfschina.com X-MD-SrcIP: 180.167.10.98 From: Su Hui In-Reply-To: <167fbc7a77db447d90f696666f6f0a9b@realtek.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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! Su Hui