Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1476021ybv; Sun, 23 Feb 2020 07:34:04 -0800 (PST) X-Google-Smtp-Source: APXvYqxOtaAfxEtnhFdjXV3xL+zXUe6ZLm0zfYxZOyEzSOMcRVDR9lmh6BnO9TULcQ8ZtrD4118g X-Received: by 2002:a05:6830:1385:: with SMTP id d5mr38144092otq.61.1582472043928; Sun, 23 Feb 2020 07:34:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582472043; cv=none; d=google.com; s=arc-20160816; b=V552IZa0fE1SUVurLqeUdhshJMQfjwH+PEyQ+cXEO2nKeDso3rZNp/qZOqq85GuBUk UlP/dMnZg8u8s6f9jq4Hv9ywP1jSzaSDpw/0iDuaaoCGoqzxQgqsYKofJdvk6UN8IF/T lzWFekb1vbpbzX3BurchcKQSQAwLu2JNkWWT0HDk8mPZIWVlVCghgtyS6Sf/hyn4CeXA Gtl0gpsCfTGPAKRNqMxzJpHBYDqrwHKsEJMZWds/bTCICHt17ycbSNyEynpbFn4Dk+to SGV9IJ7ZXnkpp92zpF/+8gjkCot4Phj5HDnAx8ndxQOzsHxStloLZ8tlDeA7grAxoU1y sa3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:references:organization:in-reply-to:subject:cc:to :from; bh=kXn1Nl19P/zVK8uCzxH+t8dbtXuVXFbREX7C3Dizu+I=; b=BdAuxv6ys+4We52TAv+ZfjAbxe2J8b9b6ioWNp0jvyCGNgjWFkSj6qeIaGiMh2W7kU WNZy2XPwFlo6Ppypck0jHoJIwE4YwSS6TJblLBR7wX/BEZNRUoctNonCXr12Cg13yIpX 0VKV9QLxqA6Ewi6FPnvQTHau5OPrJOv1jfxcd/LLHbIoBm4rrlkc7jCoF+466TPTvvJD 4CFrlmLkLTHjDmHnIOkl3ml8k1ImdqFOe+Y2/PPvousCgAfwkMS8hF9koHRyoYbriSP5 G9mmaacirpBRnAZ36KN4JZ2k4kFxwikYyt5Jc/I6FHx5tOop72PWGRz1uL/NTgcYZVA0 t+BA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b141si3882910oii.79.2020.02.23.07.33.51; Sun, 23 Feb 2020 07:34:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726748AbgBWPcl convert rfc822-to-8bit (ORCPT + 99 others); Sun, 23 Feb 2020 10:32:41 -0500 Received: from mga17.intel.com ([192.55.52.151]:40832 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726208AbgBWPcl (ORCPT ); Sun, 23 Feb 2020 10:32:41 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Feb 2020 07:32:40 -0800 X-IronPort-AV: E=Sophos;i="5.70,476,1574150400"; d="scan'208";a="230388634" Received: from rcoelln-mobl.ger.corp.intel.com (HELO localhost) ([10.252.40.180]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Feb 2020 07:32:37 -0800 From: Jani Nikula To: Ville =?utf-8?B?U3lyasOkbMOk?= , Kees Cook Cc: Joonas Lahtinen , Rodrigo Vivi , intel-gfx@lists.freedesktop.org, Alexander Potapenko , linux-kernel@vger.kernel.org Subject: Re: [Intel-gfx] [PATCH v2] drm/i915: Distribute switch variables for initialization In-Reply-To: <20200221113057.GL13686@intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: <202002201602.92CADF7D@keescook> <20200221113057.GL13686@intel.com> Date: Sun, 23 Feb 2020 17:32:49 +0200 Message-ID: <87h7zhtj32.fsf@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 21 Feb 2020, Ville Syrjälä wrote: > On Thu, Feb 20, 2020 at 04:05:17PM -0800, Kees Cook wrote: >> Variables declared in a switch statement before any case statements >> cannot be automatically initialized with compiler instrumentation (as >> they are not part of any execution flow). With GCC's proposed automatic >> stack variable initialization feature, this triggers a warning (and they >> don't get initialized). Clang's automatic stack variable initialization >> (via CONFIG_INIT_STACK_ALL=y) doesn't throw a warning, but it also >> doesn't initialize such variables[1]. Note that these warnings (or silent >> skipping) happen before the dead-store elimination optimization phase, >> so even when the automatic initializations are later elided in favor of >> direct initializations, the warnings remain. >> >> To avoid these problems, move such variables into the "case" where >> they're used or lift them up into the main function body. >> >> drivers/gpu/drm/i915/display/intel_display.c: In function ‘check_digital_port_conflicts’: >> drivers/gpu/drm/i915/display/intel_display.c:12963:17: warning: statement will never be executed [-Wswitch-unreachable] >> 12963 | unsigned int port_mask; >> | ^~~~~~~~~ >> >> drivers/gpu/drm/i915/intel_pm.c: In function ‘vlv_get_fifo_size’: >> drivers/gpu/drm/i915/intel_pm.c:474:7: warning: statement will never be executed [-Wswitch-unreachable] >> 474 | u32 dsparb, dsparb2, dsparb3; >> | ^~~~~~ >> drivers/gpu/drm/i915/intel_pm.c: In function ‘vlv_atomic_update_fifo’: >> drivers/gpu/drm/i915/intel_pm.c:1997:7: warning: statement will never be executed [-Wswitch-unreachable] >> 1997 | u32 dsparb, dsparb2, dsparb3; >> | ^~~~~~ >> >> [1] https://bugs.llvm.org/show_bug.cgi?id=44916 >> >> Signed-off-by: Kees Cook >> --- >> v2: remove port_mask entirely (Ville Syrjälä) >> v1: https://lore.kernel.org/lkml/20200220062258.68854-1-keescook@chromium.org >> --- >> drivers/gpu/drm/i915/display/intel_display.c | 7 ++----- >> drivers/gpu/drm/i915/intel_pm.c | 4 ++-- >> 2 files changed, 4 insertions(+), 7 deletions(-) >> >> diff --git a/drivers/gpu/drm/i915/display/intel_display.c b/drivers/gpu/drm/i915/display/intel_display.c >> index 064dd99bbc49..5f8c61932e82 100644 >> --- a/drivers/gpu/drm/i915/display/intel_display.c >> +++ b/drivers/gpu/drm/i915/display/intel_display.c >> @@ -12960,7 +12960,6 @@ static bool check_digital_port_conflicts(struct intel_atomic_state *state) >> WARN_ON(!connector_state->crtc); >> >> switch (encoder->type) { >> - unsigned int port_mask; >> case INTEL_OUTPUT_DDI: >> if (WARN_ON(!HAS_DDI(to_i915(dev)))) >> break; >> @@ -12968,13 +12967,11 @@ static bool check_digital_port_conflicts(struct intel_atomic_state *state) >> case INTEL_OUTPUT_DP: >> case INTEL_OUTPUT_HDMI: >> case INTEL_OUTPUT_EDP: >> - port_mask = 1 << encoder->port; >> - >> /* the same port mustn't appear more than once */ >> - if (used_ports & port_mask) >> + if (used_ports & BIT(encoder->port)) >> ret = false; >> >> - used_ports |= port_mask; >> + used_ports |= BIT(encoder->port); > > Thanks. Looks good. > > Reviewed-by: Ville Syrjälä Thanks for the patch and review, pushed to dinq. BR, Jani. > >> break; >> case INTEL_OUTPUT_DP_MST: >> used_mst_ports |= >> diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c >> index bd2d30ecc030..17d8833787c4 100644 >> --- a/drivers/gpu/drm/i915/intel_pm.c >> +++ b/drivers/gpu/drm/i915/intel_pm.c >> @@ -469,9 +469,9 @@ static void vlv_get_fifo_size(struct intel_crtc_state *crtc_state) >> struct vlv_fifo_state *fifo_state = &crtc_state->wm.vlv.fifo_state; >> enum pipe pipe = crtc->pipe; >> int sprite0_start, sprite1_start; >> + u32 dsparb, dsparb2, dsparb3; >> >> switch (pipe) { >> - u32 dsparb, dsparb2, dsparb3; >> case PIPE_A: >> dsparb = I915_READ(DSPARB); >> dsparb2 = I915_READ(DSPARB2); >> @@ -1969,6 +1969,7 @@ static void vlv_atomic_update_fifo(struct intel_atomic_state *state, >> const struct vlv_fifo_state *fifo_state = >> &crtc_state->wm.vlv.fifo_state; >> int sprite0_start, sprite1_start, fifo_size; >> + u32 dsparb, dsparb2, dsparb3; >> >> if (!crtc_state->fifo_changed) >> return; >> @@ -1994,7 +1995,6 @@ static void vlv_atomic_update_fifo(struct intel_atomic_state *state, >> spin_lock(&uncore->lock); >> >> switch (crtc->pipe) { >> - u32 dsparb, dsparb2, dsparb3; >> case PIPE_A: >> dsparb = intel_uncore_read_fw(uncore, DSPARB); >> dsparb2 = intel_uncore_read_fw(uncore, DSPARB2); >> -- >> 2.20.1 >> >> >> -- >> Kees Cook >> _______________________________________________ >> Intel-gfx mailing list >> Intel-gfx@lists.freedesktop.org >> https://lists.freedesktop.org/mailman/listinfo/intel-gfx -- Jani Nikula, Intel Open Source Graphics Center