Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1207422imu; Wed, 23 Jan 2019 12:37:13 -0800 (PST) X-Google-Smtp-Source: ALg8bN4pH1bJefYtSwwlhuhnzdOrK8LhPWk3slWmtmqZ11r/7LblvHOLb5qLyt5y5EatbDBUeVmQ X-Received: by 2002:a62:6408:: with SMTP id y8mr3501166pfb.202.1548275832945; Wed, 23 Jan 2019 12:37:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548275832; cv=none; d=google.com; s=arc-20160816; b=Xd3KQvYWuNnh0gVbASU6dYbB4etGYvn9vpNhMTRkmSV9+kG/AsaZnru5djj4+DKEte EAMsmZBREn15vDn+pF3YLQ11sq/l+LaDqY/Oe4JeFNktjveHjAtCJ7lpurCfyei515JX p4vxBiB0YHqjWTW5QJammo26Hx5S4KGlpzIlW9Sfycdd0FkqQlyQDVFZ89kccyy9qP/p 03Uy5VoVJPSOAak/3UZUK+75qVi50EhEusF62mK8g289a4jwTdftrfA09RH6GHllLRMh 2OFr1GvpcWFNpF8WGr8yYp6cX21v2r/C5fPQZhtsRny4n5dCEvLXVXPfMlejAI1O2wBG rFJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=rFCkOF2gK3wr1UB995eD+/CTWS4iazBBfFIZUEffwxc=; b=H/hYUqe5RL8K6wGbl9bY9CZnE26GxwB8V3F8WeTHMKjcWdezKZ9QEOEp2hFNQ+CePq xirpMye/D/8pwKxJ2tcZ9rOBZtX1hY079bTuIn90nKdnxpN4z0Gu3+iuxcsdrmE6b2AR kreYXVodQCk+EjWCJuccrv61iDYgCJjWA6+5TDz/Y6Bileg74kl1OkFqLE+sU9dzIvUI DsulIFtMKPebiHAbarvukP2dgn9OxZvrlZ0tRJQBa/pEe29Y76xVILswMZWJhDZVSpUg MCFMcThgXDqhjUHXSpxsPPEOnO49oCgM8ea0swvS4m3dRGx7So4vWTgAm+zCRQ1rWcXm BG7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=L8GygvYw; 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 u131si20298942pgc.287.2019.01.23.12.36.57; Wed, 23 Jan 2019 12:37:12 -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=L8GygvYw; 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 S1726843AbfAWUg3 (ORCPT + 99 others); Wed, 23 Jan 2019 15:36:29 -0500 Received: from mail-ua1-f68.google.com ([209.85.222.68]:33846 "EHLO mail-ua1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726803AbfAWUg2 (ORCPT ); Wed, 23 Jan 2019 15:36:28 -0500 Received: by mail-ua1-f68.google.com with SMTP id c24so1206945uak.1 for ; Wed, 23 Jan 2019 12:36:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rFCkOF2gK3wr1UB995eD+/CTWS4iazBBfFIZUEffwxc=; b=L8GygvYwk5FYD+Ce0ML1TRQbDfEIv0oR+ZZMDgwVJntrdffAzAT1EMjtnCS4Vm7kGF 9dyJBTPuJm07cjZsS/xzizI42KQnMArMr2N3CLtPSslUeR/3lApJBdvCmKdyWI0HKF0C Vq7eIyo8gjyd5kPrv1YhbaPvpYIMVU0STBBf4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rFCkOF2gK3wr1UB995eD+/CTWS4iazBBfFIZUEffwxc=; b=pdRAYogogA9o6OWZYm2xB10edMydWr6mys2X+SHVKSSey1v7pHxckxLuGGifyUIjvb 4Etv4RzTLziSEUObRwlJIEs8LlP9EvT8u+gjx+2JvlApcfjA0Gtj9mwyuuaVYWgeWclq Evglt9jhmmWErDkoayciN0vw5kDImDDHqSMtB9cGpehMpPHAspOxcORoYcPfVGPLbyIT aaFzkGbWGL/uy6WYs5nSc4zFfOmizPt8lu/jgMTEks7qQwIaNkJyF0dXTmYPcldardQK k3pJhySixd9xLcSVtrki5mAH4/DtgK1l6e+dnb6FSRFDeGGcdkiWe8edpbLFKGtS8NR/ etJg== X-Gm-Message-State: AJcUukfSjwndX8CWmbHbAhwS4nTOmtVLTB0ryctW9p8UlDSv7ieN+IQ7 hPvVb6KZapxZbcPPBh93biIBmsYmMcw= X-Received: by 2002:a9f:300d:: with SMTP id h13mr1577506uab.80.1548275786904; Wed, 23 Jan 2019 12:36:26 -0800 (PST) Received: from mail-vs1-f50.google.com (mail-vs1-f50.google.com. [209.85.217.50]) by smtp.gmail.com with ESMTPSA id s195sm23378139vks.28.2019.01.23.12.36.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 12:36:24 -0800 (PST) Received: by mail-vs1-f50.google.com with SMTP id b74so2135200vsd.9 for ; Wed, 23 Jan 2019 12:36:23 -0800 (PST) X-Received: by 2002:a67:e199:: with SMTP id e25mr1560245vsl.188.1548275782895; Wed, 23 Jan 2019 12:36:22 -0800 (PST) MIME-Version: 1.0 References: <20190123110349.35882-1-keescook@chromium.org> <20190123110349.35882-2-keescook@chromium.org> <20190123115829.GA31385@kroah.com> <874l9z31c5.fsf@intel.com> <20190123191802.GB15311@bombadil.infradead.org> In-Reply-To: <20190123191802.GB15311@bombadil.infradead.org> From: Kees Cook Date: Thu, 24 Jan 2019 09:36:11 +1300 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [Intel-gfx] [PATCH 1/3] treewide: Lift switch variables out of switches To: Matthew Wilcox Cc: Jani Nikula , Greg KH , dev@openvswitch.org, Ard Biesheuvel , Network Development , intel-gfx@lists.freedesktop.org, linux-usb@vger.kernel.org, LKML , Maling list - DRI developers , Linux-MM , linux-security-module , Kernel Hardening , intel-wired-lan@lists.osuosl.org, "linux-fsdevel@vger.kernel.org" , xen-devel , Laura Abbott , linux-kbuild , Alexander Popov Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 24, 2019 at 8:18 AM Matthew Wilcox wrote: > > On Wed, Jan 23, 2019 at 04:17:30PM +0200, Jani Nikula wrote: > > Can't have: > > > > switch (i) { > > int j; > > case 0: > > /* ... */ > > } > > > > because it can't be turned into: > > > > switch (i) { > > int j = 0; /* not valid C */ > > case 0: > > /* ... */ > > } > > > > but can have e.g.: > > > > switch (i) { > > case 0: > > { > > int j = 0; > > /* ... */ > > } > > } > > > > I think Kees' approach of moving such variable declarations to the > > enclosing block scope is better than adding another nesting block. > > Another nesting level would be bad, but I think this is OK: > > switch (i) { > case 0: { > int j = 0; > /* ... */ > } > case 1: { > void *p = q; > /* ... */ > } > } > > I can imagine Kees' patch might have a bad effect on stack consumption, > unless GCC can be relied on to be smart enough to notice the > non-overlapping liveness of the vriables and use the same stack slots > for both. GCC is reasonable at this. The main issue, though, was most of these places were using the variables in multiple case statements, so they couldn't be limited to a single block (or they'd need to be manually repeated in each block, which is even more ugly, IMO). Whatever the consensus, I'm happy to tweak the patch. Thanks! -- Kees Cook