Received: by 2002:ac0:cd04:0:0:0:0:0 with SMTP id w4csp46643imn; Fri, 1 Jul 2022 09:37:26 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uBcnMIwC14BACFnqVbVk6xoyOQis3VBff7Akykp/Iy3ud9amc09XXFrz0EmaMj8BhR6zqG X-Received: by 2002:a50:ed8a:0:b0:435:6582:6864 with SMTP id h10-20020a50ed8a000000b0043565826864mr19782880edr.417.1656693446495; Fri, 01 Jul 2022 09:37:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656693446; cv=none; d=google.com; s=arc-20160816; b=LNZgQB0KkS6As6awm+PsOSm9Q84z28Q/SFmiWmxs3km8YxfFyYFD0Ie/6uSkKJAVnm XJKc7ELnpeeuHkBOJ3o4mdjHuaUH+x329R86U7h+D09HUAkkLogzXV2kxh8/0iYJTiq9 I9UHfxeAU3idUrzyYmFMFO0fGrHMnhpvb0AhbsMZ0oW839apNhUrDkTWGsHVp2Bwtxhz Sm6vbVNX5GI8sCnixtTpSPgf3MfgEaMb6Klz3A4u4LOuxuDX/p/QIl7HPl8Sv0kTyw9Q 93aBd2mdr4ImvfxxD4NvD6oFl9e6UneWgHjZV+R+1SVQ73TzC5la1qvMMgVlXL5/w0oq M7Rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=BTnpvWFg+A+Gr1PLpIrBkv/lzk+trc2uJFwoAM7yxRo=; b=Y41YtBgOLRKPR0d4GxyO6LZ8SCNpKx1Chj8xpkoYGB/7SWxo3yYQveKIIEBZf+7282 9LqHDgpJf+q5so5lqFhIH0LXqm9ShKgj5mcFbC/QOJ2jFTJ/NFC5cRWqavFyp8I+k5eW i3+drxlk8jk3gQVaKoDTXjB4C9YLuPfjgBNsHn4ri9FsyrBQwDly9WsvZpWLxa4Aeuca wSHCCFDPxuciPL8Hk/6tiLrjsFnZ5wrovOuoj/vJo+MnNehFj9dYMp/vHTxQ3itC04ue P336IZKHS6XG8oXA3wy+eZTfA84waNbygQrGM/AjVezem0JrIPXMsnz6tl5COcn0nkic TV0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lJ1PXtBe; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bo4-20020a0564020b2400b004355a4637f4si10335916edb.491.2022.07.01.09.37.00; Fri, 01 Jul 2022 09:37:26 -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=@kernel.org header.s=k20201202 header.b=lJ1PXtBe; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232475AbiGAQ2L (ORCPT + 99 others); Fri, 1 Jul 2022 12:28:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232459AbiGAQ17 (ORCPT ); Fri, 1 Jul 2022 12:27:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B7F742A09 for ; Fri, 1 Jul 2022 09:27:55 -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 dfw.source.kernel.org (Postfix) with ESMTPS id EA3876255A for ; Fri, 1 Jul 2022 16:27:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E137EC3411E; Fri, 1 Jul 2022 16:27:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1656692874; bh=CfrRwJeGcqujZMKzXtTS5dmHXhzhyLZ2PysUxfIWMb4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lJ1PXtBex6m8EajNJwd7sY7UdPUKfnHO+rmOkoVaIN7EXb3ZoOS1mys+vRewtoQ+K CTmgdKIDT45a+ugRneNynFUu3e0aTfcgMBfF4LzPFUhkoGY+2bNvgBbi3RuECusKrG jXKOdi6w3Q5CAY24ZqrSqWCKQsSOOZ+ncTgkDgtcI9LSZHi5a4tNbZ/6pNtBTLvVlV PqQ2es7Irzl+DW8umFoLlPxga1U02DWVfzTU0Z/WfvAsc2XMvSb2JnlwrWhN91OvYU AF1FP/XlGt+YyOPkAgIH9PLWb0I9edASU/zexnWUlv14T87mt8pDU55eJB9iEneWZh OT5gVq5eSlqhg== Date: Fri, 1 Jul 2022 09:27:52 -0700 From: Nathan Chancellor To: Shuah Khan Cc: Greg Kroah-Hartman , kernel test robot , llvm@lists.linux.dev, kbuild-all@lists.01.org, linux-kernel@vger.kernel.org Subject: Re: [char-misc:char-misc-linus 3/3] drivers/misc/cardreader/rtsx_usb.c:639:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is true Message-ID: References: <202207011658.rHJFVLWA-lkp@intel.com> <67a09516-ec1f-d0b6-c027-fd52159318ed@linuxfoundation.org> <1c13496a-9e45-38b6-1563-c09d412cf576@linuxfoundation.org> <6e148c41-4a31-f173-f5ea-d52e115c268c@linuxfoundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <6e148c41-4a31-f173-f5ea-d52e115c268c@linuxfoundation.org> X-Spam-Status: No, score=-7.5 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,T_SCC_BODY_TEXT_LINE 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 On Fri, Jul 01, 2022 at 10:09:45AM -0600, Shuah Khan wrote: > On 7/1/22 9:52 AM, Shuah Khan wrote: > > On 7/1/22 9:39 AM, Nathan Chancellor wrote: > > > On Fri, Jul 01, 2022 at 08:48:11AM -0600, Shuah Khan wrote: > > > > On 7/1/22 2:59 AM, Greg Kroah-Hartman wrote: > > > > > > > All warnings (new ones prefixed by >>): > > > > > > > > > > > > > > drivers/misc/cardreader/rtsx_usb.c:639:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] > > > > > >              if (!ucr->rsp_buf) > > > > > >                  ^~~~~~~~~~~~~ > > > > > >      drivers/misc/cardreader/rtsx_usb.c:678:9: note: uninitialized use occurs here > > > > > >              return ret; > > > > > >                     ^~~ > > > > > >      drivers/misc/cardreader/rtsx_usb.c:639:2: note: remove the 'if' if its condition is always false > > > > > >              if (!ucr->rsp_buf) > > > > > >              ^~~~~~~~~~~~~~~~~~ > > > > > >      drivers/misc/cardreader/rtsx_usb.c:622:9: note: initialize the variable 'ret' to silence this warning > > > > > >              int ret; > > > > > >                     ^ > > > > > >                      = 0 > > > > > >      1 warning generated. > > > > > > > > > > Odd, gcc doesn't show this for me.  Shuah, can you send a follow-on > > > > > patch to fix this?  The warning does look correct. > > > > > > > > > > > > > gcc didn't complain when I compiled either. I will send a follow-on patch. > > > > > > Unfortunately, GCC won't warn for most uninitialized variables by > > > default after 5.7, which included commit 78a5255ffb6a ("Stop the ad-hoc > > > games with -Wno-maybe-initialized"). They will potentially show up at > > > W=2 or with an explicit KCFLAGS=-Wmaybe-uninitialized (it does in this > > > case): > > > > > > > Thank you. > > > > > | drivers/misc/cardreader/rtsx_usb.c: In function ‘rtsx_usb_probe’: > > > | drivers/misc/cardreader/rtsx_usb.c:678:16: error: ‘ret’ may be used uninitialized [-Werror=maybe-uninitialized] > > > |   678 |         return ret; > > > |       |                ^~~ > > > | drivers/misc/cardreader/rtsx_usb.c:622:13: note: ‘ret’ was declared here > > > |   622 |         int ret; > > > |       |             ^~~ > > > | cc1: all warnings being treated as errors > > > > > > > This is a bug and a good find. ret should have been set > > in the if (!ucr->rsp_buf) before going to error handling. > > > > I wonder if it would have been flagged if ret were to be > > initialized to 0. Something to experiment. > > > > I had to try. As I suspected initializing ret will mask this bug. > > KCFLAGS=-Wmaybe-uninitialized will not flag it even though > the bug still exists. It will return 0 w hen memory allocation > fails. Right, if the variable is unconditonally initialized at the top of the function, it can never be flagged as uninitialized but that doesn't mean the value is correct for every branch within the function. > Initializing isn't always the right answer for these kinds of > warnings. I would say "unconditional initialization", as ret has to be initialized somewhere to fix this warning, right? If you are referring to clang's 'ret = 0' suggestion, I agree that it can be misleading (especially in the case of suggesting initializing dereferenced pointers to NULL..., see [1]) but at the end of the day, it is still on the programmer to analyze their code fully in light of the warning before implementing a fix. Clang cannot know that the return code should be set in the if statement rather than at the top of the function. [1]: https://github.com/llvm/llvm-project/issues/51901 Cheers, Nathan