Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1265524pxj; Fri, 4 Jun 2021 09:56:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxljboenHPeZLNYpaU1Gc0tH8z93yVM4VBinFQySU+kMhzoxGgL2Qg7bx0kWydSLyFEuCVT X-Received: by 2002:a17:906:7c02:: with SMTP id t2mr5152690ejo.0.1622825763206; Fri, 04 Jun 2021 09:56:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622825763; cv=none; d=google.com; s=arc-20160816; b=ZLd1siFfvFxTtDqgAV01OAnRVAlxB2aO22JLIUyUxe5anRrttj2G86K5lhgfsC45o0 DtFv9FZDzPAir/Mep9KIpwnOIz512c0M0NVdbrEfcPk3B14BB2pkBOk6kE+kZYEWNBiZ uOfVi13n+tMZEP1B/EV+mqoGI1DSGaPmut29gnDw5SZ/T+Ox1bEyNk6IsyDrGhAsfnlF tuEB041PXpcprIRxJ8BU9UMYQv8igyyFtPk+cwPZvcLruDqIr6sxuZBipzxue3NfPRwq qtBrUj4cm7rNkgTmAyLukx5NdnLZo4CLeVaHgdf3IgSNB6B/BsWy6P10QyaWrti/p4t0 1g5Q== 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 :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=dorOJhKfjiLW1AqnyT37bNgEdk5LtYJ5Ih/KIdssPJY=; b=Nm7tYaWZb+V9308FNP4wa83Iw8rrLqCB9cei++o3NyNjXrvm9jKr0z0cEzPkZwIdMf N7mUsbNy02k3Rzg+kSVDEG2YIDeBUeI8Bk3NpaZYPsTGd4P9F+I3Sd56Q7zPZkwUqhck csrYPAzgfvw8kMS8Kj6TcVl3SpvMnJllMErw4mKKKl/Z4FmK4xIILLZeBJzEKoYAG8Yt s9x6uh8b6PJz9da77ENKG3q63Ol4OEJwZpWvv17K4Zt2iaYm5UzsGHIPIf4Hm85jA0Pp TXN1pSU9dcba82Tfe1BMZPLXc4fn8Q2pSL1yvtaHErbJEShOWxW91Z+AlgYBQkxf7T3C mfwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VMcCoxmF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u19si5694197edo.409.2021.06.04.09.55.38; Fri, 04 Jun 2021 09:56:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VMcCoxmF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230037AbhFDQzu (ORCPT + 99 others); Fri, 4 Jun 2021 12:55:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:35448 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229791AbhFDQzu (ORCPT ); Fri, 4 Jun 2021 12:55:50 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4107A61287; Fri, 4 Jun 2021 16:54:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622825644; bh=mz6cIA1EIJyWfjzcdTql50qtZoFGmtGK88vnB2IoHAQ=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=VMcCoxmFGWNABY/u7NL4rbKbnwAXozcgMaJ3Erutzy7+POR/+zyFwIij+ifEXygTO q+j4KKJf+SO7nUQ+o7yga1yQ+nYBjq5/z0mKZLp1yvs1jOcLjuvn7KxTYVXWY9mN7q 01Ud4GHNFn/j86dKUSMRKcX+mlV0AZ7GBRF4sHBLQlqZqx2r9C8tMjgDUWyb862HCc Dh6jkM0gjo/V10ZhOs1IPi2vmvsSGf89ZzwZiAdCeMzQtwGWB/exj1gX5UIAoo1aIr cj/yUz8qqZwfHVEHGL6padxG0xukQbN30OEOnsgzdA/aYW43mj/4c2NixqEMWr0Jjn UNWlXfHoON4mw== Subject: Re: [PATCH net-next] net: ethernet: rmnet: Restructure if checks to avoid uninitialized warning To: subashab@codeaurora.org, patchwork-bot+netdevbpf@kernel.org Cc: stranche@codeaurora.org, davem@davemloft.net, kuba@kernel.org, ndesaulniers@google.com, sharathv@codeaurora.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com References: <20210603173410.310362-1-nathan@kernel.org> <162276000605.13062.14467575723320615318.git-patchwork-notify@kernel.org> <1f6f8246f0cd477c0b1e2b88b4ec825a@codeaurora.org> From: Nathan Chancellor Message-ID: <2145e27f-c8b3-ef4b-793a-841cb2f7e60f@kernel.org> Date: Fri, 4 Jun 2021 09:54:02 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: <1f6f8246f0cd477c0b1e2b88b4ec825a@codeaurora.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Subash, On 6/3/2021 10:15 PM, subashab@codeaurora.org wrote: > On 2021-06-03 16:40, patchwork-bot+netdevbpf@kernel.org wrote: >> Hello: >> >> This patch was applied to netdev/net-next.git (refs/heads/master): >> >> On Thu,  3 Jun 2021 10:34:10 -0700 you wrote: >>> Clang warns that proto in rmnet_map_v5_checksum_uplink_packet() might be >>> used uninitialized: >>> >>> drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c:283:14: warning: >>> variable 'proto' is used uninitialized whenever 'if' condition is false >>> [-Wsometimes-uninitialized] >>>                 } else if (skb->protocol == htons(ETH_P_IPV6)) { >>>                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >>> drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c:295:36: note: >>> uninitialized use occurs here >>>                 check = rmnet_map_get_csum_field(proto, trans); >>>                                                  ^~~~~ >>> drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c:283:10: note: >>> remove the 'if' if its condition is always true >>>                 } else if (skb->protocol == htons(ETH_P_IPV6)) { >>>                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >>> drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c:270:11: note: >>> initialize the variable 'proto' to silence this warning >>>                 u8 proto; >>>                         ^ >>>                          = '\0' >>> 1 warning generated. >>> >>> [...] >> >> Here is the summary with links: >>   - [net-next] net: ethernet: rmnet: Restructure if checks to avoid >> uninitialized warning >>     https://git.kernel.org/netdev/net-next/c/118de6106735 >> >> You are awesome, thank you! >> -- >> Deet-doot-dot, I am a bot. >> https://korg.docs.kernel.org/patchwork/pwbot.html > > Hi Nathan > > Can you tell why CLANG detected this error. > Does it require a bug fix. As far as I understand it, clang does not remember the conditions of previous if statements when generating this warning. Basically: void bar(int x) { } int foo(int a, int b) { int x; if (!a && !b) goto out; if (a) x = 1; else if (b) x = 2; bar(x); out: return 0; } clang will warn that x is uninitialized when neither of the second if statement's conditions are true, even though we as humans know that is not possible due to the first if statement. I am guessing this has something to do with how clang generates its control flow graphs. While this is a false positive, I do not personally see this as a bug in the compiler. The code is more clear to both the compiler and humans if it is written as: if (a) x = 1; else if (b) x = 2; else goto out; Cheers, Nathan