From 3dc763c88b19d8272b5d8eaba0f14feace74eff3 Mon Sep 17 00:00:00 2001 From: mycroft Date: Thu, 30 Oct 2003 17:46:08 +0000 Subject: [PATCH] Patches from Christos to fix double-frees and error handling. --- sys/dev/acpi/acpica/Subsystem/evxfregn.c | 3 +- sys/dev/acpi/acpica/Subsystem/nsalloc.c | 192 +++++++++++++---------- sys/dev/acpi/acpica/Subsystem/nseval.c | 6 +- sys/dev/acpi/acpica/Subsystem/nsutils.c | 5 +- 4 files changed, 112 insertions(+), 94 deletions(-) diff --git a/sys/dev/acpi/acpica/Subsystem/evxfregn.c b/sys/dev/acpi/acpica/Subsystem/evxfregn.c index 2cdca5aefe42..84456fd3dec0 100644 --- a/sys/dev/acpi/acpica/Subsystem/evxfregn.c +++ b/sys/dev/acpi/acpica/Subsystem/evxfregn.c @@ -116,7 +116,7 @@ *****************************************************************************/ #include -__KERNEL_RCSID(0, "$NetBSD: evxfregn.c,v 1.6 2003/03/04 17:25:16 kochi Exp $"); +__KERNEL_RCSID(0, "$NetBSD: evxfregn.c,v 1.7 2003/10/30 17:46:08 mycroft Exp $"); #define __EVXFREGN_C__ @@ -492,7 +492,6 @@ AcpiRemoveAddressSpaceHandler ( * Now we can delete the handler object */ AcpiUtRemoveReference (HandlerObj); - AcpiUtRemoveReference (HandlerObj); goto UnlockAndExit; } diff --git a/sys/dev/acpi/acpica/Subsystem/nsalloc.c b/sys/dev/acpi/acpica/Subsystem/nsalloc.c index 604837e9b42d..67e8e20f917b 100644 --- a/sys/dev/acpi/acpica/Subsystem/nsalloc.c +++ b/sys/dev/acpi/acpica/Subsystem/nsalloc.c @@ -115,7 +115,7 @@ *****************************************************************************/ #include -__KERNEL_RCSID(0, "$NetBSD: nsalloc.c,v 1.8 2003/05/13 13:29:00 kochi Exp $"); +__KERNEL_RCSID(0, "$NetBSD: nsalloc.c,v 1.9 2003/10/30 17:46:08 mycroft Exp $"); #define __NSALLOC_C__ @@ -542,92 +542,6 @@ AcpiNsDeleteChildren ( } -/******************************************************************************* - * - * FUNCTION: AcpiNsDeleteNamespaceSubtree - * - * PARAMETERS: ParentNode - Root of the subtree to be deleted - * - * RETURN: None. - * - * DESCRIPTION: Delete a subtree of the namespace. This includes all objects - * stored within the subtree. - * - ******************************************************************************/ - -void -AcpiNsDeleteNamespaceSubtree ( - ACPI_NAMESPACE_NODE *ParentNode) -{ - ACPI_NAMESPACE_NODE *ChildNode = NULL; - UINT32 Level = 1; - - - ACPI_FUNCTION_TRACE ("NsDeleteNamespaceSubtree"); - - - if (!ParentNode) - { - return_VOID; - } - - /* - * Traverse the tree of objects until we bubble back up - * to where we started. - */ - while (Level > 0) - { - /* Get the next node in this scope (NULL if none) */ - - ChildNode = AcpiNsGetNextNode (ACPI_TYPE_ANY, ParentNode, - ChildNode); - if (ChildNode) - { - /* Found a child node - detach any attached object */ - - AcpiNsDetachObject (ChildNode); - - /* Check if this node has any children */ - - if (AcpiNsGetNextNode (ACPI_TYPE_ANY, ChildNode, 0)) - { - /* - * There is at least one child of this node, - * visit the node - */ - Level++; - ParentNode = ChildNode; - ChildNode = 0; - } - } - else - { - /* - * No more children of this parent node. - * Move up to the grandparent. - */ - Level--; - - /* - * Now delete all of the children of this parent - * all at the same time. - */ - AcpiNsDeleteChildren (ParentNode); - - /* New "last child" is this parent node */ - - ChildNode = ParentNode; - - /* Move up the tree to the grandparent */ - - ParentNode = AcpiNsGetParentNode (ParentNode); - } - } - - return_VOID; -} - - /******************************************************************************* * * FUNCTION: AcpiNsRemoveReference @@ -684,6 +598,110 @@ AcpiNsRemoveReference ( } +/******************************************************************************* + * + * FUNCTION: AcpiNsDeleteNamespaceSubtree + * + * PARAMETERS: ParentNode - Root of the subtree to be deleted + * + * RETURN: None. + * + * DESCRIPTION: Delete a subtree of the namespace. This includes all objects + * stored within the subtree. + * + ******************************************************************************/ + +void +AcpiNsDeleteNamespaceSubtree ( + ACPI_NAMESPACE_NODE *ParentNode) +{ + ACPI_NAMESPACE_NODE *ChildNode; + ACPI_NAMESPACE_NODE *DeletionNode; + UINT32 Level; + + + ACPI_FUNCTION_TRACE ("NsDeleteNamespaceSubtree"); + + + if (!ParentNode) + { + return_VOID; + } + + ChildNode = NULL; + DeletionNode = NULL; + Level = 1; + + /* + * Traverse the tree of objects until we bubble back up + * to where we started. + */ + while (Level > 0) + { + /* Get the next node in this scope (NULL if none) */ + + ChildNode = AcpiNsGetNextNode (ACPI_TYPE_ANY, ParentNode, + ChildNode); + if (DeletionNode) + { + AcpiNsRemoveReference (DeletionNode); + DeletionNode = NULL; + } + + if (ChildNode) + { + /* Found a child node - detach any attached object */ + + AcpiNsDetachObject (ChildNode); + + /* Check if this node has any children */ + + if (AcpiNsGetNextNode (ACPI_TYPE_ANY, ChildNode, 0)) + { + /* + * There is at least one child of this node, + * visit the node + */ + Level++; + ParentNode = ChildNode; + ChildNode = 0; + } + else + { + DeletionNode = ChildNode; + } + } + else + { + /* + * No more children of this parent node. + * Move up to the grandparent. + */ + Level--; + + /* + * Now delete all of the children of this parent + * all at the same time. + */ + if (Level != 0) + { + DeletionNode = ParentNode; + } + + /* New "last child" is this parent node */ + + ChildNode = ParentNode; + + /* Move up the tree to the grandparent */ + + ParentNode = AcpiNsGetParentNode (ParentNode); + } + } + + return_VOID; +} + + /******************************************************************************* * * FUNCTION: AcpiNsDeleteNamespaceByOwner diff --git a/sys/dev/acpi/acpica/Subsystem/nseval.c b/sys/dev/acpi/acpica/Subsystem/nseval.c index c692e2839d5e..27a4055e9beb 100644 --- a/sys/dev/acpi/acpica/Subsystem/nseval.c +++ b/sys/dev/acpi/acpica/Subsystem/nseval.c @@ -117,7 +117,7 @@ *****************************************************************************/ #include -__KERNEL_RCSID(0, "$NetBSD: nseval.c,v 1.6 2003/03/04 17:25:22 kochi Exp $"); +__KERNEL_RCSID(0, "$NetBSD: nseval.c,v 1.7 2003/10/30 17:46:08 mycroft Exp $"); #define __NSEVAL_C__ @@ -191,7 +191,7 @@ AcpiNsEvaluateRelative ( Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); if (ACPI_FAILURE (Status)) { - return_ACPI_STATUS (Status); + goto Cleanup; } PrefixNode = AcpiNsMapHandleToNode (Handle); @@ -282,7 +282,7 @@ AcpiNsEvaluateByName ( Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); if (ACPI_FAILURE (Status)) { - return_ACPI_STATUS (Status); + goto Cleanup; } /* Lookup the name in the namespace */ diff --git a/sys/dev/acpi/acpica/Subsystem/nsutils.c b/sys/dev/acpi/acpica/Subsystem/nsutils.c index c7cac9193c04..c938d53ad02b 100644 --- a/sys/dev/acpi/acpica/Subsystem/nsutils.c +++ b/sys/dev/acpi/acpica/Subsystem/nsutils.c @@ -116,7 +116,7 @@ *****************************************************************************/ #include -__KERNEL_RCSID(0, "$NetBSD: nsutils.c,v 1.6 2003/03/04 17:25:23 kochi Exp $"); +__KERNEL_RCSID(0, "$NetBSD: nsutils.c,v 1.7 2003/10/30 17:46:08 mycroft Exp $"); #define __NSUTILS_C__ @@ -1043,7 +1043,7 @@ AcpiNsGetNodeByPath ( Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); if (ACPI_FAILURE (Status)) { - return_ACPI_STATUS (Status); + goto Cleanup; } /* Setup lookup scope (search starting point) */ @@ -1066,6 +1066,7 @@ AcpiNsGetNodeByPath ( (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); +Cleanup: if (InternalPath) { ACPI_MEM_FREE (InternalPath);