All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Rybchenko <arybchenko@solarflare.com>
To: <dev@dpdk.org>
Cc: <stable@dpdk.org>
Subject: [dpdk-dev] [PATCH v3 2/3] net/sfc: fix align to power of 2 when align has smaller type
Date: Wed, 24 Jul 2019 14:16:33 +0100	[thread overview]
Message-ID: <1563974194-5930-3-git-send-email-arybchenko@solarflare.com> (raw)
In-Reply-To: <1563974194-5930-1-git-send-email-arybchenko@solarflare.com>

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 <arybchenko@solarflare.com>
---
 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 b087a5d42..bb4489bbf 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 835d057b1..6aff68b54 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 4c122d040..79fd3c144 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 23dff0967..e6809bb64 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.17.1


  parent reply	other threads:[~2019-07-24 13:17 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-24 12:59 [dpdk-dev] [PATCH 0/3] net/sfc: fix power of 2 alignment macros Andrew Rybchenko
2019-07-24 12:59 ` [dpdk-dev] [PATCH 1/3] net/sfc: fix power of 2 round up when align has smaller type Andrew Rybchenko
2019-07-24 12:59 ` [dpdk-dev] [PATCH 2/3] net/sfc: fix align to power of 2 " Andrew Rybchenko
2019-07-24 12:59 ` [dpdk-dev] [PATCH 3/3] net/sfc: unify power of 2 alignment check macro Andrew Rybchenko
2019-07-24 13:04 ` [dpdk-dev] [PATCH 0/3] net/sfc: fix power of 2 alignment macros Andrew Rybchenko
2019-07-24 13:08 ` [dpdk-dev] [PATCH v2 " Andrew Rybchenko
2019-07-24 13:08   ` [dpdk-dev] [PATCH v2 1/3] net/sfc: fix power of 2 round up when align has smaller type Andrew Rybchenko
2019-07-24 13:08   ` [dpdk-dev] [PATCH v2 3/3] net/sfc: unify power of 2 alignment check macro Andrew Rybchenko
2019-07-24 13:16 ` [dpdk-dev] [PATCH v3 0/3] net/sfc: fix power of 2 alignment macros Andrew Rybchenko
2019-07-24 13:16   ` [dpdk-dev] [PATCH v3 1/3] net/sfc: fix power of 2 round up when align has smaller type Andrew Rybchenko
2019-07-24 16:57     ` Ferruh Yigit
2019-07-24 18:41       ` Andrew Rybchenko
2019-07-24 18:52         ` Ferruh Yigit
2019-07-24 13:16   ` Andrew Rybchenko [this message]
2019-07-24 13:16   ` [dpdk-dev] [PATCH v3 3/3] net/sfc: unify power of 2 alignment check macro Andrew Rybchenko
2019-07-24 18:47   ` [dpdk-dev] [PATCH v3 0/3] net/sfc: fix power of 2 alignment macros Ferruh Yigit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1563974194-5930-3-git-send-email-arybchenko@solarflare.com \
    --to=arybchenko@solarflare.com \
    --cc=dev@dpdk.org \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.