linux-staging.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Stefan Wahren <stefan.wahren@i2se.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Nicolas Saenz Julienne <nsaenz@kernel.org>
Cc: linux-staging@lists.linux.dev, Stefan Wahren <stefan.wahren@i2se.com>
Subject: [PATCH 04/16] staging: vchiq_core: get the rid of IS_POW2
Date: Thu,  3 Jun 2021 17:49:53 +0200	[thread overview]
Message-ID: <1622735405-9980-5-git-send-email-stefan.wahren@i2se.com> (raw)
In-Reply-To: <1622735405-9980-1-git-send-email-stefan.wahren@i2se.com>

The macro IS_POW2 is only used to ensure some size are powers of 2.
Better use BUILD_BUG_ON_NOT_POWER_OF_2 for this. Since this must be done
in a function, merge all these checks in a new function.

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
---
 .../vc04_services/interface/vchiq_arm/vchiq_core.c      | 17 +++++++++++++----
 .../vc04_services/interface/vchiq_arm/vchiq_core.h      |  7 -------
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
index b808f91..32016ea 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
@@ -124,12 +124,19 @@ enum {
 
 /* we require this for consistency between endpoints */
 vchiq_static_assert(sizeof(struct vchiq_header) == 8);
-vchiq_static_assert(IS_POW2(sizeof(struct vchiq_header)));
-vchiq_static_assert(IS_POW2(VCHIQ_NUM_CURRENT_BULKS));
-vchiq_static_assert(IS_POW2(VCHIQ_NUM_SERVICE_BULKS));
-vchiq_static_assert(IS_POW2(VCHIQ_MAX_SERVICES));
 vchiq_static_assert(VCHIQ_VERSION >= VCHIQ_VERSION_MIN);
 
+static inline void check_sizes(void)
+{
+	BUILD_BUG_ON_NOT_POWER_OF_2(VCHIQ_SLOT_SIZE);
+	BUILD_BUG_ON_NOT_POWER_OF_2(VCHIQ_MAX_SLOTS);
+	BUILD_BUG_ON_NOT_POWER_OF_2(VCHIQ_MAX_SLOTS_PER_SIDE);
+	BUILD_BUG_ON_NOT_POWER_OF_2(sizeof(struct vchiq_header));
+	BUILD_BUG_ON_NOT_POWER_OF_2(VCHIQ_NUM_CURRENT_BULKS);
+	BUILD_BUG_ON_NOT_POWER_OF_2(VCHIQ_NUM_SERVICE_BULKS);
+	BUILD_BUG_ON_NOT_POWER_OF_2(VCHIQ_MAX_SERVICES);
+}
+
 /* Run time control of log level, based on KERN_XXX level. */
 int vchiq_core_log_level = VCHIQ_LOG_DEFAULT;
 int vchiq_core_msg_log_level = VCHIQ_LOG_DEFAULT;
@@ -2206,6 +2213,8 @@ vchiq_init_slots(void *mem_base, int mem_size)
 	int num_slots = (mem_size - mem_align)/VCHIQ_SLOT_SIZE;
 	int first_data_slot = VCHIQ_SLOT_ZERO_SLOTS;
 
+	check_sizes();
+
 	/* Ensure there is enough memory to run an absolutely minimum system */
 	num_slots -= first_data_slot;
 
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h
index db93495..df51418 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h
@@ -69,13 +69,6 @@
 	extern int vchiq_static_assert[(cond) ? 1 : -1]
 #endif
 
-#define IS_POW2(x) (x && ((x & (x - 1)) == 0))
-
-/* Ensure that the slot size and maximum number of slots are powers of 2 */
-vchiq_static_assert(IS_POW2(VCHIQ_SLOT_SIZE));
-vchiq_static_assert(IS_POW2(VCHIQ_MAX_SLOTS));
-vchiq_static_assert(IS_POW2(VCHIQ_MAX_SLOTS_PER_SIDE));
-
 #define VCHIQ_SLOT_MASK        (VCHIQ_SLOT_SIZE - 1)
 #define VCHIQ_SLOT_QUEUE_MASK  (VCHIQ_MAX_SLOTS_PER_SIDE - 1)
 #define VCHIQ_SLOT_ZERO_SLOTS  DIV_ROUND_UP(sizeof(struct vchiq_slot_zero), \
-- 
2.7.4


  parent reply	other threads:[~2021-06-03 15:50 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-03 15:49 [PATCH 00/16] staging: vchiq_arm: code clean-up part 3 Stefan Wahren
2021-06-03 15:49 ` [PATCH 01/16] staging: vchiq_core: fix logic in poll_services_of_group Stefan Wahren
2021-06-03 15:49 ` [PATCH 02/16] staging: vchiq_arm: introduce free_bulk_waiter Stefan Wahren
2021-06-03 15:49 ` [PATCH 03/16] staging: vchiq_core: move internals to C source Stefan Wahren
2021-06-03 15:49 ` Stefan Wahren [this message]
2021-06-03 15:49 ` [PATCH 05/16] staging: vchiq_core: get the rid of vchiq_static_assert Stefan Wahren
2021-06-03 15:49 ` [PATCH 06/16] staging: vchiq_core: put spaces around operators Stefan Wahren
2021-06-03 15:49 ` [PATCH 07/16] staging: vchiq_core: avoid precedence issues Stefan Wahren
2021-06-03 15:49 ` [PATCH 08/16] staging: vchiq_core: use define for message type shift Stefan Wahren
2021-06-03 15:49 ` [PATCH 09/16] staging: vchiq_core: introduce message specific make macros Stefan Wahren
2021-06-03 15:49 ` [PATCH 10/16] staging: vchiq_core: simplify WARN_ON conditions Stefan Wahren
2021-06-03 15:50 ` [PATCH 11/16] staging: vchiq_arm: tidy up service function naming Stefan Wahren
2021-06-03 15:50 ` [PATCH 12/16] staging: vchiq_core: introduce process_free_data_message Stefan Wahren
2021-06-03 15:50 ` [PATCH 13/16] staging: vchiq_core: reduce indentation in parse_open Stefan Wahren
2021-06-03 15:50 ` [PATCH 14/16] staging: vchiq_core: store message id in local variable Stefan Wahren
2021-06-03 15:50 ` [PATCH 15/16] staging: vchiq_connected: move EXPORT_SYMBOL below the right function Stefan Wahren
2021-06-03 15:50 ` [PATCH 16/16] staging: vchiq_core: introduce handle_poll Stefan Wahren

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=1622735405-9980-5-git-send-email-stefan.wahren@i2se.com \
    --to=stefan.wahren@i2se.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=nsaenz@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).