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

Commit c5f37d50 authored by Yuanfang Zhang's avatar Yuanfang Zhang Committed by Gerrit - the friendly Code Review server
Browse files

Coresight: byte-cntr: Don't read byte-cntr when etr is diasbled



Tmc etr buffer will be read when cat /dev/byte-cntr. If tmc etr
is disabled, the buffer will be released. So exit byte-cntr-read
when etr is disabled.

Change-Id: Ia7037362dd973895f3b095a2ffbbab83570fb57e
Signed-off-by: default avatarYuanfang Zhang <zhangyuanfang@codeaurora.org>
parent 98d83a7e
Loading
Loading
Loading
Loading
+23 −8
Original line number Diff line number Diff line
@@ -64,25 +64,31 @@ static ssize_t tmc_etr_byte_cntr_read(struct file *fp, char __user *data,
{
	struct byte_cntr *byte_cntr_data = fp->private_data;
	char *bufp;

	int ret = 0;
	if (!data)
		return -EINVAL;

	mutex_lock(&byte_cntr_data->byte_cntr_lock);
	if (!byte_cntr_data->read_active)
	if (!byte_cntr_data->read_active) {
		ret = -EINVAL;
		goto err0;
	}

	if (byte_cntr_data->enable) {
		if (!atomic_read(&byte_cntr_data->irq_cnt)) {
			mutex_unlock(&byte_cntr_data->byte_cntr_lock);
			if (wait_event_interruptible(byte_cntr_data->wq,
				atomic_read(&byte_cntr_data->irq_cnt) > 0))
				atomic_read(&byte_cntr_data->irq_cnt) > 0
				|| !byte_cntr_data->enable))
				return -ERESTARTSYS;
			mutex_lock(&byte_cntr_data->byte_cntr_lock);
			if (!byte_cntr_data->read_active)
			if (!byte_cntr_data->read_active) {
				ret = -EINVAL;
				goto err0;
			}

		}

		tmc_etr_read_bytes(byte_cntr_data, ppos,
				   byte_cntr_data->block_size, &len, &bufp);

@@ -90,8 +96,10 @@ static ssize_t tmc_etr_byte_cntr_read(struct file *fp, char __user *data,
		if (!atomic_read(&byte_cntr_data->irq_cnt)) {
			tmc_etr_flush_bytes(ppos, byte_cntr_data->block_size,
						  &len);
			if (!len)
			if (!len) {
				ret = -EINVAL;
				goto err0;
			}
		} else {
			tmc_etr_read_bytes(byte_cntr_data, ppos,
						   byte_cntr_data->block_size,
@@ -110,9 +118,14 @@ static ssize_t tmc_etr_byte_cntr_read(struct file *fp, char __user *data,
		*ppos = 0;
	else
		*ppos += len;

	goto out;

err0:
	mutex_unlock(&byte_cntr_data->byte_cntr_lock);

	return ret;
out:
	mutex_unlock(&byte_cntr_data->byte_cntr_lock);
	return len;
}

@@ -123,7 +136,8 @@ void tmc_etr_byte_cntr_start(struct byte_cntr *byte_cntr_data)

	mutex_lock(&byte_cntr_data->byte_cntr_lock);

	if (byte_cntr_data->block_size == 0) {
	if (byte_cntr_data->block_size == 0
		|| byte_cntr_data->read_active) {
		mutex_unlock(&byte_cntr_data->byte_cntr_lock);
		return;
	}
@@ -141,6 +155,8 @@ void tmc_etr_byte_cntr_stop(struct byte_cntr *byte_cntr_data)

	mutex_lock(&byte_cntr_data->byte_cntr_lock);
	byte_cntr_data->enable = false;
	byte_cntr_data->read_active = false;
	wake_up(&byte_cntr_data->wq);
	coresight_csr_set_byte_cntr(byte_cntr_data->csr, 0);
	mutex_unlock(&byte_cntr_data->byte_cntr_lock);

@@ -184,7 +200,6 @@ static int tmc_etr_byte_cntr_open(struct inode *in, struct file *fp)
	byte_cntr_data->enable = true;
	byte_cntr_data->read_active = true;
	mutex_unlock(&byte_cntr_data->byte_cntr_lock);

	return 0;
}