Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp319841ybv; Wed, 19 Feb 2020 22:23:09 -0800 (PST) X-Google-Smtp-Source: APXvYqw80Z2pCsyg4Dt4y5r8oNbsQvQBZJs3jnnqLHzzrQ7VkWEKtQWjbPfWOpoTJ33prqp/obzs X-Received: by 2002:a05:6808:a8a:: with SMTP id q10mr948845oij.66.1582179789251; Wed, 19 Feb 2020 22:23:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582179789; cv=none; d=google.com; s=arc-20160816; b=QHyVP2V7G6ss2grt9pmhd08foxDVGOpfFO/1J1ZxyRLgkxwvivlzgyhWxgZ43S7wIS SnMVn/UC3KAsjUPGYnupSIu32YuP1fzTP+LGCYSAZi4m0udhrfTfUdJvJzoMNCsiw6lC lymaYdtjD42G2Xwh+GRTC0m3WQWdPPlCuqE8OTZ/IWDIdRVbNOYai7tKcnUQbjmc3Y/a BscC6OAH/mGtV6yUTc3yAQYDjr/AZWg+GNoRAhgaS4eIMKjFxvnRk/RsCNbYHsd5jH2D 6h//bx6j+rhEr/r6pf7C74sQPneHOG3g5cHnLdZaC9nede8STGKSRYS1GJ+gPvyWwHOu YPXQ== 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:subject:cc:to:from:dkim-signature; bh=4HmaMrg/A0ePGN0EoT7LOXLlO0HcR/QAQGKc66IQiBw=; b=HyFPJT2gAYK/esyIqxFSjUXz+YU1HBlk6TB1SeXL5YJS1545O+p+wP5BK5Nn1+O0Pz fLmw1y/VVkRIE6z+ZMPdymNbywS10+jPnO0BGn9kGIDUeVehYemMNx5W5xG7Gqskks54 JYSrTMFEqwcsOYRfJdUcHH9Ry1iP8Amma3Ae6+qxPiSSwDCU9er4KzFo4aY7j1Ap99Uh GY0kuexiaqg5nulOrD6vHorFV81dB1EUf24XW2QJvNDBJ+mg1MfHWOZsyTAjxgn4QsQh 33HcfItcb6FzU59ZIPaCTZrL8ExuBOU3c95YlxWYNbDO70AEMEEsc+KkLZKMo7XOTu5N 6JxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=fRDY4Kkr; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f62si2575457oib.131.2020.02.19.22.22.56; Wed, 19 Feb 2020 22:23:09 -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; dkim=pass header.i=@chromium.org header.s=google header.b=fRDY4Kkr; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726756AbgBTGWq (ORCPT + 99 others); Thu, 20 Feb 2020 01:22:46 -0500 Received: from mail-pj1-f68.google.com ([209.85.216.68]:52264 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725988AbgBTGWq (ORCPT ); Thu, 20 Feb 2020 01:22:46 -0500 Received: by mail-pj1-f68.google.com with SMTP id ep11so431415pjb.2 for ; Wed, 19 Feb 2020 22:22:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=4HmaMrg/A0ePGN0EoT7LOXLlO0HcR/QAQGKc66IQiBw=; b=fRDY4KkruK7J3WvWuRYCMBR/HFq68axyRau9YhW75xxf3hmvY0zQZh0pHSJdxCvJX7 OQMw9MatyxS8oE7/oWzN1VFUJ+cdS3Iy4OW3bcuoCgn4/ByJ9PNnV6JA7ZyFauySNe/A SAhzTtQ7YoXLrfvYJSrfL6HXeiIm/S7OEWuQw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=4HmaMrg/A0ePGN0EoT7LOXLlO0HcR/QAQGKc66IQiBw=; b=cnK78+1LOaI2lhUjWmANTEsLrL13VhawnZPzINyrmRpxMNk/JWBN7OFByGaxNf4OBz EPPx9oRg9ZkSsqX00BpmOtGeJzynGF376ougmAlw6WghK3HP0Go+t1e52vkOa6dsylN+ J9Rrs/lptksDCHVmd3mM/+qZya5l9x2aeGHv0UbKEKwN//Yq+kjiQz7ec3X/rL01IuW0 0jtiUwhIqilw+Q7SdNlnTLEAUwSeIOSHCtczum003ovP3WE+wO02jTT5gz90pNSoMMba DY6gahTjUp0KsdnoZE8z5rbHpsvA8GjyjCgKtc2olDNz/AqcByaiAU1m0rDmLVX35Jge HEBg== X-Gm-Message-State: APjAAAUEp94npWaKjJvblmdEJ+D3D3TGMmDj4qrPgG10Ge2aLGU5toTG wyaaAnoWHoYYcrtDP2umF/Jlzw== X-Received: by 2002:a17:90a:348a:: with SMTP id p10mr1787055pjb.120.1582179765345; Wed, 19 Feb 2020 22:22:45 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id k2sm1836863pgk.84.2020.02.19.22.22.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2020 22:22:44 -0800 (PST) From: Kees Cook To: Maarten Lankhorst , Maxime Ripard Cc: Alexander Potapenko , Kees Cook , linux-kernel@vger.kernel.org Subject: [PATCH] drm/edid: Distribute switch variables for initialization Date: Wed, 19 Feb 2020 22:22:29 -0800 Message-Id: <20200220062229.68762-1-keescook@chromium.org> X-Mailer: git-send-email 2.20.1 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 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/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 --- drivers/gpu/drm/drm_edid.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 805fb004c8eb..2941b65b427f 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -4392,9 +4392,9 @@ 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: { - case AUDIO_BLOCK: + int sad_count; /* Audio Data Block, contains SADs */ sad_count = min(dbl / 3, 15 - total_sad_count); if (sad_count >= 1) @@ -4402,6 +4402,7 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid) &db[1], sad_count * 3); total_sad_count += sad_count; break; + } case SPEAKER_BLOCK: /* Speaker Allocation Data Block */ if (dbl >= 1)