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 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D4079C77B7C for ; Fri, 12 May 2023 20:40:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5333910E2A3; Fri, 12 May 2023 20:40:28 +0000 (UTC) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id 348F010E2A3; Fri, 12 May 2023 20:40:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683924027; x=1715460027; h=date:message-id:from:to:cc:subject:in-reply-to: references:mime-version; bh=itJ9Nbyp09b3qjC/EGMKi359+B3pFLoxcBCNUF2+8Io=; b=IgMe0I7xA1/Xz0KDcdZad/Yqw8OR25Fztsm0lPUFtbcK8gg+JBmMaTGX XU3KmUdN56S+MGCss2oExMe2NUT9Bk86wIvJtJJSDxAeUmhBjeaTjRniU 13nOVc9IPJ4+A7XIwR8al/IcRsyknwSaVuRuuXdbDdSaB5YyfvUJQ+L5o svDbINpZhMhv6iEbpz+tRWUSgzK2MawARH4W5wJBvGP5SjrGRlLkWLmNH XgOnf/8G8Vol/Xk4mEC2dj/Ub/XFAEnoZ69NExOOvt6+yHVVcM1FhZcnS d5K+Sfl4FT1WIlXZbWLoa+oi9QT2CJnWUl4a323cFCEIS1qt0FTEzPOCe Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10708"; a="349721699" X-IronPort-AV: E=Sophos;i="5.99,269,1677571200"; d="scan'208";a="349721699" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 May 2023 13:40:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10708"; a="789949082" X-IronPort-AV: E=Sophos;i="5.99,269,1677571200"; d="scan'208";a="789949082" Received: from adixit-mobl.amr.corp.intel.com (HELO adixit-arch.intel.com) ([10.212.239.47]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 May 2023 13:40:26 -0700 Date: Fri, 12 May 2023 13:40:07 -0700 Message-ID: <87jzxde120.wl-ashutosh.dixit@intel.com> From: "Dixit, Ashutosh" To: Andi Shyti In-Reply-To: References: <20230510183606.2480777-1-ashutosh.dixit@intel.com> <87y1luepbx.wl-ashutosh.dixit@intel.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?ISO-8859-4?Q?Goj=F2?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/28.2 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Subject: Re: [Intel-gfx] [PATCH] drm/i915/hwmon: Silence UBSAN uninitialized bool variable warning X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Rodrigo Vivi Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" On Fri, 12 May 2023 02:33:33 -0700, Andi Shyti wrote: > Hi Andi, > > On Thu, May 11, 2023 at 10:43:30AM -0700, Dixit, Ashutosh wrote: > > On Wed, 10 May 2023 11:36:06 -0700, Ashutosh Dixit wrote: > > > > > > Loading i915 on UBSAN enabled kernels (CONFIG_UBSAN/CONFIG_UBSAN_BOOL) > > > causes the following warning: > > > > > > UBSAN: invalid-load in drivers/gpu/drm/i915/gt/uc/intel_uc.c:558:2 > > > load of value 255 is not a valid value for type '_Bool' > > > Call Trace: > > > dump_stack_lvl+0x57/0x7d > > > ubsan_epilogue+0x5/0x40 > > > __ubsan_handle_load_invalid_value.cold+0x43/0x48 > > > __uc_init_hw+0x76a/0x903 [i915] > > > ... > > > i915_driver_probe+0xfb1/0x1eb0 [i915] > > > i915_pci_probe+0xbe/0x2d0 [i915] > > > > > > The warning happens because during probe i915_hwmon is still not available > > > which results in the output boolean variable *old remaining > > > uninitialized. > > > > Note that the variable was uninitialized in this case but it was never used > > uninitialized (the variable was not needed when it was uninitialized). So > > there was no bug in the code. UBSAN warning is just complaining about the > > uninitialized variable being passed into a function (where it is not used). > > > > Also the variable can be initialized in the caller (__uc_init_hw) too and > > it will fix this issue. However in __uc_init_hw the assumption is that the > > variable will be initialized in the callee (i915_hwmon_power_max_disable), > > so that is how I have done it in this patch. > > > > I thought these clarifications will help with the review. > > I think we should not just consider what's now but also what can > come later. The use of pl1en is not 100% future proof and > therefore your patch, even though now is not fixing anything, > might avoid wrong uses in the future. > > I'm just wondering, though, why not initializing the variable at > it's declaration. As you wish. OK, in v2 I went ahead and did just that (initializing the variable at the declaration). I was splitting hair too much :/ > Reviewed-by: Andi Shyti Thanks. -- Ashutosh > > > > > Silence the warning by initializing the variable to an arbitrary value. > > > > > > Signed-off-by: Ashutosh Dixit > > > --- > > > drivers/gpu/drm/i915/i915_hwmon.c | 5 ++++- > > > 1 file changed, 4 insertions(+), 1 deletion(-) > > > > > > diff --git a/drivers/gpu/drm/i915/i915_hwmon.c b/drivers/gpu/drm/i915/i915_hwmon.c > > > index a3bdd9f68a458..685663861bc0b 100644 > > > --- a/drivers/gpu/drm/i915/i915_hwmon.c > > > +++ b/drivers/gpu/drm/i915/i915_hwmon.c > > > @@ -502,8 +502,11 @@ void i915_hwmon_power_max_disable(struct drm_i915_private *i915, bool *old) > > > struct i915_hwmon *hwmon = i915->hwmon; > > > u32 r; > > > > > > - if (!hwmon || !i915_mmio_reg_valid(hwmon->rg.pkg_rapl_limit)) > > > + if (!hwmon || !i915_mmio_reg_valid(hwmon->rg.pkg_rapl_limit)) { > > > + /* Fix uninitialized bool variable warning */ > > > + *old = false; > > > return; > > > + } > > > > > > mutex_lock(&hwmon->hwmon_lock); > > > > > > -- > > > 2.38.0 > > >