From 827ad8232cb87a0f79e65c3f5bb154a2fd771153 Mon Sep 17 00:00:00 2001 From: Andrew Rybchenko Date: Wed, 24 Jul 2019 14:16:33 +0100 Subject: [PATCH] net/sfc: fix align to power of 2 when align has smaller type Substitute driver-defined P2ALIGN() with EFX_P2ALIGN() defined in libefx. Cast value and alignment to one specified type to guarantee result correctness. Fixes: e1b944598579 ("net/sfc: build libefx") Cc: stable@dpdk.org Signed-off-by: Andrew Rybchenko --- drivers/net/sfc/base/ef10_rx.c | 2 +- drivers/net/sfc/base/efx.h | 4 ++++ drivers/net/sfc/efsys.h | 4 ---- drivers/net/sfc/sfc_rx.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/net/sfc/base/ef10_rx.c b/drivers/net/sfc/base/ef10_rx.c index b087a5d42d..bb4489bbf3 100644 --- a/drivers/net/sfc/base/ef10_rx.c +++ b/drivers/net/sfc/base/ef10_rx.c @@ -859,7 +859,7 @@ ef10_rx_qpush( efx_dword_t dword; /* Hardware has alignment restriction for WPTR */ - wptr = P2ALIGN(added, EF10_RX_WPTR_ALIGN); + wptr = EFX_P2ALIGN(unsigned int, added, EF10_RX_WPTR_ALIGN); if (pushed == wptr) return; diff --git a/drivers/net/sfc/base/efx.h b/drivers/net/sfc/base/efx.h index 835d057b12..6aff68b540 100644 --- a/drivers/net/sfc/base/efx.h +++ b/drivers/net/sfc/base/efx.h @@ -33,6 +33,10 @@ extern "C" { #define EFX_P2ROUNDUP(_type, _value, _align) \ (-(-(_type)(_value) & -(_type)(_align))) +/* Align value down to the nearest power of two. */ +#define EFX_P2ALIGN(_type, _value, _align) \ + ((_type)(_value) & -(_type)(_align)) + /* Return codes */ typedef __success(return == 0) int efx_rc_t; diff --git a/drivers/net/sfc/efsys.h b/drivers/net/sfc/efsys.h index 4c122d040b..79fd3c144d 100644 --- a/drivers/net/sfc/efsys.h +++ b/drivers/net/sfc/efsys.h @@ -76,10 +76,6 @@ typedef bool boolean_t; #define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0) #endif -#ifndef P2ALIGN -#define P2ALIGN(_x, _a) ((_x) & -(_a)) -#endif - #ifndef ISP2 #define ISP2(x) rte_is_power_of_2(x) #endif diff --git a/drivers/net/sfc/sfc_rx.c b/drivers/net/sfc/sfc_rx.c index 23dff09672..e6809bb64e 100644 --- a/drivers/net/sfc/sfc_rx.c +++ b/drivers/net/sfc/sfc_rx.c @@ -1019,7 +1019,7 @@ sfc_rx_mb_pool_buf_size(struct sfc_adapter *sa, struct rte_mempool *mb_pool) * Start is aligned the same or better than end, * just align length. */ - buf_size = P2ALIGN(buf_size, nic_align_end); + buf_size = EFX_P2ALIGN(uint32_t, buf_size, nic_align_end); } return buf_size; -- 2.20.1