Thread (9 messages) 9 messages, 4 authors, 2021-07-22

[dpdk-dev] [PATCH v2] eal/windows: enforce alarm APIs parameter check

From: Jie Zhou <hidden>
Date: 2021-07-07 20:25:48
Subsystem: library code, the rest · Maintainers: Andrew Morton, Linus Torvalds

eal/windows alarm APIs rte_eal_alarm_set and rte_eal_alarm_cancel
did not check parameters to fail fast for invalid parameters, which
caught by DPDK UT alarm_autotest.

Enforce eal/windows alarm APIs parameter check to fail fast for
invalid parameters.

Fixes: f4cbdbc7fbd2 ("eal/windows: implement alarm API")
Cc: stable@dpdk.org

Signed-off-by: Jie Zhou <redacted>

---
V2 changes:
    - Remove API parameter check on arbitrary 'us' range
    - Do explicit NULL cb_fn check

---
 lib/eal/windows/eal_alarm.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
diff --git a/lib/eal/windows/eal_alarm.c b/lib/eal/windows/eal_alarm.c
index f5bf88715a..e5dc54efb8 100644
--- a/lib/eal/windows/eal_alarm.c
+++ b/lib/eal/windows/eal_alarm.c
@@ -91,6 +91,12 @@ rte_eal_alarm_set(uint64_t us, rte_eal_alarm_callback cb_fn, void *cb_arg)
 	LARGE_INTEGER deadline;
 	int ret;
 
+	if (cb_fn == NULL) {
+		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 +186,12 @@ rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg)
 	bool executing;
 
 	removed = 0;
+
+	if (cb_fn == NULL) {
+		RTE_LOG(ERR, EAL, "NULL callback\n");
+		return -EINVAL;
+	}
+
 	do {
 		executing = false;
 
-- 
2.31.0.vfs.0.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help