winebus.sys: Use helpers to create and destroy unix devices.

Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Rémi Bernon 2021-09-14 08:58:22 +02:00 committed by Alexandre Julliard
parent cd830398dd
commit b86eade743
5 changed files with 26 additions and 19 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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;