[ros-dev] [ros-diffs] [janderwald] 73016: [USBAUDIO] - implement retrieving string descriptor of product and store it in registry.

Thomas Faber thomas.faber at reactos.org
Fri Oct 21 21:40:48 UTC 2016


On 2016-10-21 23:15, janderwald at svn.reactos.org wrote:
 >  NTSTATUS
 > +NTAPI
 > +USBAudioGetDescriptor(
 > +    IN PDEVICE_OBJECT DeviceObject,
 > +    IN UCHAR DescriptorType,
 > +    IN ULONG DescriptorLength,
 > +    IN UCHAR DescriptorIndex,
 > +    IN LANGID LanguageId,
 > +    OUT PVOID *OutDescriptor)
 > +{
 > +    PURB Urb;
 > +    NTSTATUS Status;
 > +    PVOID Descriptor;
 > +
 > +    /* sanity checks */
 > +    ASSERT(DeviceObject);
 > +    ASSERT(OutDescriptor);
 > +    ASSERT(DescriptorLength);
 > +
 > +    //
 > +    // first allocate descriptor buffer
 > +    //
 > +    Descriptor = AllocFunction(DescriptorLength);
 > +    if (!Descriptor)
 > +    {
 > +        /* no memory */
 > +        return STATUS_INSUFFICIENT_RESOURCES;
 > +    }
 > +
 > +    /* allocate urb */
 > +    Urb = (PURB)AllocFunction(sizeof(URB));
 > +    if (!Urb)
 > +    {
 > +        /* no memory */
 > +        FreeFunction(Descriptor);
 > +        return STATUS_INSUFFICIENT_RESOURCES;
 > +    }
 > +
 > +    /* initialize urb */
 > +    UsbBuildGetDescriptorRequest(Urb,
 > +        sizeof(Urb->UrbControlDescriptorRequest),
 > +        DescriptorType,
 > +        DescriptorIndex,
 > +        LanguageId,
 > +        Descriptor,
 > +        NULL,
 > +        DescriptorLength,
 > +        NULL);
 > +
 > +    /* submit urb */
 > +    Status = SubmitUrbSync(DeviceObject, Urb);
 > +
 > +    /* free urb */
 > +    FreeFunction(Urb);
 > +
 > +    if (NT_SUCCESS(Status))
 > +    {
 > +        /* store result */
 > +        *OutDescriptor = Descriptor;
 > +    }

Is Descriptor leaked in the failure case, or does something down the
stack take care of that?

 > +
 > +    /* done */
 > +    return Status;
 > +}



> +NTSTATUS
> +USBAudioRegCreateMediaCategoriesKey(
> +    IN PUNICODE_STRING Name,
> +    OUT PHANDLE OutHandle)
> +{
> +    NTSTATUS Status;
> +    OBJECT_ATTRIBUTES ObjectAttributes;
> +    UNICODE_STRING DestinationString;
> +    HANDLE Handle;
> +
> +    /* initialize root name*/
> +    RtlInitUnicodeString(&DestinationString, L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\MediaCategories\\");
> +
> +    /* initialize object attributes */
> +    InitializeObjectAttributes(&ObjectAttributes, &DestinationString, OBJ_CASE_INSENSITIVE | OBJ_OPENIF, NULL, NULL);

You're missing OBJ_KERNEL_HANDLE.

> +
> +    /* create the key */
> +    Status = ZwOpenKey(&Handle, KEY_ALL_ACCESS, &ObjectAttributes);
> +    if (NT_SUCCESS(Status))
> +    {
> +        /* initialize object attributes */
> +        InitializeObjectAttributes(&ObjectAttributes, Name, OBJ_CASE_INSENSITIVE, Handle, NULL);

Here too.

> +
> +        Status = ZwCreateKey(OutHandle, KEY_ALL_ACCESS, &ObjectAttributes, 0, NULL, 0, NULL);
> +        ZwClose(Handle);
> +
> +    }
> +    return Status;
> +}


Thanks.
-Thomas



More information about the Ros-dev mailing list