[dpdk-dev] [PATCH v1] lib/eal: enforce alarm APIs parameters check
Jie Zhou
jizh at linux.microsoft.com
Thu Jun 24 02:36:41 CEST 2021
From: Jie Zhou <jizh at microsoft.com>
lib/eal alarm APIs rte_eal_alarm_set and rte_eal_alarm_cancel
on Windows do not check parameters to fail fast for invalid
parameters, which captured by DPDK UT alarm_autotest.
Enforce Windows lib/eal alarm APIs parameters check and log
invalid parameter info.
Signed-off-by: Jie Zhou <jizh at microsoft.com>
Signed-off-by: Jie Zhou <jizh at linux.microsoft.com>
---
lib/eal/windows/eal_alarm.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/lib/eal/windows/eal_alarm.c b/lib/eal/windows/eal_alarm.c
index f5bf88715a..7bb79ae869 100644
--- a/lib/eal/windows/eal_alarm.c
+++ b/lib/eal/windows/eal_alarm.c
@@ -4,6 +4,7 @@
#include <stdatomic.h>
#include <stdbool.h>
+#include <inttypes.h>
#include <rte_alarm.h>
#include <rte_spinlock.h>
@@ -91,6 +92,22 @@ rte_eal_alarm_set(uint64_t us, rte_eal_alarm_callback cb_fn, void *cb_arg)
LARGE_INTEGER deadline;
int ret;
+ /* Check if us is valid */
+ if (us < 1 || us >(UINT64_MAX - US_PER_S)) {
+ RTE_LOG(ERR, EAL, "Invalid us: %" PRIu64 "\n"
+ "Valid us range is 1 to (UINT64_MAX - US_PER_S)\n",
+ us);
+ ret = -EINVAL;
+ goto exit;
+ }
+
+ /* Check if callback is not NULL */
+ if (!cb_fn) {
+ RTE_LOG(ERR, EAL, "NULL callback\n");
+ ret = -EINVAL;
+ goto exit;
+ }
+
/* Calculate deadline ASAP, unit of measure = 100ns. */
GetSystemTimePreciseAsFileTime(&ft);
deadline.LowPart = ft.dwLowDateTime;
@@ -180,6 +197,12 @@ rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg)
bool executing;
removed = 0;
+
+ if (!cb_fn) {
+ RTE_LOG(ERR, EAL, "NULL callback\n");
+ return -EINVAL;
+ }
+
do {
executing = false;
--
2.31.0.vfs.0.1
More information about the dev
mailing list