Merge master.kernel.org:/pub/scm/linux/kernel/git/davej/agpgart
[linux-drm-fsl-dcu.git] / drivers / acpi / events / evxface.c
index 4f948df17ab975f15cc6a5d22c842a10332d55e1..685a103a35873ee920e3d8e1c7783bed2b3ce1fd 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -428,7 +428,7 @@ acpi_remove_notify_handler(acpi_handle device,
        node = acpi_ns_map_handle_to_node(device);
        if (!node) {
                status = AE_BAD_PARAMETER;
-               goto unlock;
+               goto unlock_and_exit;
        }
 
        /* Root Object */
@@ -442,7 +442,7 @@ acpi_remove_notify_handler(acpi_handle device,
                    ((handler_type & ACPI_DEVICE_NOTIFY) &&
                     !acpi_gbl_device_notify.handler)) {
                        status = AE_NOT_EXIST;
-                       goto unlock;
+                       goto unlock_and_exit;
                }
 
                /* Make sure all deferred tasks are completed */
@@ -474,7 +474,7 @@ acpi_remove_notify_handler(acpi_handle device,
 
                if (!acpi_ev_is_notify_object(node)) {
                        status = AE_TYPE;
-                       goto unlock;
+                       goto unlock_and_exit;
                }
 
                /* Check for an existing internal object */
@@ -482,17 +482,21 @@ acpi_remove_notify_handler(acpi_handle device,
                obj_desc = acpi_ns_get_attached_object(node);
                if (!obj_desc) {
                        status = AE_NOT_EXIST;
-                       goto unlock;
+                       goto unlock_and_exit;
                }
 
                /* Object exists - make sure there's an existing handler */
 
                if (handler_type & ACPI_SYSTEM_NOTIFY) {
                        notify_obj = obj_desc->common_notify.system_notify;
-                       if ((!notify_obj) ||
-                           (notify_obj->notify.handler != handler)) {
+                       if (!notify_obj) {
+                               status = AE_NOT_EXIST;
+                               goto unlock_and_exit;
+                       }
+
+                       if (notify_obj->notify.handler != handler) {
                                status = AE_BAD_PARAMETER;
-                               goto unlock;
+                               goto unlock_and_exit;
                        }
                        /* Make sure all deferred tasks are completed */
 
@@ -510,10 +514,14 @@ acpi_remove_notify_handler(acpi_handle device,
 
                if (handler_type & ACPI_DEVICE_NOTIFY) {
                        notify_obj = obj_desc->common_notify.device_notify;
-                       if ((!notify_obj) ||
-                           (notify_obj->notify.handler != handler)) {
+                       if (!notify_obj) {
+                               status = AE_NOT_EXIST;
+                               goto unlock_and_exit;
+                       }
+
+                       if (notify_obj->notify.handler != handler) {
                                status = AE_BAD_PARAMETER;
-                               goto unlock;
+                               goto unlock_and_exit;
                        }
                        /* Make sure all deferred tasks are completed */
 
@@ -530,9 +538,9 @@ acpi_remove_notify_handler(acpi_handle device,
                }
        }
 
-unlock:
+      unlock_and_exit:
        (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
-exit:
+      exit:
        if (ACPI_FAILURE(status))
                ACPI_EXCEPTION((AE_INFO, status, "Removing notify handler"));
        return_ACPI_STATUS(status);
@@ -586,7 +594,7 @@ acpi_install_gpe_handler(acpi_handle gpe_device,
        gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
        if (!gpe_event_info) {
                status = AE_BAD_PARAMETER;
-               goto unlock;
+               goto unlock_and_exit;
        }
 
        /* Make sure that there isn't a handler there already */
@@ -594,7 +602,7 @@ acpi_install_gpe_handler(acpi_handle gpe_device,
        if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
            ACPI_GPE_DISPATCH_HANDLER) {
                status = AE_ALREADY_EXISTS;
-               goto unlock;
+               goto unlock_and_exit;
        }
 
        /* Allocate and init handler object */
@@ -602,7 +610,7 @@ acpi_install_gpe_handler(acpi_handle gpe_device,
        handler = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_handler_info));
        if (!handler) {
                status = AE_NO_MEMORY;
-               goto unlock;
+               goto unlock_and_exit;
        }
 
        handler->address = address;
@@ -613,7 +621,7 @@ acpi_install_gpe_handler(acpi_handle gpe_device,
 
        status = acpi_ev_disable_gpe(gpe_event_info);
        if (ACPI_FAILURE(status)) {
-               goto unlock;
+               goto unlock_and_exit;
        }
 
        /* Install the handler */
@@ -628,9 +636,9 @@ acpi_install_gpe_handler(acpi_handle gpe_device,
 
        acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
 
-unlock:
+      unlock_and_exit:
        (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
-exit:
+      exit:
        if (ACPI_FAILURE(status))
                ACPI_EXCEPTION((AE_INFO, status,
                                "Installing notify handler failed"));
@@ -760,11 +768,9 @@ acpi_status acpi_acquire_global_lock(u16 timeout, u32 * handle)
                return (AE_BAD_PARAMETER);
        }
 
-       status = acpi_ex_enter_interpreter();
-       if (ACPI_FAILURE(status)) {
-               return (status);
-       }
+       /* Must lock interpreter to prevent race conditions */
 
+       acpi_ex_enter_interpreter();
        status = acpi_ev_acquire_global_lock(timeout);
        acpi_ex_exit_interpreter();