Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5c5fc156 authored by Pan Fang's avatar Pan Fang
Browse files

msm:rpm-log: add the mutex to protect read opertion



This commit will protect rpm log read operation. Then multithread
read the same rpm log buffer will not corruption.

CRs-Fixed: 646485
Change-Id: I38b10c89902a9268fc0a4d649267d3a3df9a739a
Signed-off-by: default avatarPan Fang <fangpan@codeaurora.org>
parent c82bee2d
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -50,6 +50,7 @@ struct msm_rpm_log_buffer {
	char *data;
	char *data;
	u32 len;
	u32 len;
	u32 pos;
	u32 pos;
	struct mutex mutex;
	u32 max_len;
	u32 max_len;
	u32 read_idx;
	u32 read_idx;
	struct msm_rpm_log_platform_data *pdata;
	struct msm_rpm_log_platform_data *pdata;
@@ -216,6 +217,7 @@ static ssize_t msm_rpm_log_file_read(struct file *file, char __user *bufu,
	if (!access_ok(VERIFY_WRITE, bufu, count))
	if (!access_ok(VERIFY_WRITE, bufu, count))
		return -EFAULT;
		return -EFAULT;


	mutex_lock(&buf->mutex);
	/* check for more messages if local buffer empty */
	/* check for more messages if local buffer empty */
	if (buf->pos == buf->len) {
	if (buf->pos == buf->len) {
		buf->pos = 0;
		buf->pos = 0;
@@ -224,6 +226,7 @@ static ssize_t msm_rpm_log_file_read(struct file *file, char __user *bufu,
	}
	}


	if ((file->f_flags & O_NONBLOCK) && buf->len == 0)
	if ((file->f_flags & O_NONBLOCK) && buf->len == 0)
		mutex_unlock(&buf->mutex);
		return -EAGAIN;
		return -EAGAIN;


	/* loop until new messages arrive */
	/* loop until new messages arrive */
@@ -239,6 +242,7 @@ static ssize_t msm_rpm_log_file_read(struct file *file, char __user *bufu,


	remaining = __copy_to_user(bufu, &(buf->data[buf->pos]), out_len);
	remaining = __copy_to_user(bufu, &(buf->data[buf->pos]), out_len);
	buf->pos += out_len - remaining;
	buf->pos += out_len - remaining;
	mutex_unlock(&buf->mutex);


	return out_len - remaining;
	return out_len - remaining;
}
}
@@ -285,6 +289,7 @@ static int msm_rpm_log_file_open(struct inode *inode, struct file *file)
	buf->pdata = pdata;
	buf->pdata = pdata;
	buf->len = 0;
	buf->len = 0;
	buf->pos = 0;
	buf->pos = 0;
	mutex_init(&buf->mutex);
	buf->max_len = PRINTED_LENGTH(pdata->log_len);
	buf->max_len = PRINTED_LENGTH(pdata->log_len);
	buf->read_idx = msm_rpm_log_read(pdata, MSM_RPM_LOG_PAGE_INDICES,
	buf->read_idx = msm_rpm_log_read(pdata, MSM_RPM_LOG_PAGE_INDICES,
					 MSM_RPM_LOG_HEAD);
					 MSM_RPM_LOG_HEAD);