From c5f37d509e04e0624d7c81a3a789c1a41e8db145 Mon Sep 17 00:00:00 2001 From: Yuanfang Zhang Date: Wed, 19 Jun 2019 13:12:20 +0800 Subject: [PATCH] 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: Yuanfang Zhang --- .../hwtracing/coresight/coresight-byte-cntr.c | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-byte-cntr.c b/drivers/hwtracing/coresight/coresight-byte-cntr.c index 518362d9a76e..1d7c217cd3d5 100644 --- a/drivers/hwtracing/coresight/coresight-byte-cntr.c +++ b/drivers/hwtracing/coresight/coresight-byte-cntr.c @@ -64,23 +64,29 @@ 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, @@ -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; }