[VIDEOPRT] Honour NumAccessRanges == 0 / AccessRanges == NULL in VideoPortVerifyAccessRanges()

These are specified for releasing the hardware resources previously
acquired by either a previous call to VideoPortVerifyAccessRanges()
or a call to VideoPortGetAccessRanges().
This commit is contained in:
Hermès Bélusca-Maïto 2023-06-23 20:49:42 +02:00
parent de6313d89e
commit 3121aee56e
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
2 changed files with 46 additions and 5 deletions

View file

@ -190,6 +190,31 @@ IntVideoPortFilterResourceRequirements(
return STATUS_SUCCESS;
}
VOID
IntVideoPortReleaseResources(
_In_ PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension)
{
NTSTATUS Status;
BOOLEAN ConflictDetected;
// An empty CM_RESOURCE_LIST
UCHAR EmptyResourceList[FIELD_OFFSET(CM_RESOURCE_LIST, List)] = {0};
Status = IoReportResourceForDetection(
DeviceExtension->DriverObject,
NULL, 0, /* Driver List */
DeviceExtension->PhysicalDeviceObject,
(PCM_RESOURCE_LIST)EmptyResourceList,
sizeof(EmptyResourceList),
&ConflictDetected);
if (!NT_SUCCESS(Status))
{
DPRINT1("VideoPortReleaseResources IoReportResource failed with 0x%08lx ; ConflictDetected: %s\n",
Status, ConflictDetected ? "TRUE" : "FALSE");
}
/* Ignore the returned status however... */
}
NTSTATUS NTAPI
IntVideoPortMapPhysicalMemory(
IN HANDLE Process,
@ -844,20 +869,31 @@ VideoPortVerifyAccessRanges(
{
PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
BOOLEAN ConflictDetected;
ULONG i;
PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
PCM_RESOURCE_LIST ResourceList;
ULONG ResourceListSize;
PCM_RESOURCE_LIST ResourceList;
PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
ULONG i;
NTSTATUS Status;
TRACE_(VIDEOPRT, "VideoPortVerifyAccessRanges\n");
/* Verify parameters */
if (NumAccessRanges && !AccessRanges)
return ERROR_INVALID_PARAMETER;
DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
if (NumAccessRanges == 0)
{
/* Release the resources and do nothing more for now... */
IntVideoPortReleaseResources(DeviceExtension);
return NO_ERROR;
}
/* Create the resource list */
ResourceListSize = sizeof(CM_RESOURCE_LIST)
+ (NumAccessRanges - 1) * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
ResourceList = ExAllocatePool(PagedPool, ResourceListSize);
ResourceList = ExAllocatePoolWithTag(PagedPool, ResourceListSize, TAG_VIDEO_PORT);
if (!ResourceList)
{
WARN_(VIDEOPRT, "ExAllocatePool() failed\n");
@ -904,7 +940,8 @@ VideoPortVerifyAccessRanges(
DeviceExtension->PhysicalDeviceObject,
ResourceList, ResourceListSize,
&ConflictDetected);
ExFreePool(ResourceList);
ExFreePoolWithTag(ResourceList, TAG_VIDEO_PORT);
if (!NT_SUCCESS(Status) || ConflictDetected)
return ERROR_INVALID_PARAMETER;

View file

@ -237,6 +237,10 @@ IntVideoPortFilterResourceRequirements(
IN PIO_STACK_LOCATION IrpStack,
IN PIRP Irp);
VOID
IntVideoPortReleaseResources(
_In_ PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension);
NTSTATUS NTAPI
IntVideoPortMapPhysicalMemory(
IN HANDLE Process,