public inbox for wireguard@lists.zx2c4.com
 help / color / mirror / Atom feed
From: Jean-Alexandre CHRONE <Jean-Alexandre.CHRONE@stormshield.eu>
To: "wireguard@lists.zx2c4.com" <wireguard@lists.zx2c4.com>
Cc: Jean-Alexandre CHRONE <Jean-Alexandre.CHRONE@stormshield.eu>
Subject: [PATCH] api: use mutex when removing instance on close adapter
Date: Mon, 2 Feb 2026 14:36:00 +0000	[thread overview]
Message-ID: <7ef930c54a4b4aa5bd3ecd9cf01fe12a@stormshield.eu> (raw)

From 298267d3ead7110880a5dc0f5d0e8822600d30c0 Mon Sep 17 00:00:00 2001
From: "jean-alexandre.chrone" <jean-alexandre.chrone@stormshield.eu>
Date: Mon, 2 Feb 2026 15:24:12 +0100
Subject: [PATCH] api: use mutex when removing instance on close adapter

on successive create and close there might be some error logged
---
 api/adapter.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/api/adapter.c b/api/adapter.c
index 0dd8c42..042645c 100644
--- a/api/adapter.c
+++ b/api/adapter.c
@@ -158,7 +158,8 @@ VOID AdapterCleanupOrphanedDevices(VOID)
             continue;
         }
         ULONG Status, Code;
-        if (CM_Get_DevNode_Status(&Status, &Code, DevInfoData.DevInst, 0) == CR_SUCCESS && !(Status & DN_HAS_PROBLEM))
+        CONFIGRET Ret = CM_Get_DevNode_Status(&Status, &Code, DevInfoData.DevInst, 0);
+        if ((Ret == CR_SUCCESS && !(Status & DN_HAS_PROBLEM)) || Ret == CR_NO_SUCH_DEVNODE)
             continue;
 
         DEVPROPTYPE PropType;
@@ -195,8 +196,16 @@ WintunCloseAdapter(WINTUN_ADAPTER *Adapter)
         SwDeviceClose(Adapter->SwDevice);
     if (Adapter->DevInfo)
     {
+        HANDLE DeviceInstallationMutex = NamespaceTakeDeviceInstallationMutex();
+        if (DeviceInstallationMutex == NULL)
+            LOG_LAST_ERROR(L"Failed to take device installation mutex");
+
         if (!AdapterRemoveInstance(Adapter->DevInfo, &Adapter->DevInfoData))
             LOG_LAST_ERROR(L"Failed to remove adapter when closing");
+
+        if (DeviceInstallationMutex != NULL)
+            NamespaceReleaseMutex(DeviceInstallationMutex);
+
         SetupDiDestroyDeviceInfoList(Adapter->DevInfo);
     }
     Free(Adapter);
-- 
2.52.0.windows.1


             reply	other threads:[~2026-02-08 18:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-02 14:36 Jean-Alexandre CHRONE [this message]
2026-03-06 10:05 ` [PATCH] api: use mutex when removing instance on close adapter Jean-Alexandre CHRONE

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7ef930c54a4b4aa5bd3ecd9cf01fe12a@stormshield.eu \
    --to=jean-alexandre.chrone@stormshield.eu \
    --cc=wireguard@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox