]> xenbits.xensource.com Git - libvirt.git/commitdiff
node_device_udev: Add support for `g_autoptr` to `udevEventData`
authorMarc Hartmayer <mhartmay@linux.ibm.com>
Tue, 23 Apr 2024 18:09:04 +0000 (20:09 +0200)
committerJonathon Jongsma <jjongsma@redhat.com>
Tue, 18 Jun 2024 14:00:34 +0000 (09:00 -0500)
Use this feature in `udevEventDataNew`.

Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
src/node_device/node_device_udev.c

index af640d6f2b7cbe9b81b65413bea3f7fecc4e790a..766dcaffd464da5be559c50d1bad22911a6e5b8e 100644 (file)
@@ -78,6 +78,7 @@ struct _udevEventData {
     /* Immutable pointer, self-locking APIs */
     virThreadPool *workerPool;
 };
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(udevEventData, virObjectUnref);
 
 static virClass *udevEventDataClass;
 
@@ -121,7 +122,7 @@ VIR_ONCE_GLOBAL_INIT(udevEventData);
 static udevEventData *
 udevEventDataNew(void)
 {
-    udevEventData *ret = NULL;
+    g_autoptr(udevEventData) ret = NULL;
 
     if (udevEventDataInitialize() < 0)
         return NULL;
@@ -129,19 +130,15 @@ udevEventDataNew(void)
     if (!(ret = virObjectLockableNew(udevEventDataClass)))
         return NULL;
 
-    if (virCondInit(&ret->udevThreadCond) < 0) {
-        virObjectUnref(ret);
+    if (virCondInit(&ret->udevThreadCond) < 0)
         return NULL;
-    }
 
-    if (virMutexInit(&ret->mdevctlLock) < 0) {
-        virObjectUnref(ret);
+    if (virMutexInit(&ret->mdevctlLock) < 0)
         return NULL;
-    }
 
     ret->mdevctlTimeout = -1;
     ret->watch = -1;
-    return ret;
+    return g_steal_pointer(&ret);
 }
 
 typedef enum {