Skip to content

Commit

Permalink
kernel: mem_slab: only define slab_ptr_is_good with assert enabled
Browse files Browse the repository at this point in the history
Add a __ASSERT_ON guard around slab_ptr_is_good, as that is only used in
assertions and leaving it on seems to generate a build warning with some
clang versions:

kernel/mem_slab.c:207:20: error: unused function 'slab_ptr_is_good'
  207 | static inline bool slab_ptr_is_good(struct k_mem_slab *slab,...
      |                    ^~~~~~~~~~~~~~~~

(cherry picked from commit 3283659)

Original-Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
GitOrigin-RevId: 3283659
Change-Id: If196dd35272db76466cece7c44139e4c1ec98dc1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5616301
Tested-by: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
Commit-Queue: Fabio Baltieri <fabiobaltieri@google.com>
Reviewed-by: Fabio Baltieri <fabiobaltieri@google.com>
  • Loading branch information
fabiobaltieri authored and Chromeos LUCI committed Jun 10, 2024
1 parent 16001b8 commit faed25a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion kernel/mem_slab.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ int k_mem_slab_init(struct k_mem_slab *slab, void *buffer,
return rc;
}

static inline bool slab_ptr_is_good(struct k_mem_slab *slab, const void *ptr)
#if __ASSERT_ON
static bool slab_ptr_is_good(struct k_mem_slab *slab, const void *ptr)
{
const char *p = ptr;
ptrdiff_t offset = p - slab->buffer;
Expand All @@ -213,6 +214,7 @@ static inline bool slab_ptr_is_good(struct k_mem_slab *slab, const void *ptr)
(offset < (slab->info.block_size * slab->info.num_blocks)) &&
((offset % slab->info.block_size) == 0);
}
#endif

int k_mem_slab_alloc(struct k_mem_slab *slab, void **mem, k_timeout_t timeout)
{
Expand Down

0 comments on commit faed25a

Please sign in to comment.