eal/windows: check callback parameter of alarm functions
authorJie Zhou <jizh@linux.microsoft.com>
Wed, 7 Jul 2021 20:25:38 +0000 (13:25 -0700)
committerThomas Monjalon <thomas@monjalon.net>
Thu, 22 Jul 2021 20:06:27 +0000 (22:06 +0200)
EAL functions rte_eal_alarm_set() and rte_eal_alarm_cancel()
did not for invalid parameters in Windows implementation,
which is caught by the unit test alarm_autotest.

Enforce parameter check to fail fast for invalid parameters.

Fixes: f4cbdbc7fbd2 ("eal/windows: implement alarm API")
Cc: stable@dpdk.org
Signed-off-by: Jie Zhou <jizh@linux.microsoft.com>
Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
lib/eal/windows/eal_alarm.c

index f5bf887..e5dc54e 100644 (file)
@@ -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;