summaryrefslogtreecommitdiffstats
path: root/src/libudev/libudev-device.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-08-28 06:07:48 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-09-11 05:45:21 +0200
commit3c6ac219296aaba8ef99644b1185326ed114392d (patch)
treeea1936f89e4bc940588e9b1fa1631605e7cbcceb /src/libudev/libudev-device.c
parentlibudev-monitor: use safe_close() in udev_monitor_disconnect() (diff)
downloadsystemd-3c6ac219296aaba8ef99644b1185326ed114392d.tar.xz
systemd-3c6ac219296aaba8ef99644b1185326ed114392d.zip
libudev: use DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC() macro where applicable
Diffstat (limited to 'src/libudev/libudev-device.c')
-rw-r--r--src/libudev/libudev-device.c40
1 files changed, 16 insertions, 24 deletions
diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c
index e6d6f70510..ce8acd59b2 100644
--- a/src/libudev/libudev-device.c
+++ b/src/libudev/libudev-device.c
@@ -201,7 +201,7 @@ struct udev_device *udev_device_new(struct udev *udev) {
errno = ENOMEM;
return NULL;
}
- udev_device->refcount = 1;
+ udev_device->n_ref = 1;
udev_device->udev = udev;
udev_list_init(udev, &udev_device->properties, true);
udev_list_init(udev, &udev_device->tags, true);
@@ -501,6 +501,20 @@ _public_ struct udev *udev_device_get_udev(struct udev_device *udev_device)
return udev_device->udev;
}
+static struct udev_device *udev_device_free(struct udev_device *udev_device) {
+ assert(udev_device);
+
+ sd_device_unref(udev_device->device);
+ udev_device_unref(udev_device->parent);
+
+ udev_list_cleanup(&udev_device->properties);
+ udev_list_cleanup(&udev_device->sysattrs);
+ udev_list_cleanup(&udev_device->tags);
+ udev_list_cleanup(&udev_device->devlinks);
+
+ return mfree(udev_device);
+}
+
/**
* udev_device_ref:
* @udev_device: udev device
@@ -509,13 +523,6 @@ _public_ struct udev *udev_device_get_udev(struct udev_device *udev_device)
*
* Returns: the passed udev device
**/
-_public_ struct udev_device *udev_device_ref(struct udev_device *udev_device)
-{
- if (udev_device)
- udev_device->refcount++;
-
- return udev_device;
-}
/**
* udev_device_unref:
@@ -526,22 +533,7 @@ _public_ struct udev_device *udev_device_ref(struct udev_device *udev_device)
*
* Returns: #NULL
**/
-_public_ struct udev_device *udev_device_unref(struct udev_device *udev_device)
-{
- if (udev_device && (-- udev_device->refcount) == 0) {
- sd_device_unref(udev_device->device);
- udev_device_unref(udev_device->parent);
-
- udev_list_cleanup(&udev_device->properties);
- udev_list_cleanup(&udev_device->sysattrs);
- udev_list_cleanup(&udev_device->tags);
- udev_list_cleanup(&udev_device->devlinks);
-
- free(udev_device);
- }
-
- return NULL;
-}
+DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(struct udev_device, udev_device, udev_device_free);
/**
* udev_device_get_devpath: