mfreadwrite/reader: Add missing allocation check (Coverity).
[wine/zf.git] / dlls / hidclass.sys / main.c
blob50657b80f5e26aac67319351dd8a50904efd2ae1
1 /*
2 * WINE Hid device services
4 * Copyright 2015 Aric Stewart
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define NONAMELESSUNION
22 #include <unistd.h>
23 #include <stdarg.h>
24 #include "hid.h"
25 #include "wine/debug.h"
26 #include "wine/list.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(hid);
30 static struct list minidriver_list = LIST_INIT(minidriver_list);
32 minidriver* find_minidriver(DRIVER_OBJECT *driver)
34 minidriver *md;
35 LIST_FOR_EACH_ENTRY(md, &minidriver_list, minidriver, entry)
37 if (md->minidriver.DriverObject == driver)
38 return md;
40 return NULL;
43 static VOID WINAPI UnloadDriver(DRIVER_OBJECT *driver)
45 minidriver *md;
47 TRACE("Driver Unload\n");
48 md = find_minidriver(driver);
49 if (md)
51 if (md->DriverUnload)
52 md->DriverUnload(md->minidriver.DriverObject);
53 list_remove(&md->entry);
54 HeapFree( GetProcessHeap(), 0, md );
58 NTSTATUS WINAPI HidRegisterMinidriver(HID_MINIDRIVER_REGISTRATION *registration)
60 minidriver *driver;
61 driver = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*driver));
63 if (!driver)
64 return STATUS_NO_MEMORY;
66 driver->DriverUnload = registration->DriverObject->DriverUnload;
67 registration->DriverObject->DriverUnload = UnloadDriver;
69 registration->DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = HID_Device_ioctl;
70 registration->DriverObject->MajorFunction[IRP_MJ_READ] = HID_Device_read;
71 registration->DriverObject->MajorFunction[IRP_MJ_WRITE] = HID_Device_write;
72 registration->DriverObject->MajorFunction[IRP_MJ_CREATE] = HID_Device_create;
73 registration->DriverObject->MajorFunction[IRP_MJ_CLOSE] = HID_Device_close;
75 driver->PNPDispatch = registration->DriverObject->MajorFunction[IRP_MJ_PNP];
76 registration->DriverObject->MajorFunction[IRP_MJ_PNP] = HID_PNP_Dispatch;
78 driver->AddDevice = registration->DriverObject->DriverExtension->AddDevice;
79 registration->DriverObject->DriverExtension->AddDevice = PNP_AddDevice;
81 driver->minidriver = *registration;
82 list_add_tail(&minidriver_list, &driver->entry);
84 return STATUS_SUCCESS;
87 NTSTATUS call_minidriver(ULONG code, DEVICE_OBJECT *device, void *in_buff, ULONG in_size, void *out_buff, ULONG out_size)
89 IRP *irp;
90 IO_STATUS_BLOCK io;
91 KEVENT event;
93 KeInitializeEvent(&event, NotificationEvent, FALSE);
95 irp = IoBuildDeviceIoControlRequest(code, device, in_buff, in_size,
96 out_buff, out_size, TRUE, &event, &io);
98 if (IoCallDriver(device, irp) == STATUS_PENDING)
99 KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
101 return io.u.Status;