Staging: heci: fix wrong order of device_lock and file_lock
authorDongxiao Xu <dongxiao.xu@intel.com>
Sun, 31 May 2009 06:43:39 +0000 (14:43 +0800)
committerGreg Kroah-Hartman <gregkh@suse.de>
Fri, 19 Jun 2009 18:00:55 +0000 (11:00 -0700)
When the two locks are nested, the code should always first acquire file_lock,
and then acquire device_lock in order not to generate dead-lock race.

Signed-off-by: Dongxiao Xu <dongxiao.xu@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/staging/heci/io_heci.c

index 619eeed87ea20ccf12ed0c1aaba9901e9d513bf6..53dc770727d858d6235c04e70efd0ee609954448 100644 (file)
@@ -277,14 +277,16 @@ int heci_ioctl_connect_client(struct iamt_heci_device *dev, int if_num,
                }
                goto end;
        }
+       spin_unlock_bh(&dev->device_lock);
+
        spin_lock(&file_ext->file_lock);
+       spin_lock_bh(&dev->device_lock);
        if (file_ext->state != HECI_FILE_CONNECTING) {
                rets = -ENODEV;
-               spin_unlock(&file_ext->file_lock);
                spin_unlock_bh(&dev->device_lock);
+               spin_unlock(&file_ext->file_lock);
                goto end;
        }
-       spin_unlock(&file_ext->file_lock);
        /* prepare the output buffer */
        client = (struct heci_client *) res_msg.data;
        client->max_msg_length = dev->me_clients[i].props.max_msg_length;
@@ -312,6 +314,7 @@ int heci_ioctl_connect_client(struct iamt_heci_device *dev, int if_num,
                              &dev->ctrl_wr_list.heci_cb.cb_list);
        }
        spin_unlock_bh(&dev->device_lock);
+       spin_unlock(&file_ext->file_lock);
        err = wait_event_timeout(dev->wait_recvd_msg,
                        (HECI_FILE_CONNECTED == file_ext->state
                         || HECI_FILE_DISCONNECTED == file_ext->state),