From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1963FC4360F for ; Tue, 26 Feb 2019 00:03:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C88BC218B0 for ; Tue, 26 Feb 2019 00:03:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lca.pw header.i=@lca.pw header.b="PJJsUkox" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729220AbfBZADk (ORCPT ); Mon, 25 Feb 2019 19:03:40 -0500 Received: from mail-qt1-f195.google.com ([209.85.160.195]:43446 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727529AbfBZADj (ORCPT ); Mon, 25 Feb 2019 19:03:39 -0500 Received: by mail-qt1-f195.google.com with SMTP id y4so12844232qtc.10 for ; Mon, 25 Feb 2019 16:03:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lca.pw; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=nTyz3nhhRJAnQKCmBEdqx7AWOxz2VXU5sIgb32iHM/w=; b=PJJsUkox6+CF/dkHN/mWvihVRBMQXaHtCiEK3yJYAb26Tnfg3gdEmPvv/P7OJSRryw EwoaelNhNXnt48CV6HmkElLK/lu0JFMFftzxEkZbHBXWOO/u4FrvWRouZOm2jiDUMDK+ 8t6zAp0mzvSZYCxIae8QNfmbe1iV1FXNJ+J6XXCXi6wiK2VDHqFxNAAYEWH5XEqm7Nsn 9wcxN8A9r66KZTvMxvKt0fX1Fv/jQrIRUNQVcBefS6kjMtPnlv8uLO8iwOeIprTMyG/u cyc70TkE9lmuapdwSWKEFkF9aSaZB1N1gFpyD/yCaAdnI18EaAm9qdFR8A0Z/GXzDCEq 6BCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=nTyz3nhhRJAnQKCmBEdqx7AWOxz2VXU5sIgb32iHM/w=; b=NSFfVx/1s/NRwPmTF2+dKSLsffT7Hi1mo0ZvVvTlYurUHtQdssVdN3mODRHe3S/FDH AnjiP7jmSNjLPklIqAxTXKllzv9hImS0NMrBTwn2mpBSb2LUA803dcf1KtflIsXK6If7 oVAlITc/CGuOKe5z2oQk/WyLsaHyikXS3qaAZ6NmHpveI5ITBhCoK3hz950TqnoHAjhF Bvi9dE8CRpbmPBbzilm5UFNE07YqO5qw5006BJXebaxdJA/CfTqVro/4xfIh5f0W675c 8oyy1SGLyvGYwdbU0r9kONo5Vlk8JMg9uqdls2XygODslZDa7mYFEVcisOOxIS/ewXQJ ovZw== X-Gm-Message-State: AHQUAuYlIoDRvBNCfmU/jJQ4Y/uKAKI21QAHdg6I6QXDEEZbZ5SQrvv7 vxecdWNwVN1E3LD44FaRAFlwLg== X-Google-Smtp-Source: AHgI3IY3Rv9382UHR/eB55SAV2oFmZhY4NP5S3bSRzOz/Z3hwV7neRHhA0HwE0IAIdN7HevRouSW8Q== X-Received: by 2002:ac8:1e15:: with SMTP id n21mr16392133qtl.342.1551139418281; Mon, 25 Feb 2019 16:03:38 -0800 (PST) Received: from ovpn-120-150.rdu2.redhat.com (pool-71-184-117-43.bstnma.fios.verizon.net. [71.184.117.43]) by smtp.gmail.com with ESMTPSA id z140sm6241992qka.81.2019.02.25.16.03.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Feb 2019 16:03:37 -0800 (PST) Subject: Re: [PATCH] tmpfs: fix uninitialized return value in shmem_link To: Linus Torvalds , Hugh Dickins Cc: "Darrick J. Wong" , Andrew Morton , Matej Kupljen , Al Viro , Dan Carpenter , Linux List Kernel Mailing , linux-fsdevel , Linux-MM References: <20190221222123.GC6474@magnolia> From: Qian Cai Message-ID: <86649ee4-9794-77a3-502c-f4cd10019c36@lca.pw> Date: Mon, 25 Feb 2019 19:03:36 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.3.3 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On 2/25/19 6:58 PM, Linus Torvalds wrote: > On Mon, Feb 25, 2019 at 2:34 PM Linus Torvalds > wrote: >> >> On Mon, Feb 25, 2019 at 12:34 PM Hugh Dickins wrote: >>> >>> Seems like a gcc bug? But I don't have a decent recent gcc to hand >>> to submit a proper report, hope someone else can shed light on it. >> >> I don't have a _very_ recent gcc either [..] > > Well, that was quick. Yup, it's considered a gcc bug. > > Sadly, it's just a different version of a really old bug: > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=18501 > > which goes back to 2004. > > Which I guess means we should not expect this to be fixed in gcc any time soon. > > The *good* news (I guess) is that if we have other situations with > that pattern, and that lack of warning, it really is because gcc will > have generated code as if it was initialized (to the value that we > tested it must have been in the one basic block where it *was* > initialized). > > So it won't leak random kernel data, and with the common error > condition case (like in this example - checking that we didn't have an > error) it will actually end up doing the right thing. > > Entirely by mistake, and without a warniing, but still.. It could have > been much worse. Basically at least for this pattern, "lack of > warning" ends up meaning "it got initialized to the expected value". > > Of course, that's just gcc. I have no idea what llvm ends up doing. > Clang 7.0: # clang -O2 -S -Wall /tmp/test.c /tmp/test.c:46:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized] if (inode->i_nlink) { ^~~~~~~~~~~~~~ /tmp/test.c:60:9: note: uninitialized use occurs here return ret; ^~~ /tmp/test.c:46:2: note: remove the 'if' if its condition is always true if (inode->i_nlink) { ^~~~~~~~~~~~~~~~~~~~ /tmp/test.c:37:9: note: initialize the variable 'ret' to silence this warning int ret; ^ = 0 1 warning generated.