Rémi Bernon : winebus.sys: Use helpers to create and destroy unix devices.
Alexandre Julliard
julliard at winehq.org
Tue Sep 14 16:00:11 CDT 2021
Module: wine
Branch: master
Commit: b86eade743c1edd6e181373c7f1876ea0b643169
URL: https://source.winehq.org/git/wine.git/?a=commit;h=b86eade743c1edd6e181373c7f1876ea0b643169
Author: Rémi Bernon <rbernon at codeweavers.com>
Date: Tue Sep 14 08:58:22 2021 +0200
winebus.sys: Use helpers to create and destroy unix devices.
Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/winebus.sys/bus_iohid.c | 7 ++-----
dlls/winebus.sys/bus_sdl.c | 8 ++------
dlls/winebus.sys/bus_udev.c | 12 ++++--------
dlls/winebus.sys/unix_private.h | 3 +++
dlls/winebus.sys/unixlib.c | 15 +++++++++++++++
5 files changed, 26 insertions(+), 19 deletions(-)
diff --git a/dlls/winebus.sys/bus_iohid.c b/dlls/winebus.sys/bus_iohid.c
index d362906637a..93b3605f8d2 100644
--- a/dlls/winebus.sys/bus_iohid.c
+++ b/dlls/winebus.sys/bus_iohid.c
@@ -139,8 +139,7 @@ static void handle_IOHIDDeviceIOHIDReportCallback(void *context,
static void iohid_device_destroy(struct unix_device *iface)
{
- struct platform_private *private = impl_from_unix_device(iface);
- HeapFree(GetProcessHeap(), 0, private);
+ unix_device_destroy(iface);
}
static int iohid_device_compare(struct unix_device *iface, void *context)
@@ -337,9 +336,7 @@ static void handle_DeviceMatchingCallback(void *context, IOReturn result, void *
TRACE("dev %p, desc %s.\n", IOHIDDevice, debugstr_device_desc(&desc));
- if (!(private = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct platform_private))))
- return;
- private->unix_device.vtbl = &iohid_device_vtbl;
+ if (!(private = unix_device_create(&iohid_device_vtbl, sizeof(struct platform_private)))) return;
private->device = IOHIDDevice;
private->buffer = NULL;
diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c
index 73562fec14f..cda9e9bdcd9 100644
--- a/dlls/winebus.sys/bus_sdl.c
+++ b/dlls/winebus.sys/bus_sdl.c
@@ -480,9 +480,7 @@ failed:
static void sdl_device_destroy(struct unix_device *iface)
{
- struct platform_private *ext = impl_from_unix_device(iface);
-
- HeapFree(GetProcessHeap(), 0, ext);
+ unix_device_destroy(iface);
}
static int sdl_device_compare(struct unix_device *iface, void *context)
@@ -761,9 +759,7 @@ static void sdl_add_device(unsigned int index)
TRACE("%s id %d, desc %s.\n", controller ? "controller" : "joystick", id, debugstr_device_desc(&desc));
- if (!(private = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*private))))
- return;
- private->unix_device.vtbl = &sdl_device_vtbl;
+ if (!(private = unix_device_create(&sdl_device_vtbl, sizeof(struct platform_private)))) return;
private->sdl_joystick = joystick;
private->sdl_controller = controller;
private->id = id;
diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c
index 25a408489a4..004bbb379c4 100644
--- a/dlls/winebus.sys/bus_udev.c
+++ b/dlls/winebus.sys/bus_udev.c
@@ -561,7 +561,7 @@ static void hidraw_device_destroy(struct unix_device *iface)
close(private->device_fd);
udev_device_unref(private->udev_device);
- HeapFree(GetProcessHeap(), 0, private);
+ unix_device_destroy(iface);
}
static int udev_device_compare(struct unix_device *iface, void *platform_dev)
@@ -815,7 +815,7 @@ static void lnxev_device_destroy(struct unix_device *iface)
close(ext->base.device_fd);
udev_device_unref(ext->base.udev_device);
- HeapFree(GetProcessHeap(), 0, ext);
+ unix_device_destroy(iface);
}
static DWORD CALLBACK lnxev_device_report_thread(void *args);
@@ -1084,9 +1084,7 @@ static void udev_add_device(struct udev_device *dev)
if (strcmp(subsystem, "hidraw") == 0)
{
- if (!(private = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct platform_private))))
- return;
- private->unix_device.vtbl = &hidraw_device_vtbl;
+ if (!(private = unix_device_create(&hidraw_device_vtbl, sizeof(struct platform_private)))) return;
EnterCriticalSection(&udev_cs);
list_add_tail(&device_list, &private->unix_device.entry);
LeaveCriticalSection(&udev_cs);
@@ -1098,9 +1096,7 @@ static void udev_add_device(struct udev_device *dev)
#ifdef HAS_PROPER_INPUT_HEADER
else if (strcmp(subsystem, "input") == 0)
{
- if (!(private = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct wine_input_private))))
- return;
- private->unix_device.vtbl = &lnxev_device_vtbl;
+ if (!(private = unix_device_create(&lnxev_device_vtbl, sizeof(struct wine_input_private)))) return;
EnterCriticalSection(&udev_cs);
list_add_tail(&device_list, &private->unix_device.entry);
LeaveCriticalSection(&udev_cs);
diff --git a/dlls/winebus.sys/unix_private.h b/dlls/winebus.sys/unix_private.h
index 2a878cdb583..3b0375bb761 100644
--- a/dlls/winebus.sys/unix_private.h
+++ b/dlls/winebus.sys/unix_private.h
@@ -47,6 +47,9 @@ struct unix_device
struct list entry;
};
+extern void *unix_device_create(const struct unix_device_vtbl *vtbl, SIZE_T size) DECLSPEC_HIDDEN;
+extern void unix_device_destroy(struct unix_device *iface) DECLSPEC_HIDDEN;
+
extern NTSTATUS sdl_bus_init(void *) DECLSPEC_HIDDEN;
extern NTSTATUS sdl_bus_wait(void *) DECLSPEC_HIDDEN;
extern NTSTATUS sdl_bus_stop(void *) DECLSPEC_HIDDEN;
diff --git a/dlls/winebus.sys/unixlib.c b/dlls/winebus.sys/unixlib.c
index 2407a2af468..b37d9534540 100644
--- a/dlls/winebus.sys/unixlib.c
+++ b/dlls/winebus.sys/unixlib.c
@@ -213,6 +213,21 @@ static NTSTATUS keyboard_device_create(void *args)
return STATUS_SUCCESS;
}
+void *unix_device_create(const struct unix_device_vtbl *vtbl, SIZE_T size)
+{
+ struct unix_device *iface;
+
+ if (!(iface = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size))) return NULL;
+ iface->vtbl = vtbl;
+
+ return iface;
+}
+
+void unix_device_destroy(struct unix_device *iface)
+{
+ HeapFree(GetProcessHeap(), 0, iface);
+}
+
static NTSTATUS unix_device_remove(void *args)
{
struct unix_device *iface = args;
More information about the wine-cvs
mailing list