Skip to content

Commit

Permalink
common/sfc_efx/base: use C11 static assert
Browse files Browse the repository at this point in the history
[ upstream commit 047d7032b76a226f2f1c36775688950933f9121b ]

The sfc base code had its own definition of static assertions
using the out of bound array access hack. Replace it with a
static_assert like rte_common.h.

The use of null pointer to compute offset is not always a constant
in older versions of clang. Use standard offsetof() instead.

Fixes: f67e471 ("net/sfc/base: fix coding style")

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Reviewed-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
  • Loading branch information
shemminger authored and bluca committed Mar 7, 2024
1 parent 706c98e commit f90918d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions drivers/common/sfc_efx/base/efx.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#ifndef _SYS_EFX_H
#define _SYS_EFX_H

#include <assert.h>

#include "efx_annote.h"
#include "efsys.h"
#include "efx_types.h"
Expand All @@ -17,14 +19,20 @@
extern "C" {
#endif

#define EFX_STATIC_ASSERT(_cond) \
((void)sizeof (char[(_cond) ? 1 : -1]))
/*
* Triggers an error at compilation time if the condition is false.
*
* The { } exists to workaround a bug in clang (#55821)
* where it would not handle _Static_assert in a switch case.
*/
#define EFX_STATIC_ASSERT(_cond) \
{ static_assert((_cond), #_cond); }

#define EFX_ARRAY_SIZE(_array) \
(sizeof (_array) / sizeof ((_array)[0]))

#define EFX_FIELD_OFFSET(_type, _field) \
((size_t)&(((_type *)0)->_field))
offsetof(_type, _field)

/* The macro expands divider twice */
#define EFX_DIV_ROUND_UP(_n, _d) (((_n) + (_d) - 1) / (_d))
Expand Down

0 comments on commit f90918d

Please sign in to comment.