Skip to content

Commit f67bc15

Browse files
Dan CarpenterSuzuki K Poulose
authored andcommitted
coresight: Fix signedness bug in tmc_etr_buf_insert_barrier_packet()
This code generates a Smatch warning: drivers/hwtracing/coresight/coresight-tmc-etr.c:947 tmc_etr_buf_insert_barrier_packet() error: uninitialized symbol 'bufp'. The problem is that if tmc_sg_table_get_data() returns -EINVAL, then when we test if "len < CORESIGHT_BARRIER_PKT_SIZE", the negative "len" value is type promoted to a high unsigned long value which is greater than CORESIGHT_BARRIER_PKT_SIZE. Fix this bug by adding an explicit check for error codes. Fixes: 75f4e36 ("coresight: tmc-etr: Add transparent buffer management") Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com> Link: https://lore.kernel.org/r/7d33e244-d8b9-4c27-9653-883a13534b01@kili.mountain
1 parent ac9a786 commit f67bc15

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/hwtracing/coresight/coresight-tmc-etr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ tmc_etr_buf_insert_barrier_packet(struct etr_buf *etr_buf, u64 offset)
942942

943943
len = tmc_etr_buf_get_data(etr_buf, offset,
944944
CORESIGHT_BARRIER_PKT_SIZE, &bufp);
945-
if (WARN_ON(len < CORESIGHT_BARRIER_PKT_SIZE))
945+
if (WARN_ON(len < 0 || len < CORESIGHT_BARRIER_PKT_SIZE))
946946
return -EINVAL;
947947
coresight_insert_barrier_packet(bufp);
948948
return offset + CORESIGHT_BARRIER_PKT_SIZE;

0 commit comments

Comments
 (0)