Add ASSERTs
Correct a bug when processing IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / TargetDeviceRelation (serenum)
Don't breakpoint if NDEBUG is defined (serenum)
Allow to write more than 16 bytes in one IRP_MJ_WRITE (serial)
Modified: trunk/reactos/drivers/bus/serenum/detect.c
Modified: trunk/reactos/drivers/bus/serenum/misc.c
Modified: trunk/reactos/drivers/bus/serenum/pdo.c
Modified: trunk/reactos/drivers/bus/serenum/serenum.c
Modified: trunk/reactos/drivers/dd/serial/circularbuffer.c
Modified: trunk/reactos/drivers/dd/serial/create.c
Modified: trunk/reactos/drivers/dd/serial/devctrl.c
Modified: trunk/reactos/drivers/dd/serial/info.c
Modified: trunk/reactos/drivers/dd/serial/misc.c
Modified: trunk/reactos/drivers/dd/serial/pnp.c
Modified: trunk/reactos/drivers/dd/serial/rw.c

Modified: trunk/reactos/drivers/bus/serenum/detect.c
--- trunk/reactos/drivers/bus/serenum/detect.c	2005-04-15 10:52:29 UTC (rev 14626)
+++ trunk/reactos/drivers/bus/serenum/detect.c	2005-04-15 15:56:19 UTC (rev 14627)
@@ -199,7 +199,7 @@
 	KTIMER Timer;
 	LARGE_INTEGER DueTime;
 	
-	DueTime.QuadPart = -milliseconds * 10;
+	DueTime.QuadPart = milliseconds * -10;
 	KeInitializeTimer(&Timer);
 	KeSetTimer(&Timer, DueTime, NULL);
 	return KeWaitForSingleObject(&Timer, Executive, KernelMode, FALSE, NULL);

Modified: trunk/reactos/drivers/bus/serenum/misc.c
--- trunk/reactos/drivers/bus/serenum/misc.c	2005-04-15 10:52:29 UTC (rev 14626)
+++ trunk/reactos/drivers/bus/serenum/misc.c	2005-04-15 15:56:19 UTC (rev 14627)
@@ -14,10 +14,12 @@
 
 NTSTATUS
 SerenumDuplicateUnicodeString(
-  OUT PUNICODE_STRING Destination,
-  IN PUNICODE_STRING Source,
-  IN POOL_TYPE PoolType)
+	OUT PUNICODE_STRING Destination,
+	IN PUNICODE_STRING Source,
+	IN POOL_TYPE PoolType)
 {
+	ASSERT(Destination);
+	
 	if (Source == NULL)
 	{
 		RtlInitUnicodeString(Destination, NULL);
@@ -52,6 +54,8 @@
 	ULONG DestinationSize = 0;
 	NTSTATUS Status = STATUS_SUCCESS;
 	
+	ASSERT(Destination);
+	
 	/* Calculate length needed for destination unicode string */
 	va_start(args, Destination);
 	Source = va_arg(args, PCSZ);
@@ -133,6 +137,8 @@
 	ASSERT(((PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsFDO);
 	LowerDevice = ((PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice;
 	
+	ASSERT(LowerDevice);
+	
 	KeInitializeEvent(&Event, NotificationEvent, FALSE);
 	IoCopyCurrentIrpStackLocationToNext(Irp);
 	
@@ -162,6 +168,7 @@
 	ASSERT(DeviceExtension->Common.IsFDO);
 	
 	LowerDevice = DeviceExtension->LowerDevice;
+	ASSERT(LowerDevice);
 	DPRINT("Serenum: calling lower device 0x%p [%wZ]\n",
 		LowerDevice, &LowerDevice->DriverObject->DriverName);
 	IoSkipCurrentIrpStackLocation(Irp);
@@ -180,6 +187,7 @@
 	ASSERT(!DeviceExtension->Common.IsFDO);
 	
 	Fdo = DeviceExtension->AttachedFdo;
+	ASSERT(Fdo);
 	DPRINT("Serenum: calling attached Fdo 0x%p [%wZ]\n",
 		Fdo, &Fdo->DriverObject->DriverName);
 	IoSkipCurrentIrpStackLocation(Irp);
@@ -195,6 +203,7 @@
 	
 	ASSERT(((PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsFDO);
 	LowerDevice = ((PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice;
+	ASSERT(LowerDevice);
 	
 	IoSkipCurrentIrpStackLocation(Irp);
 	return IoCallDriver(LowerDevice, Irp);

Modified: trunk/reactos/drivers/bus/serenum/pdo.c
--- trunk/reactos/drivers/bus/serenum/pdo.c	2005-04-15 10:52:29 UTC (rev 14626)
+++ trunk/reactos/drivers/bus/serenum/pdo.c	2005-04-15 15:56:19 UTC (rev 14627)
@@ -99,6 +99,7 @@
 		return STATUS_INSUFFICIENT_RESOURCES;
 	
 	ObReferenceObject(DeviceObject);
+	DeviceRelations->Count = 1;
 	DeviceRelations->Objects[0] = DeviceObject;
 	
 	*pDeviceRelations = DeviceRelations;

Modified: trunk/reactos/drivers/bus/serenum/serenum.c
--- trunk/reactos/drivers/bus/serenum/serenum.c	2005-04-15 10:52:29 UTC (rev 14626)
+++ trunk/reactos/drivers/bus/serenum/serenum.c	2005-04-15 15:56:19 UTC (rev 14627)
@@ -52,7 +52,9 @@
 			{
 				DPRINT1("Serenum: FDO stub for major function 0x%lx\n",
 					IoGetCurrentIrpStackLocation(Irp)->MajorFunction);
+#ifndef NDEBUG
 				DbgBreakPoint();
+#endif
 				Status = Irp->IoStatus.Status;
 			}
 		}
@@ -73,7 +75,9 @@
 			{
 				DPRINT1("Serenum: PDO stub for major function 0x%lx\n",
 					IoGetCurrentIrpStackLocation(Irp)->MajorFunction);
+#ifndef NDEBUG
 				DbgBreakPoint();
+#endif
 				Status = Irp->IoStatus.Status;
 			}
 		}
@@ -100,12 +104,6 @@
 	for (i = 0; i < IRP_MJ_MAXIMUM_FUNCTION; i++)
 		DriverObject->MajorFunction[i] = IrpStub;
 	
-	/*DriverObject->MajorFunction[IRP_MJ_CREATE] = SerialCreate;
-	DriverObject->MajorFunction[IRP_MJ_CLOSE] = SerialClose;
-	DriverObject->MajorFunction[IRP_MJ_CLEANUP] = SerialCleanup;
-	DriverObject->MajorFunction[IRP_MJ_READ] = SerialRead;
-	DriverObject->MajorFunction[IRP_MJ_WRITE] = SerialWrite;*/
-	//DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = Serenum;
 	//DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = SerialQueryInformation;
 	DriverObject->MajorFunction[IRP_MJ_PNP] = SerenumPnp;
 	//DriverObject->MajorFunction[IRP_MJ_POWER] = SerialPower;

Modified: trunk/reactos/drivers/dd/serial/circularbuffer.c
--- trunk/reactos/drivers/dd/serial/circularbuffer.c	2005-04-15 10:52:29 UTC (rev 14626)
+++ trunk/reactos/drivers/dd/serial/circularbuffer.c	2005-04-15 15:56:19 UTC (rev 14627)
@@ -17,6 +17,7 @@
 	IN ULONG BufferSize)
 {
 	DPRINT("Serial: InitializeCircularBuffer(pBuffer %p, BufferSize %lu)\n", pBuffer, BufferSize);
+	ASSERT(pBuffer);
 	pBuffer->Buffer = (PUCHAR)ExAllocatePoolWithTag(NonPagedPool, BufferSize * sizeof(UCHAR), SERIAL_TAG);
 	if (!pBuffer->Buffer)
 		return STATUS_INSUFFICIENT_RESOURCES;
@@ -30,6 +31,7 @@
 	IN PCIRCULAR_BUFFER pBuffer)
 {
 	DPRINT("Serial: FreeCircularBuffer(pBuffer %p)\n", pBuffer);
+	ASSERT(pBuffer);
 	ExFreePoolWithTag(pBuffer->Buffer, SERIAL_TAG);
 	return STATUS_SUCCESS;
 }
@@ -39,6 +41,7 @@
 	IN PCIRCULAR_BUFFER pBuffer)
 {
 	DPRINT("Serial: IsCircularBufferEmpty(pBuffer %p)\n", pBuffer);
+	ASSERT(pBuffer);
 	return (pBuffer->ReadPosition == pBuffer->WritePosition);
 }
 
@@ -49,6 +52,7 @@
 {
 	ULONG NextPosition;
 	DPRINT("Serial: PushCircularBufferEntry(pBuffer %p, Entry 0x%x)\n", pBuffer, Entry);
+	ASSERT(pBuffer);
 	ASSERT(pBuffer->Length);
 	NextPosition = (pBuffer->WritePosition + 1) % pBuffer->Length;
 	if (NextPosition == pBuffer->ReadPosition)
@@ -64,6 +68,7 @@
 	OUT PUCHAR Entry)
 {
 	DPRINT("Serial: PopCircularBufferEntry(pBuffer %p)\n", pBuffer);
+	ASSERT(pBuffer);
 	ASSERT(pBuffer->Length);
 	if (IsCircularBufferEmpty(pBuffer))
 		return STATUS_ARRAY_BOUNDS_EXCEEDED;
@@ -80,6 +85,7 @@
 	PUCHAR NewBuffer;
 	
 	DPRINT("Serial: IncreaseCircularBufferSize(pBuffer %p, NewBufferSize %lu)\n", pBuffer, NewBufferSize);
+	ASSERT(pBuffer);
 	ASSERT(pBuffer->Length);
 	if (pBuffer->Length > NewBufferSize)
 		return STATUS_INVALID_PARAMETER;

Modified: trunk/reactos/drivers/dd/serial/create.c
--- trunk/reactos/drivers/dd/serial/create.c	2005-04-15 10:52:29 UTC (rev 14626)
+++ trunk/reactos/drivers/dd/serial/create.c	2005-04-15 15:56:19 UTC (rev 14627)
@@ -26,6 +26,8 @@
 	FileObject = Stack->FileObject;
 	DeviceExtension = (PSERIAL_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
 	
+	ASSERT(FileObject);
+	
 	if (Stack->Parameters.Create.Options & FILE_DIRECTORY_FILE)
 	{
 		CHECKPOINT;

Modified: trunk/reactos/drivers/dd/serial/devctrl.c
--- trunk/reactos/drivers/dd/serial/devctrl.c	2005-04-15 10:52:29 UTC (rev 14626)
+++ trunk/reactos/drivers/dd/serial/devctrl.c	2005-04-15 15:56:19 UTC (rev 14627)
@@ -20,10 +20,10 @@
 	OUT PVOID* BufferIn,
 	OUT PVOID* BufferOut)
 {
-   ASSERT(Irp);
-   ASSERT(BufferIn);
-   ASSERT(BufferOut);
-   
+	ASSERT(Irp);
+	ASSERT(BufferIn);
+	ASSERT(BufferOut);
+	
 	switch (IO_METHOD_FROM_CTL_CODE(IoControlCode))
 	{
 		case METHOD_BUFFERED:
@@ -118,6 +118,9 @@
 	UCHAR Lcr = 0;
 	NTSTATUS Status;
 	
+	ASSERT(DeviceExtension);
+	ASSERT(NewSettings);
+	
 	DPRINT("Serial: SerialSetLineControl(COM%lu, Settings { %lu %lu %lu })\n",
 		DeviceExtension->ComPort, NewSettings->StopBits, NewSettings->Parity, NewSettings->WordLength);
 	
@@ -184,6 +187,8 @@
 SerialClearPerfStats(
 	IN PSERIAL_DEVICE_EXTENSION DeviceExtension)
 {
+	ASSERT(DeviceExtension);
+	
 	RtlZeroMemory(&DeviceExtension->SerialPerfStats, sizeof(SERIALPERF_STATS));
 	DeviceExtension->BreakInterruptErrorCount = 0;
 	return TRUE;
@@ -195,6 +200,7 @@
 	PSERIAL_DEVICE_EXTENSION pDeviceExtension;
 	pDeviceExtension = (PSERIAL_DEVICE_EXTENSION)
 		IoGetCurrentIrpStackLocation(pIrp)->DeviceObject->DeviceExtension;
+	ASSERT(DeviceExtension);
 	/*
 	 * we assume buffer is big enough to hold SerialPerfStats structure
 	 * caller must verify this
@@ -212,6 +218,8 @@
 	OUT PSERIAL_COMMPROP pCommProp,
 	IN PSERIAL_DEVICE_EXTENSION DeviceExtension)
 {
+	ASSERT(pCommProp);
+	
 	RtlZeroMemory(pCommProp, sizeof(SERIAL_COMMPROP));
 	
 	pCommProp->PacketLength = sizeof(SERIAL_COMMPROP);
@@ -257,6 +265,7 @@
 {
 	KIRQL Irql;
 	
+	ASSERT(pSerialStatus);
 	RtlZeroMemory(pSerialStatus, sizeof(SERIAL_STATUS));
 	
 	pSerialStatus->Errors = 0;

Modified: trunk/reactos/drivers/dd/serial/info.c
--- trunk/reactos/drivers/dd/serial/info.c	2005-04-15 10:52:29 UTC (rev 14626)
+++ trunk/reactos/drivers/dd/serial/info.c	2005-04-15 15:56:19 UTC (rev 14627)
@@ -37,12 +37,13 @@
 			DPRINT("Serial: IRP_MJ_QUERY_INFORMATION / FileStandardInformation\n");
 			if (BufferLength < sizeof(FILE_STANDARD_INFORMATION))
 				Status = STATUS_BUFFER_OVERFLOW;
-			else
+			else if (!StandardInfo)
+				Status = STATUS_INVALID_PARAMETER;
 			{
 				StandardInfo->AllocationSize.QuadPart = 0;
 				StandardInfo->EndOfFile.QuadPart = 0;
-      		StandardInfo->Directory = FALSE;
-      		StandardInfo->NumberOfLinks = 0;
+				StandardInfo->Directory = FALSE;
+				StandardInfo->NumberOfLinks = 0;
   				StandardInfo->DeletePending = FALSE; /* FIXME: should be TRUE sometimes */
   				Status = STATUS_SUCCESS;
 			}
@@ -52,9 +53,13 @@
 		{
 			PFILE_POSITION_INFORMATION PositionInfo = (PFILE_POSITION_INFORMATION)SystemBuffer;
 			
+			ASSERT(PositionInfo);
+			
 			DPRINT("Serial: IRP_MJ_QUERY_INFORMATION / FilePositionInformation\n");
 			if (BufferLength < sizeof(PFILE_POSITION_INFORMATION))
 				Status = STATUS_BUFFER_OVERFLOW;
+			else if (!PositionInfo)
+				Status = STATUS_INVALID_PARAMETER;
 			else
 			{
 				PositionInfo->CurrentByteOffset.QuadPart = 0;

Modified: trunk/reactos/drivers/dd/serial/misc.c
--- trunk/reactos/drivers/dd/serial/misc.c	2005-04-15 10:52:29 UTC (rev 14626)
+++ trunk/reactos/drivers/dd/serial/misc.c	2005-04-15 15:56:19 UTC (rev 14627)
@@ -32,6 +32,8 @@
 	KEVENT Event;
 	NTSTATUS Status;
 	
+	ASSERT(LowerDevice);
+	
 	KeInitializeEvent(&Event, NotificationEvent, FALSE);
 	IoCopyCurrentIrpStackLocationToNext(Irp);
 	
@@ -56,6 +58,8 @@
 {
 	PDEVICE_OBJECT LowerDevice = ((PSERIAL_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice;
 	
+	ASSERT(LowerDevice);
+	
 	IoSkipCurrentIrpStackLocation(Irp);
 	return IoCallDriver(LowerDevice, Irp);
 }

Modified: trunk/reactos/drivers/dd/serial/pnp.c
--- trunk/reactos/drivers/dd/serial/pnp.c	2005-04-15 10:52:29 UTC (rev 14626)
+++ trunk/reactos/drivers/dd/serial/pnp.c	2005-04-15 15:56:19 UTC (rev 14627)
@@ -31,6 +31,9 @@
 	static ULONG ComPortNumber = 1;
 
 	DPRINT("Serial: SerialAddDeviceInternal called\n");
+	
+	ASSERT(DeviceObject);
+	ASSERT(Pdo);
    
 	/* Create new device object */
 	swprintf(DeviceNameBuffer, L"\\Device\\Serial%lu", DeviceNumber);
@@ -125,12 +128,10 @@
 	if (Pdo == NULL)
 		return STATUS_SUCCESS;
 	
-	/* We have here a PDO that does not correspond to a legacy
-	 * serial port. So call the internal AddDevice function.
+	/* We have here a PDO not null. It represents a real serial
+	 * port. So call the internal AddDevice function.
 	 */
 	return SerialAddDeviceInternal(DriverObject, Pdo, UartUnknown, NULL, NULL);
-
-
 }
 
 NTSTATUS STDCALL
@@ -160,6 +161,8 @@
 	
 	DeviceExtension = (PSERIAL_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
 	
+	ASSERT(ResourceList);
+	ASSERT(DeviceExtension);
 	ASSERT(DeviceExtension->PnpState == dsStopped);
 	
 	DeviceExtension->BaudRate = 19200 | SERIAL_BAUD_USER;

Modified: trunk/reactos/drivers/dd/serial/rw.c
--- trunk/reactos/drivers/dd/serial/rw.c	2005-04-15 10:52:29 UTC (rev 14626)
+++ trunk/reactos/drivers/dd/serial/rw.c	2005-04-15 15:56:19 UTC (rev 14627)
@@ -37,6 +37,9 @@
 	ULONG_PTR Information = 0;
 	NTSTATUS Status;
 	
+	ASSERT(DeviceObject);
+	ASSERT(WorkItemData);
+	
 	DeviceExtension = (PSERIAL_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
 	ComPortBase = (PUCHAR)DeviceExtension->BaseAddress;
 	Length = IoGetCurrentIrpStackLocation(Irp)->Parameters.Read.Length;
@@ -285,9 +288,19 @@
 		Status = PushCircularBufferEntry(&DeviceExtension->OutputBuffer, Buffer[Information]);
 		if (!NT_SUCCESS(Status))
 		{
-			DPRINT("Serial: buffer overrun on COM%lu\n", DeviceExtension->ComPort);
-			DeviceExtension->SerialPerfStats.BufferOverrunErrorCount++;
-			break;
+			if (Status == STATUS_BUFFER_TOO_SMALL)
+			{
+				KeReleaseSpinLock(&DeviceExtension->OutputBufferLock, Irql);
+				SerialSendByte(NULL, DeviceExtension, NULL, NULL);
+				KeAcquireSpinLock(&DeviceExtension->OutputBufferLock, &Irql);
+				continue;
+			}
+			else
+			{
+				DPRINT("Serial: buffer overrun on COM%lu\n", DeviceExtension->ComPort);
+				DeviceExtension->SerialPerfStats.BufferOverrunErrorCount++;
+				break;
+			}
 		}
 		Information++;
 	}