From nobody Sun Feb 8 09:10:48 2026 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5CA7422257E for ; Sat, 20 Dec 2025 21:56:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766267785; cv=none; b=cWxYzk28Ttcoj+PF3JJ1el+/rs18bGBYw3XyQ/CZLd0nUJeyFoJFB/UPc8uZNLyuSQLG23fMgeJhTgHae6vckxoYowIJE3KxXaScG4YXTZJR5E1ZSK2/Ss/cPppWUS2I7miYp1JAkobt5nwsbd53JY4QQ0j3DQVXf0B/mEU12s0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766267785; c=relaxed/simple; bh=aQdQFCj0u/DYmnpX3yxUKCpgX0hAxOPpw7gffako07Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mHhmSlBoyfDQNTF+HUGmVn7rMaiay0uqjPM4c+J+xpBit19Cx/HHejxlzetLx2yEUlBiLZzmaaxfRvCpKEF06YmDm4lcgDVHEmuKyUzgG0B/30lwzJFGNKaWm96wbcJxggI9yuYzw/AdBtASyu1808hplreduIcmEZtbg/XI8bE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=SzLq1Aey; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SzLq1Aey" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-47755de027eso16665475e9.0 for ; Sat, 20 Dec 2025 13:56:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766267782; x=1766872582; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TOBZQapw11hNFXG1jtZUyB8kVQYLqlZzSumqk/Qw0PM=; b=SzLq1Aey7Vm6D5as2SXEZf8o+PBNq5uXQZUPWjVLwU7nyS1VgH4HtNCnIaduhz/ANY is1nzukgl7BWgy1HoaIqjRzYC20i0fgFeb9zpQqbme0YpROgd+WlGAzPtSgsRTj97xNb 3P5AXeK/Rlj0Te+HljSA8NUgN4xk+lCENL5CquGw0Vl/dsnl1NUnZMeiH1TgOwCbaXaz 30B5fOSigWt7UwBMr6ff5xsatiNmeqRd768oikCvvBQ9WUjJ8xbL7pM//RxWCFJcXay2 mmjXsRIaxUHt5RK8YnkenRj373LoptDZi/KBoFzIb1BHI2DOF5ZthdCWnP67pnVSMSdi ZpwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766267782; x=1766872582; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=TOBZQapw11hNFXG1jtZUyB8kVQYLqlZzSumqk/Qw0PM=; b=XCnLmaloYrh57kTbRA8+7bh5UNxOne0WrC/JUaDYfhVpeJmC4hyHR8zNxkvyvCrL+I sFp4gwpn8C6TyDpoY9ZwvJhFXB7lDH6XROHhBz+hmh9fCyPIGlzNKusvlS+m+vnTIoIn tu58M9uKN4+QtLff/oMA6YTaxtl50QJgzRM0EusJ5gKrOYW6POoPNI6CSpWPhYj4w1Gv 93WQDuhAmRhv9B2crDIPx0/Chyuq+7QO9kBTbz/q7VA5YtJXT1dIhFC8zMT9fHUIIK2Z botC3ZUynD8acx8KnZGtogn1pIBrhRBOmc1BGsiEVSjFAQuDYMAvSuXJEYwOKdXW8Cba jF2g== X-Forwarded-Encrypted: i=1; AJvYcCWKwUOFKjIclRp+MuQ3Chvlfabb84AYmnD/WL+iliHL0No242Jr2ihu9WpvZP7E5I4Tc8kS8GRlcbf6niw=@vger.kernel.org X-Gm-Message-State: AOJu0YzctG4nNPN/Xv8UY9eHOZC1H4EWglyZJaodjRqdWh1GV5tBrT26 EFfBW4F1XdkjwW4Bq9Ujep6isCTyZweZj3yAstVAKezyYEo+5/8DRY83 X-Gm-Gg: AY/fxX5GtRllecr2remTfCjwTUvW6/6qvQI22s9tJdCC2pvtS13zMTZpo00kW1SdN1P YAkjvoke5zXSP0fspMkGOWoXf/sipXLEvat455+SOTsmWjwpApSNXmRlDiSccaDHi2etJLpkfJb Wm6LHnFUH24oZBCmWC9wXpnzXO6T7Pfh1gxYQmuLBgft+JhnuFhiA+GV2A3YPa4UhMvgIPu+noU /aIKQBtDisIr4m3d9uI5JRhVYWUclXJ8AIZljDd8QnhTetGUCHWi3/acqQH8DJjLyYcnFIuRbur h+7pMSl+6QFxRXuPZOnB4JPS+9JL1GjtXCspvDuRVUcodMWAaEX4UAsPkyWWMwiR9fNKDGm4n3t vVyU1f0fSm0mViMCTUWzkbi2nv6iCUQg2lx7ebXQ6hhLTbgo7vNGUqo/Rx1fZMAXpoaosSBbsJg MnzytJSHoBRfO8zU8CdC7FjYhsQC2R/HFaFiCpG5cyhFl4bhdQejEepj8VjC8UGIXpTyeKMpZf X-Google-Smtp-Source: AGHT+IHShGsV361GAb6wZgyQyKUEthwNK7Hxfos7GBUE3Ck2qGgEI3QFOUr+7SqbRjn15NdhnqZeSg== X-Received: by 2002:a05:600c:828c:b0:479:3a87:2092 with SMTP id 5b1f17b1804b1-47d19598e86mr52887745e9.36.1766267781614; Sat, 20 Dec 2025 13:56:21 -0800 (PST) Received: from snowdrop.snailnet.com (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4325c052d34sm3601755f8f.25.2025.12.20.13.56.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Dec 2025 13:56:21 -0800 (PST) From: david.laight.linux@gmail.com To: Thomas Gleixner , Linus Torvalds , Peter Zijlstra , Mathieu Desnoyers , Kees Cook , linux-kernel@vger.kernel.org, akpm@linux-foundation.org, Al Viro Cc: David Laight Subject: [PATCH 2/5] compiler.h: Add generic support for 'autoterminating nested for() loops' Date: Sat, 20 Dec 2025 21:56:05 +0000 Message-Id: <20251220215608.434614-3-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20251220215608.434614-1-david.laight.linux@gmail.com> References: <20251220215608.434614-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: David Laight Autoterminating nested for() loops can be used inside #defines to declare variables that are scoped to the statement that follows. These are used by __scoped_user_access() but may have other uses and the gory details are best separated from the use. Using 'with (declaration)' and 'and_with (declaration)' seems to read reasonably well and doesn't seem to collide with any existing code. As an example the scoped user access definition becomes: with (typeof(uptr) _tmpptr =3D __scoped_user_access_begin(mode, uptr, size= , elbl)) \ and_with (CLASS(user_##mode##_access, scope)(_tmpptr)) \ /* Force modified pointer usage within the scope */ \ and_with (const typeof(uptr) uptr =3D _tmpptr) Signed-off-by: David Laight --- include/linux/compiler.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 04487c9bd751..da89a5efda5a 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -377,6 +377,32 @@ static inline void *offset_to_ptr(const int *off) */ #define prevent_tail_call_optimization() mb() =20 +/* + * Sometimes a #define needs to declare a variable that is scoped + * to the statement that follows without having mismatched {}. + * with (int x =3D expression) { + * statements + * } + * is the same as: + * { + * int x =3D expression; + * statements + * } + * but lets it all be hidden from the call site, eg: + * frobnicate(args) { + * statements + * }=20 + * Only a single variable can be defined, and_with() allows extra ones + * without adding an additional outer loop. + * + * The controlled scope can be terminated using break, continue or goto. + */ +#define with(declaration) \ + for (bool _with_done =3D false; !_with_done; _with_done =3D true) \ + and_with (declaration) +#define and_with(declaration) \ + for (declaration; !_with_done; _with_done =3D true) + #include =20 #endif /* __LINUX_COMPILER_H */ --=20 2.39.5