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 9AF6EA00C2; Sun, 21 Aug 2022 22:50:36 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2269342802; Sun, 21 Aug 2022 22:50:32 +0200 (CEST) Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) by mails.dpdk.org (Postfix) with ESMTP id 404C9410F2; Sun, 21 Aug 2022 22:50:30 +0200 (CEST) Received: by mail-lj1-f176.google.com with SMTP id x10so8991818ljq.4; Sun, 21 Aug 2022 13:50:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=i8hZ1WoRhTgMwe8SULFUTQYn8es8Ngt4eu+LpQucJkw=; b=MaFoynL7JfQrozb66SC/f9u7aCRyVWWJ5sydFLbK6G225EiMumyVXE6HmasHZ36cRx 2k+0QQlmLvxeNrWU3drDotnz4rM7TRr4jNI6vn6DaK2AHp2YAAjbWfXUEdnxK4lQ86hk ke76MITGWMBeElC3hxJCxRm/H7eEzM2ZeAYFr5QbkyX7HAEjkajeHaijsYGCCuOAu2Hi qwnHl5A8+I3pu+/mvSZAoUYJ9LHAh2M1nFB7KbSkEQ2cHrX/JZui6HngQS5Ptyfitprq 4dduDnny5TZ9qMQsSkTb848WzHTZrlu299OnUATyERk4gWBZ10e2IEm6eWiWX7F9R4IA HlqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=i8hZ1WoRhTgMwe8SULFUTQYn8es8Ngt4eu+LpQucJkw=; b=MPeqnYzJA6XtxiWOulMq1yLsKePR42TPVeqqKs2Rkqm0rbYeqXuT76M0AU0b8eMyeK njX/+ApFWFUZIwFyKvy+qnmpHhaMKLALmjSgiVV/tW3d86Glqw0OMPDnyxnSwfeMci1j yniV98Zg8x/S+aFsDW1s76DWrBJZiyEGp5JZLVbDMaavqHj/7gRUcTKwPhqjDlFpcUC/ EMSgB8EAS02nmpi1ykkLt72wyOYkAqWEvtNnjQfmFVK+lELcJAhjfgDyYdfaTkTzHskj Wm9lAzzSo01+9FEnclHF0W4NYNjwi45Z2Ul1tlAaC1HDSAG8jsxZq3L7voYjI1bR25jV VhPg== X-Gm-Message-State: ACgBeo04i7tXlTa/KydI8oa1XE+P69+B2LiapVZVEywLQcsPt2V0hnsK NhvyHnx+oAWz3imKDFyzAz2QUWBJTcg= X-Google-Smtp-Source: AA6agR4MOv0hCMdkw4pZ5FXd/BTeqL3x1MME6g0nSAmjkG1QJ/6kr75SEywxQmu4VGaDozqwpbSMHA== X-Received: by 2002:a05:651c:103c:b0:25e:78dd:62fa with SMTP id w28-20020a05651c103c00b0025e78dd62famr4590012ljm.183.1661115029435; Sun, 21 Aug 2022 13:50:29 -0700 (PDT) Received: from sovereign.. (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id b17-20020a056512071100b00492c77c55ddsm1337897lfs.67.2022.08.21.13.50.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 13:50:28 -0700 (PDT) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Dmitry Kozlyuk , stable@dpdk.org Subject: [PATCH 1/3] eal: fix pointer arithmetic with an expression argument Date: Sun, 21 Aug 2022 23:50:07 +0300 Message-Id: <20220821205009.1317044-2-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220821205009.1317044-1-dmitry.kozliuk@gmail.com> References: <20220821205009.1317044-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 RTE_PTR_SUB(ptr, x) and RTE_PTR_ALIGN_FLOOR() worked incorrectly if "ptr" was an expression: uint32_t arr[3]; RTE_PTR_SUB(arr + 1, sizeof(arr[0])); // expected: (uint32_t *)((uintptr_t)(arr + 1) - 4) == arr // actual: (uint32_t *)((uintptr_t) arr + 1 - 4) != arr RTE_PTR_ALIGN_FLOOR(arr + 2, sizeof(arr[0])); // expected: RTE_ALIGN_FLOOR((uintptr_t)(arr + 2), 4) == &arr[2] // actual: RTE_ALIGN_FLOOR((uintptr_t) arr + 2, 4) == &arr[0] Fix the macros and extend the relevant unit test. Fixes: af75078fece3 ("first public release") Cc: stable@dpdk.org Signed-off-by: Dmitry Kozlyuk --- app/test/test_common.c | 11 +++++++++++ lib/eal/include/rte_common.h | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/test/test_common.c b/app/test/test_common.c index ef177cecb1..4194c1208a 100644 --- a/app/test/test_common.c +++ b/app/test/test_common.c @@ -31,6 +31,7 @@ test_macros(int __rte_unused unused_parm) uintptr_t unused = 0; unsigned int smaller = SMALLER, bigger = BIGGER; + uint32_t arr[3]; RTE_SET_USED(unused); @@ -41,6 +42,16 @@ test_macros(int __rte_unused unused_parm) FAIL_MACRO(RTE_PTR_ADD); if ((uintptr_t)RTE_PTR_SUB(BIGGER, PTR_DIFF) != SMALLER) FAIL_MACRO(RTE_PTR_SUB); + if (RTE_PTR_ADD(arr + 1, sizeof(arr[0])) != &arr[2]) + FAIL_MACRO(RTE_PTR_ADD); + if (RTE_PTR_SUB(arr + 1, sizeof(arr[0])) != &arr[0]) + FAIL_MACRO(RTE_PTR_SUB); + if (RTE_PTR_ALIGN_FLOOR(arr + 2, 4) != &arr[2]) + FAIL_MACRO(RTE_PTR_ALIGN_FLOOR); + if (RTE_PTR_ALIGN_CEIL(arr + 2, 4) != &arr[2]) + FAIL_MACRO(RTE_PTR_ALIGN_CEIL); + if (RTE_PTR_ALIGN(arr + 2, 4) != &arr[2]) + FAIL_MACRO(RTE_PTR_ALIGN); if (RTE_PTR_DIFF(BIGGER, SMALLER) != PTR_DIFF) FAIL_MACRO(RTE_PTR_DIFF); if (RTE_MAX(SMALLER, BIGGER) != BIGGER) diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h index a96cc2a138..d517e9f75f 100644 --- a/lib/eal/include/rte_common.h +++ b/lib/eal/include/rte_common.h @@ -295,7 +295,7 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) /** * subtract a byte-value offset from a pointer */ -#define RTE_PTR_SUB(ptr, x) ((void*)((uintptr_t)ptr - (x))) +#define RTE_PTR_SUB(ptr, x) ((void *)((uintptr_t)(ptr) - (x))) /** * get the difference between two pointer values, i.e. how far apart @@ -320,7 +320,7 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) * must be a power-of-two value. */ #define RTE_PTR_ALIGN_FLOOR(ptr, align) \ - ((typeof(ptr))RTE_ALIGN_FLOOR((uintptr_t)ptr, align)) + ((typeof(ptr))RTE_ALIGN_FLOOR((uintptr_t)(ptr), align)) /** * Macro to align a value to a given power-of-two. The resultant value -- 2.33.1