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 6D4E6C77B7F for ; Thu, 11 May 2023 17:43:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CB67910E0B7; Thu, 11 May 2023 17:43:35 +0000 (UTC) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTPS id 500A610E0B7; Thu, 11 May 2023 17:43:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683827014; x=1715363014; h=date:message-id:from:to:cc:subject:in-reply-to: references:mime-version; bh=94K5bFpyBLjyV4l3FhGKVebPEtroxYRzqdZHvAHjb74=; b=MCs6At/WNeOI2/T/mAMjByJUnxJFXQt6fnWBVuXhccwJH42/k9o+50wp jyCE0vZHxCTm6cBRHeNAQ6tZvlSISqNY2BQEqZtIop4aN18Us1TZ+bT/I fesBs2Km3O915IRK9+QLJp/cVpjsCRtkWnS7AZA5+3Wo6KnRlFQb0tCFx RJ+UVPiBaHAMlY4Iumvvp1zn/e81bjBY0yFReo+PyeILeW2a5VMvhtpB4 eNCY5hmd0ESq0zoBRCMgRp01SHyy8CUVLgNEHyfWXu4jiCKePBeE31FoD kw0zMCPR2z3euKi3NdI4jZvXS2Nr6mKMEQAeCQeqNp0+JH5yO1QJ3eZ60 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10707"; a="348060076" X-IronPort-AV: E=Sophos;i="5.99,268,1677571200"; d="scan'208";a="348060076" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2023 10:43:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10707"; a="764841999" X-IronPort-AV: E=Sophos;i="5.99,268,1677571200"; d="scan'208";a="764841999" Received: from adixit-mobl.amr.corp.intel.com (HELO adixit-arch.intel.com) ([10.209.97.176]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2023 10:43:30 -0700 Date: Thu, 11 May 2023 10:43:30 -0700 Message-ID: <87y1luepbx.wl-ashutosh.dixit@intel.com> From: "Dixit, Ashutosh" To: intel-gfx@lists.freedesktop.org In-Reply-To: <20230510183606.2480777-1-ashutosh.dixit@intel.com> References: <20230510183606.2480777-1-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: dri-devel@lists.freedesktop.org, Rodrigo Vivi Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 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. 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 >