aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonny Svärd <jonny.svaerd@arm.com>2024-04-19 14:59:15 +0200
committerJonny Svärd <jonny.svaerd@arm.com>2024-04-22 14:03:46 +0000
commit149b1f38e8ca67aef965b8f5b1dac5d1e2155c65 (patch)
treee8c600e5ff68f2550ea5134e8e49f85d22a6b0c5
parent4140d66087152d21f81259300f854a841d473c0c (diff)
downloadethos-u-core-driver-149b1f38e8ca67aef965b8f5b1dac5d1e2155c65.tar.gz
Verify return value of pmu_event_value() calls
Make sure that pmu_event_value returns a valid PMU event value before writing to PMU HW registers. Change-Id: I546493a7870fc73ef2b7269cd4d7be4072c3cebf Signed-off-by: Jonny Svärd <jonny.svaerd@arm.com>
-rw-r--r--src/ethosu_pmu.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/src/ethosu_pmu.c b/src/ethosu_pmu.c
index b5925c4..0b58c6f 100644
--- a/src/ethosu_pmu.c
+++ b/src/ethosu_pmu.c
@@ -1,6 +1,5 @@
/*
- * SPDX-FileCopyrightText: Copyright 2019-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
- *
+ * SPDX-FileCopyrightText: Copyright 2019-2024 Arm Limited and/or its affiliates <open-source-office@arm.com>
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
@@ -75,10 +74,8 @@ static uint32_t pmu_event_value(enum ethosu_pmu_event_type event)
{
return eventbyid[event];
}
- else
- {
- return (uint32_t)(-1);
- }
+
+ return UINT32_MAX;
}
/*****************************************************************************
@@ -110,6 +107,12 @@ void ETHOSU_PMU_Set_EVTYPER(struct ethosu_driver *drv, uint32_t num, enum ethosu
{
assert(num < ETHOSU_PMU_NCOUNTERS);
uint32_t val = pmu_event_value(type);
+ if (val == UINT32_MAX)
+ {
+ LOG_ERR("Invalid ethosu_pmu_event_type: %d", type);
+ return;
+ }
+
LOG_DEBUG("num=%" PRIu32 ", type=%d, val=%" PRIu32, num, type, val);
drv->dev->reg->PMEVTYPER[num].word = val;
}
@@ -269,8 +272,14 @@ void ETHOSU_PMU_CNTR_Increment(struct ethosu_driver *drv, uint32_t mask)
void ETHOSU_PMU_PMCCNTR_CFG_Set_Start_Event(struct ethosu_driver *drv, enum ethosu_pmu_event_type start_event)
{
LOG_DEBUG("start_event=%u", start_event);
- uint32_t val = pmu_event_value(start_event);
struct pmccntr_cfg_r cfg;
+ uint32_t val = pmu_event_value(start_event);
+ if (val == UINT32_MAX)
+ {
+ LOG_ERR("Invalid ethosu_pmu_event_type: %d", start_event);
+ return;
+ }
+
cfg.word = drv->dev->reg->PMCCNTR_CFG.word;
cfg.CYCLE_CNT_CFG_START = val;
drv->dev->reg->PMCCNTR_CFG.word = cfg.word;
@@ -279,8 +288,14 @@ void ETHOSU_PMU_PMCCNTR_CFG_Set_Start_Event(struct ethosu_driver *drv, enum etho
void ETHOSU_PMU_PMCCNTR_CFG_Set_Stop_Event(struct ethosu_driver *drv, enum ethosu_pmu_event_type stop_event)
{
LOG_DEBUG("stop_event=%u", stop_event);
- uint32_t val = pmu_event_value(stop_event);
struct pmccntr_cfg_r cfg;
+ uint32_t val = pmu_event_value(stop_event);
+ if (val == UINT32_MAX)
+ {
+ LOG_ERR("Invalid ethosu_pmu_event_type: %d", stop_event);
+ return;
+ }
+
cfg.word = drv->dev->reg->PMCCNTR_CFG.word;
cfg.CYCLE_CNT_CFG_STOP = val;
drv->dev->reg->PMCCNTR_CFG.word = cfg.word;