Skip to content

Commit

Permalink
chore: update and run clang
Browse files Browse the repository at this point in the history
Signed-off-by: Maryam Tahhan <[email protected]>
  • Loading branch information
maryamtahhan committed Nov 25, 2024
1 parent c75b1ff commit e5bedf5
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 97 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: DoozyX/[email protected]
- uses: DoozyX/[email protected].2
with:
source: '.'
exclude: 'examples/vpp-plugin'
extensions: 'h,cpp,c,cc'
clangFormatVersion: 17
clangFormatVersion: 18.1.8
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repos:
hooks:
- id: yamllint
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.4
rev: v18.1.8
hooks:
- id: clang-format
types_or: [c++, c]
Expand Down
6 changes: 2 additions & 4 deletions lib/cnet/netlink/netlink_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
extern "C" {
#endif

#define DUMP_PARAMS_INIT(info, dump) \
{ \
.dp_type = dump, .dp_fd = stdout, .dp_dump_msgtype = 1, .dp_data = info \
}
#define DUMP_PARAMS_INIT(info, dump) \
{.dp_type = dump, .dp_fd = stdout, .dp_dump_msgtype = 1, .dp_data = info}

#define NL_DEBUG(...) \
do { \
Expand Down
18 changes: 5 additions & 13 deletions lib/cnet/tcp/cnet_tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,9 @@ typedef enum {
TCPS_TIME_WAIT /**< Connection is in time wait state */
} tcb_state_t;

#define TCP_INPUT_STATES \
{ \
"Free", "Closed", "Listen", "SYN Sent", "SYN Rcvd", "Established", "CloseWait", "Fin1", \
"Closing", "LastAck", "Fin2", "TimeWait", "DeleteTCB" \
}
#define TCP_INPUT_STATES \
{"Free", "Closed", "Listen", "SYN Sent", "SYN Rcvd", "Established", "CloseWait", \
"Fin1", "Closing", "LastAck", "Fin2", "TimeWait", "DeleteTCB"}

#define TCPS_HAVE_RCVD_SYN(s) ((s) >= TCPS_SYN_RCVD)
#define TCPS_HAVE_ESTABLISHED (s)((s) >= TCPS_ESTABLISHED)
Expand All @@ -163,10 +161,7 @@ enum {
};

/* Keep in bit order with above enums */
#define TCP_FLAGS \
{ \
"FIN", "SYN", "RST", "PSH", "ACK", "URG" \
}
#define TCP_FLAGS {"FIN", "SYN", "RST", "PSH", "ACK", "URG"}

// clang-format off
/* State of the flags for all possible states in TCP */
Expand All @@ -190,10 +185,7 @@ enum {
/* TCP Output Events to drive the output Finite State Machine. */
enum { SEND_EVENT, PERSIST_EVENT, RETRANSMIT_EVENT, DELETE_EVENT };

#define TCP_OUTPUT_EVENTS \
{ \
"Send", "Persist", "Rexmit", "Delete" \
}
#define TCP_OUTPUT_EVENTS {"Send", "Persist", "Rexmit", "Delete"}

/* TCP Option values */
enum {
Expand Down
2 changes: 1 addition & 1 deletion lib/core/hash/cne_hash_crc.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ static const uint32_t crc32c_tables[8][256] = {{
// clang-format on

#define CRC32_UPD(crc, n) \
(crc32c_tables[(n)][(crc) & 0xFF] ^ crc32c_tables[(n)-1][((crc) >> 8) & 0xFF])
(crc32c_tables[(n)][(crc) & 0xFF] ^ crc32c_tables[(n) - 1][((crc) >> 8) & 0xFF])

static inline uint32_t
crc32c_1byte(uint8_t data, uint32_t init_val)
Expand Down
2 changes: 1 addition & 1 deletion lib/core/ring/cne_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "ring_private.h" // for cne_ring, cne_ring_headtail, CNE_...

/* true if x is a power of 2 */
#define POWEROF2(x) ((((x)-1) & (x)) == 0)
#define POWEROF2(x) ((((x) - 1) & (x)) == 0)
#define RING_DFLT_ELEM_SZ sizeof(void *) /** The default ring element size*/

ssize_t
Expand Down
20 changes: 11 additions & 9 deletions lib/include/cne_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ typedef uint16_t unaligned_uint16_t;
*/
#define CNE_SET_USED(x) (void)(x)

#define cne_roundup(_x, _y) ((((_x) + ((_y)-1)) / (_y)) * (_y))
#define cne_roundup(_x, _y) ((((_x) + ((_y) - 1)) / (_y)) * (_y))
#define cne_ctz(_v) __builtin_ctz(_v)
#define cne_prefixbits(_v) ((__typeof__(_v))(sizeof(_v) * 8) - cne_ctz(_v))
#define cne_numbytes(_v) ((cne_prefixbits(_v) + 7) / 8)
Expand Down Expand Up @@ -269,7 +269,7 @@ typedef uint16_t unaligned_uint16_t;
* bigger than the first parameter. Second parameter must be a
* power-of-two value.
*/
#define CNE_ALIGN_FLOOR(val, align) (typeof(val))((val) & (~((typeof(val))((align)-1))))
#define CNE_ALIGN_FLOOR(val, align) (typeof(val))((val) & (~((typeof(val))((align) - 1))))

/**
* Macro to align a pointer to a given power-of-two. The resultant
Expand All @@ -278,15 +278,15 @@ typedef uint16_t unaligned_uint16_t;
* must be a power-of-two value.
*/
#define CNE_PTR_ALIGN_CEIL(ptr, align) \
CNE_PTR_ALIGN_FLOOR((typeof(ptr))CNE_PTR_ADD(ptr, (align)-1), align)
CNE_PTR_ALIGN_FLOOR((typeof(ptr))CNE_PTR_ADD(ptr, (align) - 1), align)

/**
* Macro to align a value to a given power-of-two. The resultant value
* will be of the same type as the first parameter, and will be no lower
* than the first parameter. Second parameter must be a power-of-two
* value.
*/
#define CNE_ALIGN_CEIL(val, align) CNE_ALIGN_FLOOR(((val) + ((typeof(val))(align)-1)), align)
#define CNE_ALIGN_CEIL(val, align) CNE_ALIGN_FLOOR(((val) + ((typeof(val))(align) - 1)), align)

/**
* Macro to align a pointer to a given power-of-two. The resultant
Expand All @@ -312,7 +312,7 @@ typedef uint16_t unaligned_uint16_t;
* than the first parameter.
*/
#define CNE_ALIGN_MUL_CEIL(v, mul) \
(((v + (typeof(v))(mul)-1) / ((typeof(v))(mul))) * (typeof(v))(mul))
(((v + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))

/**
* Macro to align a value to the multiple of given value. The resultant
Expand Down Expand Up @@ -397,7 +397,7 @@ __extension__ typedef uint64_t CNE_MARKER64[0];

/** Physical address */
typedef uint64_t phys_addr_t;
#define CNE_BAD_PHYS_ADDR ((phys_addr_t)-1)
#define CNE_BAD_PHYS_ADDR ((phys_addr_t) - 1)

/**
* IO virtual address type.
Expand All @@ -407,7 +407,7 @@ typedef uint64_t phys_addr_t;
* Otherwise, in virtual mode (IOVA as VA), an IOMMU may do the translation.
*/
typedef uint64_t cne_iova_t;
#define CNE_BAD_IOVA ((cne_iova_t)-1)
#define CNE_BAD_IOVA ((cne_iova_t) - 1)

/**
* Combines 32b inputs most significant set bits into the least
Expand Down Expand Up @@ -459,7 +459,7 @@ cne_combine64ms1b(uint64_t v)
/**
* Macro to return 1 if n is a power of 2, 0 otherwise
*/
#define CNE_IS_POWER_OF_2(n) ((n) && !(((n)-1) & (n)))
#define CNE_IS_POWER_OF_2(n) ((n) && !(((n) - 1) & (n)))

/**
* Returns true if n is a power of 2
Expand Down Expand Up @@ -773,7 +773,9 @@ cne_log2_u64(uint64_t v)
#define CNE_FMT_TAIL(fmt, ...) __VA_ARGS__

/** Mask value of type "tp" for the first "ln" bit set. */
#define CNE_LEN2MASK(ln, tp) ((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln))))
// clang-format off
#define CNE_LEN2MASK(ln, tp) ((tp)((uint64_t) - 1 >> (sizeof(uint64_t) * CHAR_BIT - (ln))))
// clang-format on

/** Number of elements in the array. */
#define CNE_DIM(a) (int)(sizeof(a) / sizeof((a)[0]))
Expand Down
5 changes: 1 addition & 4 deletions lib/include/cne_rwlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ typedef struct __cne_lockable {
/**
* A static rwlock initializer.
*/
#define CNE_RWLOCK_INITIALIZER \
{ \
0 \
}
#define CNE_RWLOCK_INITIALIZER {0}

/**
* Initialize the rwlock to an unlocked state.
Expand Down
10 changes: 2 additions & 8 deletions lib/include/cne_spinlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ typedef struct {
/**
* A static spinlock initializer.
*/
#define CNE_SPINLOCK_INITIALIZER \
{ \
0 \
}
#define CNE_SPINLOCK_INITIALIZER {0}

/**
* Initialize the spinlock to an unlocked state.
Expand Down Expand Up @@ -189,10 +186,7 @@ typedef struct {
/**
* A static recursive spinlock initializer.
*/
#define CNE_SPINLOCK_RECURSIVE_INITIALIZER \
{ \
CNE_SPINLOCK_INITIALIZER, -1, 0 \
}
#define CNE_SPINLOCK_RECURSIVE_INITIALIZER {CNE_SPINLOCK_INITIALIZER, -1, 0}

/**
* Initialize the recursive spinlock to an unlocked state.
Expand Down
13 changes: 5 additions & 8 deletions lib/usr/app/cli/cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ typedef enum {
} node_type_t;

/* Keep this list in sync with the node_type_t enum above */
#define CLI_NODE_TYPES \
{ \
"Unknown", "Directory", "Command", "File", "Alias", "String", NULL \
}
#define CLI_NODE_TYPES {"Unknown", "Directory", "Command", "File", "Alias", "String", NULL}

enum {
CLI_EXE_TYPE = (CLI_CMD_NODE | CLI_ALIAS_NODE),
Expand Down Expand Up @@ -203,25 +200,25 @@ struct cli_cmd {
const char *name; /**< Name of command */
cli_cfunc_t cfunc; /**< Function pointer */
const char *short_desc; /**< Short description */
}; /**< List of commands for cli_add_cmds() */
}; /**< List of commands for cli_add_cmds() */

struct cli_alias {
const char *name; /**< Name of command */
const char *alias_atr; /**< Alias string */
const char *short_desc; /**< Short description */
}; /**< List of alias for cli_add_aliases() */
}; /**< List of alias for cli_add_aliases() */

struct cli_file {
const char *name; /**< Name of command */
cli_ffunc_t ffunc; /**< Read/Write function pointer */
const char *short_desc; /**< Short description */
}; /**< List of alias for cli_add_aliases() */
}; /**< List of alias for cli_add_aliases() */

struct cli_str {
const char *name; /**< Name of command */
cli_sfunc_t sfunc; /**< Function pointer */
const char *string; /**< Default string */
}; /**< List of commands for cli_add_str() */
}; /**< List of commands for cli_add_str() */

struct cli_tree {
node_type_t type; /**< type of node to create */
Expand Down
8 changes: 4 additions & 4 deletions lib/usr/app/jcfg/jcfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ struct json_object;
*
* @note: make sure this matches the jcfg_cb_type_t enum order.
*/
#define JCFG_TAG_NAMES \
{ \
APP_TAG, DEFAULT_TAG, OPTION_TAG, UMEM_TAG, LPORT_TAG, LGROUP_TAG, THREAD_TAG, \
LPORT_GROUP_TAG, USER_TAG, \
#define JCFG_TAG_NAMES \
{ \
APP_TAG, DEFAULT_TAG, OPTION_TAG, UMEM_TAG, LPORT_TAG, \
LGROUP_TAG, THREAD_TAG, LPORT_GROUP_TAG, USER_TAG, \
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/usr/clib/acl/cne_acl.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ enum {
};

#define CNE_ACL_MASKLEN_TO_BITMASK(v, s) \
((v) == 0 ? (v) : (typeof(v))((uint64_t)-1 << ((s) * CHAR_BIT - (v))))
((v) == 0 ? (v) : (typeof(v))((uint64_t) - 1 << ((s) * CHAR_BIT - (v))))

/**
* Miscellaneous data for ACL rule.
Expand Down
8 changes: 5 additions & 3 deletions lib/usr/clib/cthread/cthread_cond.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ struct cthread_cond {
char name[MAX_COND_NAME_SIZE]; /**< Name of the condition variable */
} __cne_cache_aligned;

#define CTHREAD_COND_INIT(name) \
{ \
.name = #name, .blocked = NULL, .sched = NULL, \
#define CTHREAD_COND_INIT(name) \
{ \
.name = #name, \
.blocked = NULL, \
.sched = NULL, \
}

#ifdef __cplusplus
Expand Down
12 changes: 8 additions & 4 deletions lib/usr/clib/cthread/cthread_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ _qnode_pool_insert(struct qnode_pool *p, struct qnode *n)
* @return
* NULL on error or qnode pointer
*/
static inline struct qnode *__attribute__((always_inline)) _pool_remove(struct qnode_pool *p)
static inline struct qnode *__attribute__((always_inline))
_pool_remove(struct qnode_pool *p)
{
struct qnode *head;
struct qnode *tail = p->tail;
Expand Down Expand Up @@ -212,7 +213,8 @@ static inline struct qnode *__attribute__((always_inline)) _pool_remove(struct q
* @return
* The qnode removed from queue or NULL on error
*/
static inline struct qnode *__attribute__((always_inline)) _qnode_pool_remove(struct qnode_pool *p)
static inline struct qnode *__attribute__((always_inline))
_qnode_pool_remove(struct qnode_pool *p)
{
struct qnode *n;

Expand All @@ -230,7 +232,8 @@ static inline struct qnode *__attribute__((always_inline)) _qnode_pool_remove(st
* Allocate a node from the pool
* If the pool is empty add mode nodes
*/
static inline struct qnode *__attribute__((always_inline)) _qnode_alloc(void)
static inline struct qnode *__attribute__((always_inline))
_qnode_alloc(void)
{
struct qnode_pool *p = (THIS_SCHED)->qnode_pool;
int prealloc_size = p->pre_alloc;
Expand Down Expand Up @@ -263,7 +266,8 @@ static inline struct qnode *__attribute__((always_inline)) _qnode_alloc(void)
/*
* free a queue node to the per scheduler pool from which it came
*/
static inline void __attribute__((always_inline)) _qnode_free(struct qnode *n)
static inline void __attribute__((always_inline))
_qnode_free(struct qnode *n)
{
struct qnode_pool *p = n->pool;

Expand Down
9 changes: 6 additions & 3 deletions lib/usr/clib/cthread/cthread_sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,16 @@ _sched_now(void)
return 1;
}

static inline void __attribute__((always_inline)) _affinitize(void)
static inline void __attribute__((always_inline))
_affinitize(void)
{
struct cthread *ct = THIS_CTHREAD;

cthread_switch(&(THIS_SCHED)->ctx, &ct->ctx);
}

static inline void __attribute__((always_inline)) _suspend(void)
static inline void __attribute__((always_inline))
_suspend(void)
{
struct cthread *ct = THIS_CTHREAD;

Expand All @@ -117,7 +119,8 @@ static inline void __attribute__((always_inline)) _suspend(void)
(THIS_SCHED)->nb_blocked_threads--;
}

static inline void __attribute__((always_inline)) _reschedule(void)
static inline void __attribute__((always_inline))
_reschedule(void)
{
struct cthread *ct = THIS_CTHREAD;

Expand Down
4 changes: 2 additions & 2 deletions lib/usr/clib/utils/crc32.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
extern const uint32_t crc32_tab[];

#define rounddown(x, y) (((x) / (y)) * (y))
#define rounddown2(x, y) ((x) & (~((y)-1))) /* if y is power of two */
#define roundup2(x, y) (((x) + ((y)-1)) & (~((y)-1))) /* if y is power of two */
#define rounddown2(x, y) ((x) & (~((y) - 1))) /* if y is power of two */
#define roundup2(x, y) (((x) + ((y) - 1)) & (~((y) - 1))) /* if y is power of two */

static __inline uint32_t
crc32_raw(const void *buf, size_t size, uint32_t crc)
Expand Down
Loading

0 comments on commit e5bedf5

Please sign in to comment.