From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A5B53A0C41; Thu, 24 Jun 2021 02:36:48 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2FF0540141; Thu, 24 Jun 2021 02:36:48 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 5408D4003C for ; Thu, 24 Jun 2021 02:36:47 +0200 (CEST) Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id 88C0A20B6C50; Wed, 23 Jun 2021 17:36:46 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 88C0A20B6C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1624495006; bh=FW6VaMNLSdPrIr/6TNzWmgAEfGFCaY9u6AejJUr1Ujo=; h=From:To:Cc:Subject:Date:From; b=cVzhVqct2SBmkC/v0xER0KCnXctYQ2aEPmw0vl7UrVXppU5Fmn9LOegVjVszeq3JJ MQXT7ECXVTXT8SKKTNxaiZhjFj+p+53lzc6+8evbLkud+nqichytniHdPUptS+e3/9 RWU4TplFlqTHonOZ+Kwg0SMRu/na2HPssnD24jIA= From: Jie Zhou To: dev@dpdk.org Cc: dmitry.kozliuk@gmail.com, roretzla@microsoft.com, talshn@nvidia.com, pallavi.kadam@intel.com, navasile@linux.microsoft.com, dmitrym@microsoft.com Date: Wed, 23 Jun 2021 17:36:41 -0700 Message-Id: <1624495001-16613-1-git-send-email-jizh@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 Subject: [dpdk-dev] [PATCH v1] lib/eal: enforce alarm APIs parameters check X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Jie Zhou 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 Signed-off-by: Jie Zhou --- 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 #include +#include #include #include @@ -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