From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796380036; b=x2amDT5Lg+bTwL4ff4kGebC9eIdMLtVRBEcr5lHgNbKTwJkqW9nNkoy/1Lc1jU4v67ph kwbGtAlQRNTOG6vxujkZKdU7xU7E12PvZp31kMUYsc/SEx4bgmau2FKV0hHmdC2aOEOcy tt+L4qlmAcpjA8VKw//98UUQZ892axi6X6I70PWc2uv4Tv1lUFvEnKcUMDk6D1hHmma8q 5zHEqJ6QjLOAoVaxEWVf6jTeOAXZuV9AJBwrQIF+uCFJkBvLKxNDYlxbMq4jjYwMmo7tz c5RSRIvrOwopzNlW0WuIJQwIvS175UVxgtL3iW7P+RrMp/Gh2CCtpIUTbNcczGbONXA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380036; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=BZEw9AYUAxSjVFJQw1TIv1OkLEVw8Y4SeXTVMrvP0sw=; b=dVwDf1I7U01D/HSNy/4E0QwHC7Vv5O7DLoD6vMl37EPWJhh8xsQhdoxmKEb1NLi4qCqN Qy9CmzfPJW63N6ylSkBllVsEPgDtT4nosSqJqcO9i0ogBN5iqbHF94EfFKMr6rPT0ZO0x wDSCu30H2isaa6txPuR8pOwZ+k7+Q9wyctcaRFYwt2TNDqQQtLqjDAKI7XyQIfecVeJud gIdtbuykWK7wL2Xt1fM5aCtaARNCoIr09TuoNNPm2m1zYPDepi6AAqFOAB+mQxeGJqwhy EnMPkFYGNNET0f1c1EgFyfnFA2meilvtCoedeVqkJXxNB49zIWaYcwQiApo4lnIOwtg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kChDO7DB; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5F46606A322; Fri, 4 Dec 2026 10:27:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kChDO7DB Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796380036; b=RxwL+Qihu9+gowczNwFmUbEGtE09r2bd21yvQRU6DEG1nciePPpR9XlEKK7N/qHevmMa YWvZWFvo+LCb3CyOACKKbCwUJTRTwRUdD+Q8EuA24UDW3Nn1QpjhfMH2ycOINJCxFYZIN oUah68eAGL1PGFzZjKYsDS3xkBAhuvRLA6+58T1MmsF34FJELQye6n7pabLIedBnCHokv c5AYA3u/jd5LlGIYzN8e4p0xEEdfG5U1s+h11rVX/Wdi0fjTEIL7910ieYokDRXZbtC3O ursbnmNBiRQ3uNsbRQ9vDSofEO0VvG38sUtbeamuWxQZkUuOYSyqzGZpT7vgY8m7XeA== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796380036; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=BZEw9AYUAxSjVFJQw1TIv1OkLEVw8Y4SeXTVMrvP0sw=; b=cUB80wYWXxDEMe91Ut1IbkRND1BhdyOI2f3i0B/HQYoOTisyhl41e5HmBBVHrvgGX/rs hRRV+oVohRjkynHydUFIKJixeWoCFZ0pwjJDIMKcEoN3zoOU9Omd1lLy5GDeEh8jw60Ze vMaCA6WPXUzLUZMOHIooGVfMG0+7DhrSXMulBPQbQHKsPHY6MnYjmt/np/f8ig4pmNMBs A6wY58T+DwsyKRiCpIkdaAVDftNdoCwZdyQTlVe3JmSWNP5u1np95UAfJevlyF7+Wpo+E 2xgUeg1pUb4A3ebvUze8JWiEnF95EgBwpq/+ovRlXwnC4corgHSpz/aF/Zzq45NvZAw== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id C6E5D1F000C2; Fri, 4 Dec 2026 10:27:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796380036; bh=BZEw9AYUAxSjVFJQw1TIv1OkLEVw8Y4SeXTVMrvP0sw=; h=From:Date:Subject:To:Cc:Reply-To; b=kChDO7DB/RSAM39zTjzuyzVpcbEEJkxBNM7wW3Lbq7r9LEWjQa4mFyPE3bRzp7RPh NGcTIw42xqJzdEdCMIellyj6QlD1ob121w80YCpWl1bv0ja3ENbnDkUyiEW+PkxF1x FviZJsb/IQS+zsa1JyVI6f2CmojbfznWNST7otvVxNsDUY4wCqGNlzo8JGnWYa2RoP YpFEoUPd8cXlwWNah1kwryyetAPlCXWmI+D1AXkI5c6f72dZFmLSOLsLYZ63HeWjt3 Db9LX3+W7WjqvShFnz7I4r+BcweWngd00bGphkjjtLz9W0q7W5No6nyqDWy2S8Zw4S E0f+LY61YvfFw== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 54B824DA20; Fri, 4 Dec 2026 10:27:15 +0000 (UTC) From: Pavee Zheng via B4 Relay Date: Fri, 04 Dec 2026 18:26:18 +0800 Subject: [PATCH v2] kconfig: tests: avoid mutating extra_env dicts in Conf X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261204-patch-kconfig-tests-extra-env-v2-1-fe3787d1b040@gmail.com> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/42OQQ6CMBBFr0K6dkwpgujKexgWpZ3CqLSkrQ2Gc HcBL+DyJS/v/5kF9ISBXbOZeUwUyNkVxCFjqpe2QyC9MhNcVLngBYwyqh6eyllDHUQMMQBO0Ut Am4ALXZvyXKiy5WxtjB4NTXv/3vw4vNsHqrhFN6OnEJ3/7AdSvnn/bqUccsBTrUzNdaXLy60bJ L2Oyg2sWZblC8/iwzLcAAAA X-Change-ID: 20261203-patch-kconfig-tests-extra-env-02d8f573c5b0 To: Nathan Chancellor , Nicolas Schier , Julian Braha Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Pavee Zheng X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796380034; l=5213; i=pavee.zheng@gmail.com; s=20261203; h=from:subject:message-id; bh=VPUu/ygjcehxxenQhgEPeRpXizg45WAE5pCqvqfI8uE=; b=f39wx63/iTsHIQvaJashBlw9o6MXPvEIWSnmaXWyVpMnyKte29Cvb/n3fvtV55yZwn3j6oRRQ Zr+lIu6VHNHCjVm4AJmRhzPbaJjfTpow48GbQapPxTIxZEUGoykY0Rh X-Developer-Key: i=pavee.zheng@gmail.com; a=ed25519; pk=tKWX/JHvHgKJscWsVefc3+t39eSysVDI8/ZkQl1Rlyo= X-Endpoint-Received: by B4 Relay for pavee.zheng@gmail.com/20261203 with auth_id=1729 X-Original-From: Pavee Zheng Reply-To: pavee.zheng@gmail.com Content-Transfer-Encoding: 7bit From: Pavee Zheng Ruff's B006 (mutable-argument-default) lint flags using mutable data structures such as {} as default argument values because Python evaluates default arguments once at function definition time and shares the same object across all calls, so in-place mutations persist across subsequent calls. Conf._run_conf() and Conf._allconfig() both declare extra_env={} and mutate extra_env in place: - Conf._allconfig() assigns extra_env['KCONFIG_ALLCONFIG'] when all_config is set. No existing test currently passes a non-None all_config to allyesconfig(), allmodconfig(), allnoconfig(), or alldefconfig(), so this does not trigger a failure today, but a future caller doing so would leave a stale KCONFIG_ALLCONFIG entry in the shared default dictionary for subsequent calls in the same pytest session. - Conf._run_conf() assigns extra_env['srctree'], mutating both its default dictionary and caller-owned dictionaries passed via extra_env (such as warn_changed_input in scripts/kconfig/tests/warn_changed_input/__init__.py). As a defensive cleanup and readability improvement, default extra_env to None in both methods. In _run_conf(), merge extra_env into the local env dictionary and set env['srctree'] there instead of mutating extra_env. In _allconfig(), build a fresh local dictionary copy before inserting KCONFIG_ALLCONFIG. Signed-off-by: Pavee Zheng --- Found with ruff (B006) and prepared with AI coding assistant help (Antigravity). Verified on top of kbuild/linux.git (kbuild-for-next, 1b9279a567d0) with ruff 0.17.6 ("ruff check --select B006,F,E,W scripts/kconfig/tests/conftest.py", 2 B006 diagnostics before and 0 after), scripts/checkpatch.pl --strict, and in a Linux container (Python 3.11.2, pytest 7.2.1) with "make O=/tmp/build testconfig" (35 passed) plus an end-to-end regression check against the compiled scripts/kconfig/conf binary confirming no KCONFIG_ALLCONFIG leak across allnoconfig() calls and no in-place mutation of caller-owned extra_env dictionaries in _run_conf() or _allconfig(). Changes in v2: - Drop both Fixes: tags since no existing test triggers the all_config leak, as pointed out by Julian Braha. - Reframe the commit message around Ruff lint B006 and readability / defensive cleanup. - Move AI assistance and verification details below the '---' cut line. - Rebase onto kbuild/linux.git (kbuild-for-next, 1b9279a567d0) and trim stale Fixes-derived recipients. - Link to v1: https://patch.msgid.link/20261203-patch-kconfig-tests-extra-env-v1-1-e48cf80d6d59@gmail.com --- scripts/kconfig/tests/conftest.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/scripts/kconfig/tests/conftest.py b/scripts/kconfig/tests/conftest.py index d22c080a4e40..38e6ab2c264a 100644 --- a/scripts/kconfig/tests/conftest.py +++ b/scripts/kconfig/tests/conftest.py @@ -37,7 +37,7 @@ class Conf: # runners def _run_conf(self, mode, dot_config=None, out_file='.config', - interactive=False, in_keys=None, extra_env={}, + interactive=False, in_keys=None, extra_env=None, silent=False): """Run text-based Kconfig executable and save the result. @@ -54,9 +54,6 @@ class Conf: command.append('-s') command += [mode, 'Kconfig'] - # Override 'srctree' environment to make the test as the top directory - extra_env['srctree'] = self._test_dir - # Clear all KCONFIG_* environment variables env = { varname: os.environ[varname] @@ -64,6 +61,12 @@ class Conf: if not varname.startswith("KCONFIG_") } + if extra_env: + env.update(extra_env) + + # Override 'srctree' environment to make the test as the top directory + env['srctree'] = self._test_dir + # Run Kconfig in a temporary directory. # This directory is automatically removed when done. with tempfile.TemporaryDirectory() as temp_dir: @@ -78,7 +81,7 @@ class Conf: stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=temp_dir, - env=dict(env, **extra_env)) + env=env) # If input key sequence is given, feed it to stdin. if in_keys: @@ -176,7 +179,8 @@ class Conf: defconfig_path = os.path.join(self._test_dir, defconfig) return self._run_conf('--defconfig={}'.format(defconfig_path)) - def _allconfig(self, mode, all_config, extra_env={}): + def _allconfig(self, mode, all_config, extra_env=None): + extra_env = dict(extra_env) if extra_env else {} if all_config: all_config_path = os.path.join(self._test_dir, all_config) extra_env['KCONFIG_ALLCONFIG'] = all_config_path --- base-commit: 1b9279a567d09a2be46f5ac233071b3aea0e7f8c change-id: 20261203-patch-kconfig-tests-extra-env-02d8f573c5b0 Best regards, -- Pavee Zheng