[NTOSKRNL_VISTA] Implement IoGetIrpExtraCreateParameter
[reactos.git] / sdk / lib / drivers / hidparser / parser.c
index c314a96..e0208f6 100644 (file)
@@ -713,30 +713,6 @@ HidParser_AddMainItem(
     return HIDPARSER_STATUS_SUCCESS;
 }
 
     return HIDPARSER_STATUS_SUCCESS;
 }
 
-HIDPARSER_STATUS
-AllocateParserContext(
-    IN PHID_PARSER Parser,
-    OUT PHID_PARSER_CONTEXT *OutParserContext)
-{
-    PHID_PARSER_CONTEXT ParserContext;
-
-    ParserContext = Parser->Alloc(sizeof(HID_PARSER_CONTEXT));
-    if (!ParserContext)
-    {
-        //
-        // failed
-        //
-        return HIDPARSER_STATUS_INSUFFICIENT_RESOURCES;
-    }
-
-    //
-    // store result
-    //
-    *OutParserContext = ParserContext;
-    return HIDPARSER_STATUS_SUCCESS;
-}
-
-
 HIDPARSER_STATUS
 HidParser_ParseReportDescriptor(
     IN PHID_PARSER Parser,
 HIDPARSER_STATUS
 HidParser_ParseReportDescriptor(
     IN PHID_PARSER Parser,
@@ -760,12 +736,18 @@ HidParser_ParseReportDescriptor(
     PMAIN_ITEM_DATA MainItemData;
     PHID_PARSER_CONTEXT ParserContext;
 
     PMAIN_ITEM_DATA MainItemData;
     PHID_PARSER_CONTEXT ParserContext;
 
+    CurrentOffset = ReportDescriptor;
+    ReportEnd = ReportDescriptor + ReportLength;
+
+    if (ReportDescriptor >= ReportEnd)
+        return HIDPARSER_STATUS_COLLECTION_NOT_FOUND;
+
     //
     // allocate parser
     //
     //
     // allocate parser
     //
-    Status = AllocateParserContext(Parser, &ParserContext);
-    if (Status != HIDPARSER_STATUS_SUCCESS)
-        return Status;
+    ParserContext = Parser->Alloc(sizeof(HID_PARSER_CONTEXT));;
+    if (!ParserContext)
+        return HIDPARSER_STATUS_INSUFFICIENT_RESOURCES;
 
 
     //
 
 
     //
@@ -778,6 +760,7 @@ HidParser_ParseReportDescriptor(
         //
         // no memory
         //
         //
         // no memory
         //
+        Parser->Free(ParserContext);
         return HIDPARSER_STATUS_INSUFFICIENT_RESOURCES;
     }
 
         return HIDPARSER_STATUS_INSUFFICIENT_RESOURCES;
     }
 
@@ -792,6 +775,7 @@ HidParser_ParseReportDescriptor(
         //
         Parser->Free(ParserContext->LocalItemState.UsageStack);
         ParserContext->LocalItemState.UsageStack = NULL;
         //
         Parser->Free(ParserContext->LocalItemState.UsageStack);
         ParserContext->LocalItemState.UsageStack = NULL;
+        Parser->Free(ParserContext);
         return HIDPARSER_STATUS_INSUFFICIENT_RESOURCES;
     }
 
         return HIDPARSER_STATUS_INSUFFICIENT_RESOURCES;
     }
 
@@ -799,8 +783,6 @@ HidParser_ParseReportDescriptor(
     // start parsing
     //
     CurrentCollection = ParserContext->RootCollection;
     // start parsing
     //
     CurrentCollection = ParserContext->RootCollection;
-    CurrentOffset = ReportDescriptor;
-    ReportEnd = ReportDescriptor + ReportLength;
 
     do
     {
 
     do
     {
@@ -1230,8 +1212,7 @@ HidParser_ParseReportDescriptor(
         //
         CurrentOffset += CurrentItemSize + sizeof(ITEM_PREFIX);
 
         //
         CurrentOffset += CurrentItemSize + sizeof(ITEM_PREFIX);
 
-
-    }while(CurrentOffset < ReportEnd);
+    }while (CurrentOffset < ReportEnd);
 
 
     //
 
 
     //