Received: from BL2PR02CU003.outbound.protection.outlook.com (mail-eastusazon11011045.outbound.protection.outlook.com [52.101.52.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06BBF30B535 for ; Fri, 16 Jan 2026 21:50:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.52.45 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768600242; cv=fail; b=g9VB6NOLhh5G9BMiFR4jlJqLgOk+rx05jNxNp6dJ2P3lellIljWJmEy+V/Cs7/Ah1RRiEVk2oG9x/ycfh0tkJR5hVuAqNamd7t9RE9ziLim/Psqv18B6PeOnHEQPIflBsYjLg7yX1Dem/LkbyYqm3+v2S19cNxGWadAsZli2/Mk= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768600242; c=relaxed/simple; bh=RIcH0iPdKMmi3f4/77f33c9F8u4LNxOLCmj6kh3/FRk=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AF3N/EC0YLZh4EWl6TvtkpjZuRVWIFU4mcH+T7wO4AO58fOkPUBmkgJTMph0chsh4AAgYpU65DfEeuXLbtjgijjtl6MOUl+LfO2IUk9nMcZTDuRxAr+uu6Az6vKtfomZjVnsVc/e0LF14w5470bnQqubKXMjdGVJGLIL1q+6YQo= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=nuoL1u7v; arc=fail smtp.client-ip=52.101.52.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="nuoL1u7v" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wf5cRIskX6RYEDfrqAJ7b4dWW+IEGfk/xhLrq+gF6YekN5POwvSwm0jyOs4gYEoWHaAdGftQSN71TGP00pJLmJVoZ4aocjA0tMqFE19VqdsvKy5uXYeiHwYdX3y+qBQ63+1PDjMGQs9BIOPBBAs6SfriZuxs1RjUfKewlRzfrTkT5A94JB5Vo65bpniU6PW4XDMKCvx4avEWRI3D4MDPN+al87/ofza2YN4oJqpPs8S5Gws/wrLFQ/p+7WMm9SQ/KcBBTD3s2AHdvwcNwmz+UYJkM3wF6+GdM8JDo8Wad2N6zBz1syURd4vzmYtWEwmWqBbCJZbAgdYe6GUKBfGq9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ENHJm9Yn9/4bGrGxzSc632ORGbzHF9HItZ95wTpuXhg=; b=dIj7Ea61K+GP3ki4JQN1ecaTZ83pPYtm8eeFke3UXnwT7u/8KrFPKsPwIQz1njKG57EEcD/JaFlMdAAdJvf4ZP1de398pZ2UzDUwb1S2nOMkuBGq7yoYCfwPqDETar4fIwWLfUj/CFhCJHfCLyh6UmdeIggIY5CaioGFp2yx2tuYBzHLBasTE5ea135svDftbrl8NrTflXh1+6JJ8Mo8fzFzr4pMp3Z/z0eJp34rBe59b9SUuf2nae4oWFe72EVPEC/YVgqTM8PDdHwwWqYfUlIwgj3QM6Hhl1ugYudBWJAJemk9+Mo7nq/ddGv65UCBPTkkrIQ3HVJ7IsTKwWBCVg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=google.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ENHJm9Yn9/4bGrGxzSc632ORGbzHF9HItZ95wTpuXhg=; b=nuoL1u7vewcIGviefjI0xiqzwtQOm/PgrQpwKQFKMBmnsFay2x7KwuqS4GdPSvM2ha/xmSPYe/19xPVyF0slMrl4noydm/xpMiwNN+DBrYKG5bJyOw5s2ZB92YBeJCg4f0OAIUgrD5/mh6Xgyf9rqINtDJZNpBy+Dg6hUyrphQzrne4GSOh4J90fwcL8/9SO0tlR37ExUg0XwU9lRNK6/bCGBGi0s/6Ky0L3xwLogAf9XIE+E2oy2w1npe7ASynGvVbUMP9EKkiv+46aU+8i0bDAPk97OPuKfthPcS45TaqpeRHcb4pc90KbkOv4UPB07ySCeE1yP2RCPcYBnbQkCg== Received: from DS7PR05CA0067.namprd05.prod.outlook.com (2603:10b6:8:57::12) by DS0PR12MB8442.namprd12.prod.outlook.com (2603:10b6:8:125::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.5; Fri, 16 Jan 2026 21:50:33 +0000 Received: from DS2PEPF0000343C.namprd02.prod.outlook.com (2603:10b6:8:57:cafe::72) by DS7PR05CA0067.outlook.office365.com (2603:10b6:8:57::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9542.4 via Frontend Transport; Fri, 16 Jan 2026 21:50:31 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by DS2PEPF0000343C.mail.protection.outlook.com (10.167.18.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9542.4 via Frontend Transport; Fri, 16 Jan 2026 21:50:33 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Fri, 16 Jan 2026 13:50:14 -0800 Received: from ttabi.nvidia.com (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Fri, 16 Jan 2026 13:50:13 -0800 From: Timur Tabi To: Matthew Maurer , Danilo Krummrich , Gary Guo , John Hubbard , "Joel Fernandes" , Alexandre Courbot , , Subject: [PATCH v5 2/8] rust: debugfs: add Dir::empty() for conditional debugfs usage Date: Fri, 16 Jan 2026 15:49:53 -0600 Message-ID: <20260116214959.641032-3-ttabi@nvidia.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260116214959.641032-1-ttabi@nvidia.com> References: <20260116214959.641032-1-ttabi@nvidia.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NVConfidentiality: public Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS2PEPF0000343C:EE_|DS0PR12MB8442:EE_ X-MS-Office365-Filtering-Correlation-Id: 6dac5975-8243-486f-d4c8-08de55494684 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|82310400026|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?oAN7OCYTqNOwiHRPBQWCZnRvdRDR6kqv7qtGLafkcTzZkt8Bv2BdNH5LEnt4?= =?us-ascii?Q?9t39vp96aX2gGzH29hZYo0zbbJKCKi9WdDdOprC3+A5HT898V6k4XIumoM8O?= =?us-ascii?Q?XD+OftabAGmemU9qWtKhszeQIESnnqc762ziAFjM5CJ4P3nlK7RtPGkdobs8?= =?us-ascii?Q?XVl6/47wAQHVJLH4bG01QPIU9UdDIdXtGbPfIw5R8pZnmrSxmCe711yX6JNU?= =?us-ascii?Q?hSBNRQTfyYuATAWltHgC3XrmBI9lPrqNfmSmSVWRTB+haBtdWoyuExA8cpUr?= =?us-ascii?Q?cmP1dwT9+UxTAnJNeK/kmRjq3MdBPb8zaeNBWqVAz6PPCdiKh8XI3+Q1sJYU?= =?us-ascii?Q?6578lb7WWKVrL/OMDz5LkGXyAqLpHt2+JLAguSb3YmWLiTwh51LCUl1lhggd?= =?us-ascii?Q?jtwwuAJfd8MYyeKEuUoe2VuPZ6/JaoXSfBzX8N0KgtX/xadsIvOWFfCOLfdz?= =?us-ascii?Q?Z9SzFqqIfk8RQhHlfCFenipdabXorDqy3+x/MDAZe9OveVm0xlcE1lcm0MWV?= =?us-ascii?Q?8y6d//ZikdPoUhF6Gseb2HNAEtshXDeWqhkMzlPX72H6e3qHGIcQcyrjxUmh?= =?us-ascii?Q?RwbqC1gMmtft8rfhMeMrGdcFXbhCgaX3KJGK65/zJ3tkUYxCv2Rt/jmFEYwn?= =?us-ascii?Q?WPfCCZMCTSya3MAeGZTfyIGce/EociP1FumpdJGJKo4ZgInAXThpHrxM5ddK?= =?us-ascii?Q?YCtMmymJVkaL+OCH44dY5pFH/RfL2OBMSvcPyj9nFm0pvz8i/Gvj/8tUTG0/?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Q96YmritycuStZJePjWVQ9i?= =?us-ascii?Q?4AFyxw=3D=3D?= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(376014)(82310400026)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2026 21:50:33.5841 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6dac5975-8243-486f-d4c8-08de55494684 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DS2PEPF0000343C.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8442 Add Dir::empty() which returns a &'static reference to a no-op Dir. All file and subdirectory operations on this directory silently succeed without creating actual filesystem entries. This enables callers to use a single code path regardless of whether debugfs is available at runtime. For example: let dir = optional_debugfs_root.unwrap_or_else(|| Dir::empty()); dir.scope(data, name, |d, s| { ... }) The returned reference has 'static lifetime, allowing initializers returned by scope() to be used outside the immediate scope where the Dir reference was obtained. Signed-off-by: Timur Tabi --- rust/kernel/debugfs.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/rust/kernel/debugfs.rs b/rust/kernel/debugfs.rs index facad81e8290..44ff2b37786a 100644 --- a/rust/kernel/debugfs.rs +++ b/rust/kernel/debugfs.rs @@ -110,6 +110,24 @@ pub fn new(name: &CStr) -> Self { Dir::create(name, None) } + /// Returns a reference to a static no-op directory that doesn't create any debugfs entries. + /// + /// All file and subdirectory creation operations on this directory will silently succeed + /// without creating actual filesystem entries. This is useful when you want to conditionally + /// enable debugfs but use the same code path regardless. + pub fn empty() -> &'static Self { + #[cfg(CONFIG_DEBUG_FS)] + { + static EMPTY: Dir = Dir(None); + &EMPTY + } + #[cfg(not(CONFIG_DEBUG_FS))] + { + static EMPTY: Dir = Dir(); + &EMPTY + } + } + /// Creates a subdirectory within this directory. /// /// # Examples -- 2.52.0