[PATCH 13/19] nitro_enclaves: Initialise the CPU pool mutex statically

From: Alexander Graf

Date: Wed Nov 11 2026 - 22:14:38 EST


The ne_cpus setter can run before ne_init(), when the parameter is given
at boot or to modprobe, and then takes ne_cpu_pool.mutex before
mutex_init() ran on it. Initialise the mutex in its definition instead.

Fixes: ff8a4d3e3a99 ("nitro_enclaves: Add logic for setting an enclave vCPU")
Signed-off-by: Alexander Graf <graf@xxxxxxxxxx>
---
drivers/virt/nitro_enclaves/ne_misc_dev.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/virt/nitro_enclaves/ne_misc_dev.c b/drivers/virt/nitro_enclaves/ne_misc_dev.c
index 70d740d64ee17..44a4432be8164 100644
--- a/drivers/virt/nitro_enclaves/ne_misc_dev.c
+++ b/drivers/virt/nitro_enclaves/ne_misc_dev.c
@@ -125,7 +125,9 @@ struct ne_cpu_pool {
int numa_node;
};

-static struct ne_cpu_pool ne_cpu_pool;
+static struct ne_cpu_pool ne_cpu_pool = {
+ .mutex = __MUTEX_INITIALIZER(ne_cpu_pool.mutex),
+};

/**
* struct ne_phys_contig_mem_regions - Contiguous physical memory regions.
@@ -1902,8 +1904,6 @@ static long ne_ioctl(struct file *file, unsigned int cmd, unsigned long arg)

static int __init ne_init(void)
{
- mutex_init(&ne_cpu_pool.mutex);
-
return pci_register_driver(&ne_pci_driver);
}

--
2.47.1