Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp2998036ybf; Mon, 2 Mar 2020 20:40:10 -0800 (PST) X-Google-Smtp-Source: ADFU+vvmUPh0vYerLfIb3jMRBUJGpv1sNwT81P7oGUjMXOkp1RMoUYyn14sKhG1AIDS1cQn0WNuZ X-Received: by 2002:a9d:6f88:: with SMTP id h8mr2011292otq.91.1583210410530; Mon, 02 Mar 2020 20:40:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583210410; cv=none; d=google.com; s=arc-20160816; b=iZ5E/xiHl0JLL8083SR3c87WnQYsdjkI47K2LH3MhCgdWfckQZ4XtRnOEXuLcwCfKi enScTIwWZs7o9OOsgv3nNdl03VSifN6agNkD5ctnLRqySftW1sI+6NklGl9KrSJfQhIt k4FDuUAM9ibovVv0PCXAl+BGMIT3uf1ZQf08RexrZ1+KwUQOaDahEjAKWMX9Xi2UsolM V7NEkD6gi5JAZi8VlPE0LXVcsXacnwOM0BAfbAXetuUHpz45vATnvOTXh/MFs7Wh3WbV Gl8irpT1nlezZy5LgJrwagJcijlCoMH0x+urFE9JRnT4TqI3TQWtwmVt8TDuPocfLtB1 Ma/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Fsfwjx7jgGYItwF5bCeIDJyJTUNRPkOSFQYt5/XqQ6U=; b=jQ92fsNlU/ab8vFP3wsy85w2JNuuWKE8v1XqJ/RZ9QbiqSf0pB7gEB1B5+pzuRCd+e /7iR7gNglnoxU67WX+ySMvnRPHBhMHaLjv5kSDCzB0yBWBDVVXKG64FIqcQ+szDO157f eOpoUF40kYucsK42K1KvNVOMMbIwLSuS1F5Q1UlEkbc4NbHKjs9Tj7p8O6q/42bdI0ie U5Pfrmahy04ngO2NbtU56U+p/b4Go4b0iNk56+7zn9JuGRIyZ3067A1+EmEXwuStwwuG NH5pXDtDqF7iMVVt7uRoR23H2PzUdhaI8o6RjOdCYrFePGm/LmDaCYaJPrvVcYtqZdGh mmQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=HFmh7HTA; 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 v3si7905326otn.140.2020.03.02.20.39.56; Mon, 02 Mar 2020 20:40:10 -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=HFmh7HTA; 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 S1726990AbgCCEjm (ORCPT + 99 others); Mon, 2 Mar 2020 23:39:42 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:45996 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726928AbgCCEjm (ORCPT ); Mon, 2 Mar 2020 23:39:42 -0500 Received: by mail-pl1-f195.google.com with SMTP id b22so717913pls.12 for ; Mon, 02 Mar 2020 20:39:40 -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:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=Fsfwjx7jgGYItwF5bCeIDJyJTUNRPkOSFQYt5/XqQ6U=; b=HFmh7HTAS7PHa+TvciXQAcYw5whCIuhZU2zUpAkLC9ZJSjxyCGmEPDXrMVM0dfkTyv ETn18Etqs5FyLnJDrAVM/OwrQtNrlzIHx775yZXbREV7ssdmKxlU8CZQObyJhmBCBrLZ qwhlET/uk886S32xAP95UNxC5j3EejlV71gy4= 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:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=Fsfwjx7jgGYItwF5bCeIDJyJTUNRPkOSFQYt5/XqQ6U=; b=fPL6lbul8LV/Dmpt+mPC39CAF0CUYfJ69Aa5tdVH6Pwjuwy4blaN/JPzW3jDzcAK6X euv9T9RgljVrqit+tE/nOWbjY/G+0y6WqMZhcsrFcgOZFTTw3NTRhK96X7ODVQ9YMjE2 vxQs+qfVJ000dttYagR3EIhnIUNi0J5OVVPdOzkMnlQx+urqYn4NQ5sxy9q73CqoQnYd QleLSrHBAnpSR36oKWKQFMzLgLfQu3sLbeNMSXZIjLlkhpQqzd5TJPwrJsqSbAR1Ykqb 0Z2Xmqu15gCpU85VL0ATC4HW7PK+ZPwhFSPmrPxmQFCcuZ2gxvDrrPqYvmza/aPSP1wC uSpA== X-Gm-Message-State: ANhLgQ3IlP0aaifUcrLu7wXmp1tt9EvYsJE7N+y9QVC40LGCe/acwCZx JsrQ5GAckit950KhSsBfwd+tXg== X-Received: by 2002:a17:902:7087:: with SMTP id z7mr2493646plk.270.1583210379715; Mon, 02 Mar 2020 20:39:39 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id u126sm22329618pfu.182.2020.03.02.20.39.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Mar 2020 20:39:38 -0800 (PST) Date: Mon, 2 Mar 2020 20:39:37 -0800 From: Kees Cook To: Maarten Lankhorst , Maxime Ripard , David Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org Cc: Alexander Potapenko , linux-kernel@vger.kernel.org Subject: Re: [PATCH] drm/edid: Distribute switch variables for initialization Message-ID: <202003022038.07A611E@keescook> References: <20200220062229.68762-1-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200220062229.68762-1-keescook@chromium.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 19, 2020 at 10:22:29PM -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/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 Ping. Can someone pick this up, please? Thanks! -Kees > --- > 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) > -- Kees Cook