From patchwork Fri Mar 6 17:32:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11424515 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 C888D139A for ; Fri, 6 Mar 2020 17:32:19 +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 A6C0C2051A for ; Fri, 6 Mar 2020 17:32:19 +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="eJ5c87zi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A6C0C2051A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 075946E4D4; Fri, 6 Mar 2020 17:32:17 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1B92B6E4D4 for ; Fri, 6 Mar 2020 17:32:16 +0000 (UTC) Received: by mail-pl1-x642.google.com with SMTP id g12so1141118plo.3 for ; Fri, 06 Mar 2020 09:32:16 -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=G1RDgxBiyV6Kk2G6RLMWzGPree6/YVdm0hvb7UeIEqk=; b=eJ5c87ziTXTK+rhDA6QRlgfcRU/IdlKxZshAQM2TCEltwHmpXlDjzbuPMRXbX/7SGS X6IcuBDDareaY/S6mEVT0sTK3myUJL+cptTI+1dD6SVbdEuCtEJVaWp1SEPjhfBDYtPO VnfXAUQrEMFY0Nar8GnvXCEnkpF1wckCT89A4= 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=G1RDgxBiyV6Kk2G6RLMWzGPree6/YVdm0hvb7UeIEqk=; b=liW0CEuYyMCovnDdxVXUmJEzcXYI8dW/5NbVsIM62iLE86RrxhXehLWoK0u0+5FCrF o8152D0KyB+K3ZYGVjAvc8QYnY4kj5SAK9nOKdn/NFIdF0UIf1TI3wS6PgM+F33EBUs+ 7C8Jq+LAUYwbqjvT2huD0PhmxiH9FWSqwN7J380+GYi/E+hFelWCpjSKI382mJScByhP HtHPWQ/QwJa9me+LNmFTO0aQm3GFvPdZkiEkI27Zkyrkpwp6LFibj7O7V5/sJ/3bDzuz amu+o4IYMiRSTpH+jJRFZgDUBH0/RwQCsnJa6nC2pHVMVsaB89MFb6QUnVIAtxFbLXUl c+nQ== X-Gm-Message-State: ANhLgQ05EowEn2cFWjUFR9aNcKtWMaHZCOdffJmrJU9t7KXIN9GODzN2 kbdqbHJx+jZhp/5fJ5mpZyK3Vg== X-Google-Smtp-Source: ADFU+vu76IOA+FPbi+9Jw1089IGoAuLPRcbDWWPgxaDXV5HF6U2+lYzFPU/z9i6aSOe5cIMfsSEKHg== X-Received: by 2002:a17:902:342:: with SMTP id 60mr3878637pld.206.1583515935302; Fri, 06 Mar 2020 09:32:15 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id x190sm37154310pfb.96.2020.03.06.09.32.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Mar 2020 09:32:14 -0800 (PST) Date: Fri, 6 Mar 2020 09:32:13 -0800 From: Kees Cook To: Daniel Vetter Subject: [PATCH v2] drm/edid: Distribute switch variables for initialization Message-ID: <202003060930.DDCCB6659@keescook> MIME-Version: 1.0 Content-Disposition: inline X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Airlie , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, clang-built-linux@googlegroups.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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, lift such variables up into the next code block. drivers/gpu/drm/drm_edid.c: In function ‘drm_edid_to_eld’: drivers/gpu/drm/drm_edid.c:4395:9: warning: statement will never be executed [-Wswitch-unreachable] 4395 | int sad_count; | ^~~~~~~~~ [1] https://bugs.llvm.org/show_bug.cgi?id=44916 Signed-off-by: Kees Cook Reviewed-by: Nick Desaulniers --- v2: move into function block instead being switch-local (Ville Syrjälä) --- drivers/gpu/drm/drm_edid.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 805fb004c8eb..46cee78bc175 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -4381,6 +4381,7 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid) if (cea_revision(cea) >= 3) { int i, start, end; + int sad_count; if (cea_db_offsets(cea, &start, &end)) { start = 0; @@ -4392,8 +4393,6 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid) dbl = cea_db_payload_len(db); switch (cea_db_tag(db)) { - int sad_count; - case AUDIO_BLOCK: /* Audio Data Block, contains SADs */ sad_count = min(dbl / 3, 15 - total_sad_count);