All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] eal: fix pointer add/sub macros for large offsets values
@ 2026-09-11 16:40 Bruce Richardson
  2026-09-14  8:29 ` Konstantin Ananyev
  0 siblings, 1 reply; 3+ messages in thread
From: Bruce Richardson @ 2026-09-11 16:40 UTC (permalink / raw)
  To: dev; +Cc: Bruce Richardson, stable

The macros for adding or subtracting from pointers cast the pointer type
to uintptr_t before doing the arithmetic. However, for 32-bit builds, if
the value being added or subtracted is larger than uintptr_t, then we
get errors when casting back to "void *" type. We fix this by casting
the result to uintptr_t before casting to pointer.

Fixes: af75078fece3 ("first public release")
Cc: stable@dpdk.org

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 lib/eal/include/rte_common.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h
index f872d3eabb..c17f50e2fd 100644
--- a/lib/eal/include/rte_common.h
+++ b/lib/eal/include/rte_common.h
@@ -572,12 +572,12 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
 /**
  * add a byte-value offset to a pointer
  */
-#define RTE_PTR_ADD(ptr, x) ((void*)((uintptr_t)(ptr) + (x)))
+#define RTE_PTR_ADD(ptr, x) ((void *)(uintptr_t)((uintptr_t)(ptr) + (x)))
 
 /**
  * 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)((uintptr_t)(ptr) - (x)))
 
 /**
  * get the difference between two pointer values, i.e. how far apart
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [PATCH] eal: fix pointer add/sub macros for large offsets values
  2026-09-11 16:40 [PATCH] eal: fix pointer add/sub macros for large offsets values Bruce Richardson
@ 2026-09-14  8:29 ` Konstantin Ananyev
  2026-09-14  9:05   ` Bruce Richardson
  0 siblings, 1 reply; 3+ messages in thread
From: Konstantin Ananyev @ 2026-09-14  8:29 UTC (permalink / raw)
  To: Bruce Richardson, dev@dpdk.org; +Cc: stable@dpdk.org



> The macros for adding or subtracting from pointers cast the pointer type
> to uintptr_t before doing the arithmetic. However, for 32-bit builds, if
> the value being added or subtracted is larger than uintptr_t, then we
> get errors when casting back to "void *" type.

But probably error here in such case is a good thing, as it flags an overflow?
Can't user explicitly convert x then to 32-bit type, if that was an intention?

> We fix this by casting
> the result to uintptr_t before casting to pointer.
> 
> Fixes: af75078fece3 ("first public release")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
>  lib/eal/include/rte_common.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h
> index f872d3eabb..c17f50e2fd 100644
> --- a/lib/eal/include/rte_common.h
> +++ b/lib/eal/include/rte_common.h
> @@ -572,12 +572,12 @@ static void __attribute__((destructor(RTE_PRIO(prio)),
> used)) func(void)
>  /**
>   * add a byte-value offset to a pointer
>   */
> -#define RTE_PTR_ADD(ptr, x) ((void*)((uintptr_t)(ptr) + (x)))
> +#define RTE_PTR_ADD(ptr, x) ((void *)(uintptr_t)((uintptr_t)(ptr) + (x)))
> 
>  /**
>   * 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)((uintptr_t)(ptr) - (x)))
> 
>  /**
>   * get the difference between two pointer values, i.e. how far apart
> --
> 2.53.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] eal: fix pointer add/sub macros for large offsets values
  2026-09-14  8:29 ` Konstantin Ananyev
@ 2026-09-14  9:05   ` Bruce Richardson
  0 siblings, 0 replies; 3+ messages in thread
From: Bruce Richardson @ 2026-09-14  9:05 UTC (permalink / raw)
  To: Konstantin Ananyev; +Cc: dev@dpdk.org, stable@dpdk.org

On Mon, Sep 14, 2026 at 08:29:42AM +0000, Konstantin Ananyev wrote:
> 
> 
> > The macros for adding or subtracting from pointers cast the pointer type
> > to uintptr_t before doing the arithmetic. However, for 32-bit builds, if
> > the value being added or subtracted is larger than uintptr_t, then we
> > get errors when casting back to "void *" type.
> 
> But probably error here in such case is a good thing, as it flags an overflow?
> Can't user explicitly convert x then to 32-bit type, if that was an intention?
> 
Fair point, hadn't thought of that! Let me mark this as rejected so.

/Bruce

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-14  9:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-11 16:40 [PATCH] eal: fix pointer add/sub macros for large offsets values Bruce Richardson
2026-09-14  8:29 ` Konstantin Ananyev
2026-09-14  9:05   ` Bruce Richardson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.