msm: camera: Fix race condition in msm_sd_register.

Acquire ordered_sd_mtx mutex while accessing ordered_sd_list.

Change-Id: I1b045d51b56de8488b3d7186cfa4582da664b710
Signed-off-by: Trishansh Bhardwaj <tbhardwa@codeaurora.org>
This commit is contained in:
Trishansh Bhardwaj 2017-08-21 15:48:03 +05:30 committed by Gerrit - the friendly Code Review server
parent 232b0f15cc
commit d943f1588c

View file

@ -34,6 +34,7 @@
static struct v4l2_device *msm_v4l2_dev;
static struct list_head ordered_sd_list;
static struct mutex ordered_sd_mtx;
static struct pm_qos_request msm_v4l2_pm_qos_request;
@ -404,7 +405,9 @@ int msm_sd_register(struct msm_sd_subdev *msm_subdev)
if (WARN_ON(!msm_v4l2_dev) || WARN_ON(!msm_v4l2_dev->dev))
return -EIO;
mutex_lock(&ordered_sd_mtx);
msm_add_sd_in_position(msm_subdev, &ordered_sd_list);
mutex_unlock(&ordered_sd_mtx);
return __msm_sd_register_subdev(&msm_subdev->sd);
}
EXPORT_SYMBOL(msm_sd_register);
@ -806,11 +809,13 @@ static long msm_private_ioctl(struct file *file, void *fh,
__func__);
}
mutex_lock(&ordered_sd_mtx);
if (!list_empty(&msm_v4l2_dev->subdevs)) {
list_for_each_entry(msm_sd, &ordered_sd_list, list)
__msm_sd_notify_freeze_subdevs(msm_sd,
event_data->status);
}
mutex_unlock(&ordered_sd_mtx);
}
break;
@ -995,9 +1000,11 @@ static int msm_close(struct file *filep)
struct msm_sd_subdev *msm_sd;
/*stop all hardware blocks immediately*/
mutex_lock(&ordered_sd_mtx);
if (!list_empty(&msm_v4l2_dev->subdevs))
list_for_each_entry(msm_sd, &ordered_sd_list, list)
__msm_sd_close_subdevs(msm_sd, &sd_close);
mutex_unlock(&ordered_sd_mtx);
/* remove msm_v4l2_pm_qos_request */
msm_pm_qos_remove_request();
@ -1353,6 +1360,7 @@ static int msm_probe(struct platform_device *pdev)
msm_init_queue(msm_session_q);
spin_lock_init(&msm_eventq_lock);
spin_lock_init(&msm_pid_lock);
mutex_init(&ordered_sd_mtx);
INIT_LIST_HEAD(&ordered_sd_list);
cam_debugfs_root = debugfs_create_dir(MSM_CAM_LOGSYNC_FILE_BASEDIR,