From patchwork Fri Feb 21 00:05:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11395093 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CEF2292A for ; Fri, 21 Feb 2020 00:05:24 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id AD802208CD for ; Fri, 21 Feb 2020 00:05:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="VxH0eWQX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AD802208CD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3A5A46E154; Fri, 21 Feb 2020 00:05:22 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6E84E6EE86 for ; Fri, 21 Feb 2020 00:05:20 +0000 (UTC) Received: by mail-pg1-x543.google.com with SMTP id d6so64691pgn.5 for ; Thu, 20 Feb 2020 16:05:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding; bh=cG6xfIMmhv4aUUzpLxwO6dmYGKiY4JsX+x1sscFIGBo=; b=VxH0eWQXgXV0A37NybzLS45Q1yg3sL2CN8bQswEwr6dJAyeajhuIUPnyWxKhXAoack zLheja1zuHdZKtgTRHPqCMlR6riEI0p0ke+O5Re9d9vv1A/qKQvcc5qnOfwkolKwtX5o BQ5VEXseArBchh2+vdkPOSwrPuRlA/q1ovt0M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding; bh=cG6xfIMmhv4aUUzpLxwO6dmYGKiY4JsX+x1sscFIGBo=; b=DtgRibfyBdb941R7OuP0DrGwfP+mZgHReepsidXSpISk//l69QBlcwE+kLO8ASkvK7 ER4Ai9YJmCXnz0h7kB1/3+8OZK0taEFiHAPGNYo07aBXzHoJhjNkAHnbF41/pB2HR0rZ H5qpyTEgof94S1SH5IWpYBDKG9efiXK1KYdbs1KpysJfWA7uhnJcDThcB1MD9EG+cqYi Cr4YGJiThDw9xw6SyNk0BHp/KJ1k8lmfGuciPrpoyFq8QFrVmkL0pg+7Kd2Si0gTpS02 CFvpOtzkKX/J8ArOTS7ZyKpwnvl/fc1MUTg/bGWOr1WZOJzDIgtQwGo6Kt0MVSan1VZs 8SRg== X-Gm-Message-State: APjAAAXdDJBmxv3o1s3S86t5v76NB1v649Y8IHQT2C0uobY7JjOSixho XYe0qUxFU5GsMolHDuhSW9ZneA== X-Google-Smtp-Source: APXvYqwWrrCqyu+iKf6CKoTvIQXFlxyK58QKsqtU8gZfU9zUdaxuG26kbF1OKSnBPVnJHm/N4i6Ckw== X-Received: by 2002:a63:7802:: with SMTP id t2mr34514449pgc.352.1582243519903; Thu, 20 Feb 2020 16:05:19 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id d3sm688647pfn.113.2020.02.20.16.05.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2020 16:05:18 -0800 (PST) Date: Thu, 20 Feb 2020 16:05:17 -0800 From: Kees Cook To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi Message-ID: <202002201602.92CADF7D@keescook> MIME-Version: 1.0 Content-Disposition: inline Subject: [Intel-gfx] [PATCH v2] drm/i915: Distribute switch variables for initialization 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, Alexander Potapenko , linux-kernel@vger.kernel.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 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 Reviewed-by: Ville Syrjälä --- 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); 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);