IPC: add bus lock protect for ipc_device_list
authorShijie Zhang <shijie.zhang@intel.com>
Tue, 22 May 2012 20:12:23 +0000 (04:12 +0800)
committerbuildbot <buildbot@intel.com>
Wed, 30 May 2012 16:09:18 +0000 (09:09 -0700)
BZ: 37748

In current IPC framework, ipc_device_list is not under protect by bus
lock, which may cause synchronization problem when they are accessed by
multi process at the same time. This patch puts it under protect of bus
lock to avoid this risk.

Change-Id: Ic48f2eb291ef900b1f1c498a3b6e7efb3fff8737
Signed-off-by: Shijie Zhang <shijie.zhang@intel.com>
Reviewed-on: http://android.intel.com:8080/49725
Reviewed-by: Yang, Bin <bin.yang@intel.com>
Reviewed-by: Chen, Jie D <jie.d.chen@intel.com>
Reviewed-by: Du, Alek <alek.du@intel.com>
Tested-by: Tang, HaifengX <haifengx.tang@intel.com>
Reviewed-by: buildbot <buildbot@intel.com>
Tested-by: buildbot <buildbot@intel.com>
drivers/base/ipc.c

index 4bb8898..fa39091 100644 (file)
@@ -616,6 +616,8 @@ int ipc_new_device(struct ipc_board_info *info)
        if (info->num_res)
                ipc_device_add_resources(ipcdev, info->res, info->num_res);
 
+       mutex_lock(&ipc_bus_lock[ipcdev->bus_id]);
+
        /**
         * If the device driver is probed before IPC controller is initilized,
         * just add it to the ipc_board_list, and process it after controller
@@ -623,12 +625,15 @@ int ipc_new_device(struct ipc_board_info *info)
         */
        if (bus_init_done[info->bus_id] == 0) {
                list_add_tail(&ipcdev->entry, &ipc_device_list[info->bus_id]);
-               return 0;
+               ret = 0;
+       } else {
+               ret = ipc_device_add(ipcdev);
+               if (ret == 0)
+                       list_add_tail(&ipcdev->entry,
+                                       &ipc_device_list[info->bus_id]);
        }
 
-       ret = ipc_device_add(ipcdev);
-       if (ret == 0)
-               list_add_tail(&ipcdev->entry, &ipc_device_list[info->bus_id]);
+       mutex_unlock(&ipc_bus_lock[ipcdev->bus_id]);
 
        return ret;
 }
@@ -637,7 +642,10 @@ EXPORT_SYMBOL_GPL(ipc_new_device);
 void ipc_device_add_to_list(struct ipc_device *ipcdev)
 {
        int bus_id = ipcdev->bus_id;
+
+       mutex_lock(&ipc_bus_lock[bus_id]);
        list_add_tail(&ipcdev->entry, &ipc_device_list[bus_id]);
+       mutex_unlock(&ipc_bus_lock[bus_id]);
 }
 EXPORT_SYMBOL_GPL(ipc_device_add_to_list);