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

Commit 3edbdee3 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "coresight: byte-cntr: add sanity check while reading the data"

parents 1835df5c c9c0a701
Loading
Loading
Loading
Loading
+21 −14
Original line number Diff line number Diff line
/* Copyright (c) 2017, The Linux Foundation. All rights reserved.
/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -23,18 +23,24 @@
static struct tmc_drvdata *tmcdrvdata;

static void tmc_etr_read_bytes(struct byte_cntr *byte_cntr_data, loff_t *ppos,
			       size_t bytes, size_t *len)
			       size_t bytes, size_t *len, char **bufp)
{
	if (*len >= bytes) {
		atomic_dec(&byte_cntr_data->irq_cnt);

	if (*bufp >= (char *)(tmcdrvdata->vaddr + tmcdrvdata->size))
		*bufp = tmcdrvdata->vaddr;

	if (*len >= bytes)
		*len = bytes;
	} else {
		if (((uint32_t)*ppos % bytes) + *len > bytes)
	else if (((uint32_t)*ppos % bytes) + *len > bytes)
		*len = bytes - ((uint32_t)*ppos % bytes);
		if ((*len + (uint32_t)*ppos) % bytes == 0)

	if ((*bufp + *len) > (char *)(tmcdrvdata->vaddr +
		tmcdrvdata->size))
		*len = (char *)(tmcdrvdata->vaddr + tmcdrvdata->size) -
			*bufp;
	if (*len == bytes || (*len + (uint32_t)*ppos) % bytes == 0)
		atomic_dec(&byte_cntr_data->irq_cnt);
}
}

static void tmc_etr_sg_read_pos(loff_t *ppos,
				size_t bytes, bool noirq, size_t *len,
@@ -96,7 +102,7 @@ static void tmc_etr_sg_read_pos(loff_t *ppos,
		if (*len >= (bytes - ((uint32_t)*ppos % bytes)))
			*len = bytes - ((uint32_t)*ppos % bytes);

		if ((*len + (uint32_t)*ppos) % bytes == 0)
		if (*len == bytes || (*len + (uint32_t)*ppos) % bytes == 0)
			atomic_dec(&tmcdrvdata->byte_cntr->irq_cnt);
	}

@@ -153,11 +159,12 @@ static ssize_t tmc_etr_byte_cntr_read(struct file *fp, char __user *data,
			if (!byte_cntr_data->read_active)
				goto err0;
		}
		bufp = (char *)(tmcdrvdata->vaddr + *ppos);
		bufp = (char *)(tmcdrvdata->buf + *ppos);

		if (tmcdrvdata->mem_type == TMC_ETR_MEM_TYPE_CONTIG)
			tmc_etr_read_bytes(byte_cntr_data, ppos,
					   byte_cntr_data->block_size, &len);
					   byte_cntr_data->block_size, &len,
					   &bufp);
		else
			tmc_etr_sg_read_pos(ppos, byte_cntr_data->block_size, 0,
					    &len, &bufp);
@@ -179,7 +186,7 @@ static ssize_t tmc_etr_byte_cntr_read(struct file *fp, char __user *data,
			if (tmcdrvdata->mem_type == TMC_ETR_MEM_TYPE_CONTIG)
				tmc_etr_read_bytes(byte_cntr_data, ppos,
						   byte_cntr_data->block_size,
						   &len);
						   &len, &bufp);
			else
				tmc_etr_sg_read_pos(ppos,
						    byte_cntr_data->block_size,