From 753bde6a073032e063d27653331e16ce8b9b5c1f Mon Sep 17 00:00:00 2001 From: Shijie Zhang Date: Wed, 23 May 2012 04:12:23 +0800 Subject: [PATCH] IPC: add bus lock protect for ipc_device_list 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 Reviewed-on: http://android.intel.com:8080/49725 Reviewed-by: Yang, Bin Reviewed-by: Chen, Jie D Reviewed-by: Du, Alek Tested-by: Tang, HaifengX Reviewed-by: buildbot Tested-by: buildbot --- drivers/base/ipc.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/base/ipc.c b/drivers/base/ipc.c index 4bb8898..fa39091 100644 --- a/drivers/base/ipc.c +++ b/drivers/base/ipc.c @@ -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); -- 2.7.4