In case of error, free the input data buffer only if we just allocated it.

svn path=/trunk/; revision=23052
This commit is contained in:
Hervé Poussineau 2006-07-13 22:20:54 +00:00
parent 19ff9cb593
commit d0bbf9199b
2 changed files with 38 additions and 6 deletions

View file

@ -126,7 +126,7 @@ ClassDeviceControl(
PLIST_ENTRY Head = &((PCLASS_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->ListHead; PLIST_ENTRY Head = &((PCLASS_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->ListHead;
if (Head->Flink != Head) if (Head->Flink != Head)
{ {
/* We have at least one keyboard */ /* We have at least one device */
PPORT_DEVICE_EXTENSION DevExt = CONTAINING_RECORD(Head->Flink, PORT_DEVICE_EXTENSION, ListEntry); PPORT_DEVICE_EXTENSION DevExt = CONTAINING_RECORD(Head->Flink, PORT_DEVICE_EXTENSION, ListEntry);
IoGetCurrentIrpStackLocation(Irp)->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; IoGetCurrentIrpStackLocation(Irp)->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
IoSkipCurrentIrpStackLocation(Irp); IoSkipCurrentIrpStackLocation(Irp);
@ -553,6 +553,9 @@ ConnectPortDriver(
CONNECT_DATA ConnectData; CONNECT_DATA ConnectData;
NTSTATUS Status; NTSTATUS Status;
DPRINT("Connecting PortDO %p [%wZ] to ClassDO %p\n",
PortDO, &PortDO->DriverObject->DriverName, ClassDO);
KeInitializeEvent(&Event, NotificationEvent, FALSE); KeInitializeEvent(&Event, NotificationEvent, FALSE);
ConnectData.ClassDeviceObject = ClassDO; ConnectData.ClassDeviceObject = ClassDO;
@ -590,6 +593,18 @@ ConnectPortDriver(
return IoStatus.Status; return IoStatus.Status;
} }
/* Send IOCTL_INTERNAL_*_DISCONNECT to port */
static NTSTATUS
DisconnectPortDriver(
IN PDEVICE_OBJECT PortDO)
{
DPRINT("Disconnecting PortDO %p [%wZ]\n",
PortDO, &PortDO->DriverObject->DriverName);
DPRINT1("FIXME: Need to send IOCTL_INTERNAL_*_DISCONNECT\n");
return STATUS_NOT_IMPLEMENTED;
}
static NTSTATUS NTAPI static NTSTATUS NTAPI
ClassAddDevice( ClassAddDevice(
IN PDRIVER_OBJECT DriverObject, IN PDRIVER_OBJECT DriverObject,
@ -686,16 +701,17 @@ ClassAddDevice(
cleanup: cleanup:
if (!(Fdo->Flags & DO_DEVICE_INITIALIZING)) if (!(Fdo->Flags & DO_DEVICE_INITIALIZING))
DPRINT1("FIXME: Need to send IOCTL_INTERNAL_*_DISCONNECT\n"); DisconnectPortDriver(Fdo);
if (DeviceExtension) if (DeviceExtension)
{ {
if (DeviceExtension->LowerDevice) if (DeviceExtension->LowerDevice)
IoDetachDevice(DeviceExtension->LowerDevice); IoDetachDevice(DeviceExtension->LowerDevice);
if (DriverExtension->ConnectMultiplePorts && DeviceExtension->ClassDO) if (!DriverExtension->ConnectMultiplePorts && DeviceExtension->ClassDO)
{ {
PCLASS_DEVICE_EXTENSION ClassDeviceExtension; PCLASS_DEVICE_EXTENSION ClassDeviceExtension;
ClassDeviceExtension = (PCLASS_DEVICE_EXTENSION)DeviceExtension->ClassDO->DeviceExtension; ClassDeviceExtension = (PCLASS_DEVICE_EXTENSION)DeviceExtension->ClassDO->DeviceExtension;
ExFreePool(ClassDeviceExtension->PortData); ExFreePool(ClassDeviceExtension->PortData);
IoDeleteDevice(DeviceExtension->ClassDO);
} }
} }
if (Fdo) if (Fdo)

View file

@ -123,7 +123,7 @@ ClassDeviceControl(
PLIST_ENTRY Head = &((PCLASS_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->ListHead; PLIST_ENTRY Head = &((PCLASS_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->ListHead;
if (Head->Flink != Head) if (Head->Flink != Head)
{ {
/* We have at least one mouse */ /* We have at least one device */
PPORT_DEVICE_EXTENSION DevExt = CONTAINING_RECORD(Head->Flink, PORT_DEVICE_EXTENSION, ListEntry); PPORT_DEVICE_EXTENSION DevExt = CONTAINING_RECORD(Head->Flink, PORT_DEVICE_EXTENSION, ListEntry);
IoGetCurrentIrpStackLocation(Irp)->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; IoGetCurrentIrpStackLocation(Irp)->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
IoSkipCurrentIrpStackLocation(Irp); IoSkipCurrentIrpStackLocation(Irp);
@ -529,6 +529,9 @@ ConnectPortDriver(
CONNECT_DATA ConnectData; CONNECT_DATA ConnectData;
NTSTATUS Status; NTSTATUS Status;
DPRINT("Connecting PortDO %p [%wZ] to ClassDO %p\n",
PortDO, &PortDO->DriverObject->DriverName, ClassDO);
KeInitializeEvent(&Event, NotificationEvent, FALSE); KeInitializeEvent(&Event, NotificationEvent, FALSE);
ConnectData.ClassDeviceObject = ClassDO; ConnectData.ClassDeviceObject = ClassDO;
@ -566,6 +569,18 @@ ConnectPortDriver(
return IoStatus.Status; return IoStatus.Status;
} }
/* Send IOCTL_INTERNAL_*_DISCONNECT to port */
static NTSTATUS
DisconnectPortDriver(
IN PDEVICE_OBJECT PortDO)
{
DPRINT("Disconnecting PortDO %p [%wZ]\n",
PortDO, &PortDO->DriverObject->DriverName);
DPRINT1("FIXME: Need to send IOCTL_INTERNAL_*_DISCONNECT\n");
return STATUS_NOT_IMPLEMENTED;
}
static NTSTATUS NTAPI static NTSTATUS NTAPI
ClassAddDevice( ClassAddDevice(
IN PDRIVER_OBJECT DriverObject, IN PDRIVER_OBJECT DriverObject,
@ -662,16 +677,17 @@ ClassAddDevice(
cleanup: cleanup:
if (!(Fdo->Flags & DO_DEVICE_INITIALIZING)) if (!(Fdo->Flags & DO_DEVICE_INITIALIZING))
DPRINT1("FIXME: Need to send IOCTL_INTERNAL_*_DISCONNECT\n"); DisconnectPortDriver(Fdo);
if (DeviceExtension) if (DeviceExtension)
{ {
if (DeviceExtension->LowerDevice) if (DeviceExtension->LowerDevice)
IoDetachDevice(DeviceExtension->LowerDevice); IoDetachDevice(DeviceExtension->LowerDevice);
if (DriverExtension->ConnectMultiplePorts && DeviceExtension->ClassDO) if (!DriverExtension->ConnectMultiplePorts && DeviceExtension->ClassDO)
{ {
PCLASS_DEVICE_EXTENSION ClassDeviceExtension; PCLASS_DEVICE_EXTENSION ClassDeviceExtension;
ClassDeviceExtension = (PCLASS_DEVICE_EXTENSION)DeviceExtension->ClassDO->DeviceExtension; ClassDeviceExtension = (PCLASS_DEVICE_EXTENSION)DeviceExtension->ClassDO->DeviceExtension;
ExFreePool(ClassDeviceExtension->PortData); ExFreePool(ClassDeviceExtension->PortData);
IoDeleteDevice(DeviceExtension->ClassDO);
} }
} }
if (Fdo) if (Fdo)