Skip to content

Commit 37df3c0

Browse files
committed
accel-config: Fixes for pedantic compiler warnings
Debian builds enable the -Wpedantic option that gives warnings for features that are supported by GCC but prohibited by other compilers. This project is tied to the GCC compiler and uses several GCC builti-ins. Provide fixes to warnings that are potential issues. Several benighn warnings are suppressed using GCC #pragma. Signed-off-by: Ramesh Thomas <[email protected]> Reviewed-by: Dave Jiang <[email protected]> Reviewed-by: Colin King <[email protected]>
1 parent 736c792 commit 37df3c0

File tree

11 files changed

+62
-57
lines changed

11 files changed

+62
-57
lines changed

accfg/idxd.h

+20-22
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,26 @@
99
#include <linux/ioctl.h>
1010

1111
/* Driver command error status */
12-
enum idxd_scmd_stat {
13-
IDXD_SCMD_DEV_ENABLED = 0x80000010,
14-
IDXD_SCMD_DEV_NOT_ENABLED = 0x80000020,
15-
IDXD_SCMD_WQ_ENABLED = 0x80000021,
16-
IDXD_SCMD_DEV_DMA_ERR = 0x80020000,
17-
IDXD_SCMD_WQ_NO_GRP = 0x80030000,
18-
IDXD_SCMD_WQ_NO_NAME = 0x80040000,
19-
IDXD_SCMD_WQ_NO_SVM = 0x80050000,
20-
IDXD_SCMD_WQ_NO_THRESH = 0x80060000,
21-
IDXD_SCMD_WQ_PORTAL_ERR = 0x80070000,
22-
IDXD_SCMD_WQ_RES_ALLOC_ERR = 0x80080000,
23-
IDXD_SCMD_PERCPU_ERR = 0x80090000,
24-
IDXD_SCMD_DMA_CHAN_ERR = 0x800a0000,
25-
IDXD_SCMD_CDEV_ERR = 0x800b0000,
26-
IDXD_SCMD_WQ_NO_SWQ_SUPPORT = 0x800c0000,
27-
IDXD_SCMD_WQ_NONE_CONFIGURED = 0x800d0000,
28-
IDXD_SCMD_WQ_NO_SIZE = 0x800e0000,
29-
IDXD_SCMD_WQ_NO_PRIV = 0x800f0000,
30-
IDXD_SCMD_WQ_IRQ_ERR = 0x80100000,
31-
IDXD_SCMD_WQ_NO_DRV_NAME = 0x80200000,
32-
IDXD_SCMD_DEV_EVL_ERR = 0x80300000,
33-
};
12+
#define IDXD_SCMD_DEV_ENABLED 0x80000010
13+
#define IDXD_SCMD_DEV_NOT_ENABLED 0x80000020
14+
#define IDXD_SCMD_WQ_ENABLED 0x80000021
15+
#define IDXD_SCMD_DEV_DMA_ERR 0x80020000
16+
#define IDXD_SCMD_WQ_NO_GRP 0x80030000
17+
#define IDXD_SCMD_WQ_NO_NAME 0x80040000
18+
#define IDXD_SCMD_WQ_NO_SVM 0x80050000
19+
#define IDXD_SCMD_WQ_NO_THRESH 0x80060000
20+
#define IDXD_SCMD_WQ_PORTAL_ERR 0x80070000
21+
#define IDXD_SCMD_WQ_RES_ALLOC_ERR 0x80080000
22+
#define IDXD_SCMD_PERCPU_ERR 0x80090000
23+
#define IDXD_SCMD_DMA_CHAN_ERR 0x800a0000
24+
#define IDXD_SCMD_CDEV_ERR 0x800b0000
25+
#define IDXD_SCMD_WQ_NO_SWQ_SUPPORT 0x800c0000
26+
#define IDXD_SCMD_WQ_NONE_CONFIGURED 0x800d0000
27+
#define IDXD_SCMD_WQ_NO_SIZE 0x800e0000
28+
#define IDXD_SCMD_WQ_NO_PRIV 0x800f0000
29+
#define IDXD_SCMD_WQ_IRQ_ERR 0x80100000
30+
#define IDXD_SCMD_WQ_NO_DRV_NAME 0x80200000
31+
#define IDXD_SCMD_DEV_EVL_ERR 0x80300000
3432

3533
#define IDXD_SCMD_SOFTERR_MASK 0x80000000
3634
#define IDXD_SCMD_SOFTERR_SHIFT 16

accfg/lib/libaccfg.c

+9-11
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,8 @@ static unsigned int accfg_device_compl_size[] = {
6666
[ACCFG_DEVICE_IAX] = 64,
6767
};
6868

69-
enum {
70-
ACCFG_CMD_STATUS_MAX = 0x45,
71-
ACCFG_CMD_STATUS_ERROR = 0x80010000,
72-
};
69+
#define ACCFG_CMD_STATUS_MAX 0x45
70+
#define ACCFG_CMD_STATUS_ERROR 0x80010000
7371

7472
#define SCMD_STAT(x) (((x) & ~IDXD_SCMD_SOFTERR_MASK) >> \
7573
IDXD_SCMD_SOFTERR_SHIFT)
@@ -1764,13 +1762,13 @@ ACCFG_EXPORT int accfg_group_get_##field( \
17641762
return group->field; \
17651763
}
17661764

1767-
accfg_group_get_field(group, read_buffers_reserved);
1768-
accfg_group_get_field(group, read_buffers_allowed);
1769-
accfg_group_get_field(group, use_read_buffer_limit);
1770-
accfg_group_get_field(group, traffic_class_a);
1771-
accfg_group_get_field(group, traffic_class_b);
1772-
accfg_group_get_field(group, desc_progress_limit);
1773-
accfg_group_get_field(group, batch_progress_limit);
1765+
accfg_group_get_field(group, read_buffers_reserved)
1766+
accfg_group_get_field(group, read_buffers_allowed)
1767+
accfg_group_get_field(group, use_read_buffer_limit)
1768+
accfg_group_get_field(group, traffic_class_a)
1769+
accfg_group_get_field(group, traffic_class_b)
1770+
accfg_group_get_field(group, desc_progress_limit)
1771+
accfg_group_get_field(group, batch_progress_limit)
17741772

17751773
static void wqs_init(struct accfg_device *device)
17761774
{

ccan/list/list.h

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#include <ccan/container_of/container_of.h>
99
#include <ccan/check_type/check_type.h>
1010

11+
#pragma GCC diagnostic ignored "-Wpedantic"
12+
#pragma GCC diagnostic ignored "-Wformat"
13+
1114
/**
1215
* struct list_node - an entry in a doubly-linked list
1316
* @next: next entry (self if empty)

ccan/minmax/minmax.h

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "config.h"
66

7+
#pragma GCC diagnostic ignored "-Wpedantic"
8+
79
#include <ccan/build_assert/build_assert.h>
810

911
#if !HAVE_STATEMENT_EXPR || !HAVE_TYPEOF

test/accel_test.h

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <accfg/idxd.h>
77
#include "accfg_test.h"
88

9+
#pragma GCC diagnostic ignored "-Wpedantic"
10+
911
#define SHARED 1
1012
#define DEDICATED 0
1113

test/dsa.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ int init_crcgen(struct task *tsk, int tflags, int opcode, unsigned long xfer_siz
223223
memset_pattern(tsk->src1, tsk->pattern, xfer_size);
224224
tsk->crc_seed = 0x12345678;
225225
if (tsk->test_flags & (unsigned int)(READ_CRC_SEED)) {
226-
tsk->crc_seed_addr = aligned_alloc(ADDR_ALIGNMENT, sizeof(tsk->crc_seed));
226+
tsk->crc_seed_addr = aligned_alloc(ADDR_ALIGNMENT, sizeof(*tsk->crc_seed_addr));
227227
*tsk->crc_seed_addr = tsk->crc_seed;
228228
tsk->crc_seed = 0x0;
229229
}
@@ -253,7 +253,7 @@ int init_copy_crc(struct task *tsk, int tflags, int opcode, unsigned long xfer_s
253253

254254
tsk->crc_seed = 0x12345678;
255255
if (tsk->test_flags & (unsigned int)(READ_CRC_SEED)) {
256-
tsk->crc_seed_addr = aligned_alloc(ADDR_ALIGNMENT, sizeof(tsk->crc_seed));
256+
tsk->crc_seed_addr = aligned_alloc(ADDR_ALIGNMENT, sizeof(*tsk->crc_seed_addr));
257257
*tsk->crc_seed_addr = tsk->crc_seed;
258258
tsk->crc_seed = 0x0;
259259
}

test/dsa_test.c

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "dsa.h"
1414

1515
#define DSA_TEST_SIZE 20000
16+
#pragma GCC diagnostic ignored "-Wformat"
1617

1718
static void usage(void)
1819
{

test/iaa_test.c

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "iaa.h"
1010

1111
#define IAA_TEST_SIZE 20000
12+
#pragma GCC diagnostic ignored "-Wformat"
1213

1314
static void usage(void)
1415
{

util/log.h

+15-15
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,32 @@ void log_init(struct log_ctx *ctx, const char *owner, const char *log_env);
2525
static inline void __attribute__((always_inline, format(printf, 2, 3)))
2626
log_null(struct log_ctx *ctx, const char *format, ...) {}
2727

28-
#define log_cond(ctx, prio, arg...) \
28+
#define log_cond(ctx, prio, ...) \
2929
do { \
3030
if ((ctx)->log_priority >= prio) \
31-
do_log(ctx, prio, __FILE__, __LINE__, __FUNCTION__, ## arg); \
31+
do_log(ctx, prio, __FILE__, __LINE__, __func__, __VA_ARGS__); \
3232
} while (0)
3333

3434
#ifdef ENABLE_LOGGING
3535
# ifdef ENABLE_DEBUG
36-
# define log_dbg(ctx, arg...) log_cond(ctx, LOG_DEBUG, ## arg)
36+
# define log_dbg(ctx, ...) log_cond(ctx, LOG_DEBUG, __VA_ARGS__)
3737
# else
38-
# define log_dbg(ctx, arg...) log_null(ctx, ## arg)
38+
# define log_dbg(ctx, ...) log_null(ctx, __VA_ARGS__)
3939
# endif
40-
# define log_info(ctx, arg...) log_cond(ctx, LOG_INFO, ## arg)
41-
# define log_err(ctx, arg...) log_cond(ctx, LOG_ERR, ## arg)
42-
# define log_notice(ctx, arg...) log_cond(ctx, LOG_NOTICE, ## arg)
40+
# define log_info(ctx, ...) log_cond(ctx, LOG_INFO, __VA_ARGS__)
41+
# define log_err(ctx, ...) log_cond(ctx, LOG_ERR, __VA_ARGS__)
42+
# define log_notice(ctx, ...) log_cond(ctx, LOG_NOTICE, __VA_ARGS__)
4343
#else
44-
# define log_dbg(ctx, arg...) log_null(ctx, ## arg)
45-
# define log_info(ctx, arg...) log_null(ctx, ## arg)
46-
# define log_err(ctx, arg...) log_null(ctx, ## arg)
47-
# define log_notice(ctx, arg...) log_null(ctx, ## arg)
44+
# define log_dbg(ctx, ...) log_null(ctx, __VA_ARGS__)
45+
# define log_info(ctx, ...) log_null(ctx, __VA_ARGS__)
46+
# define log_err(ctx, ...) log_null(ctx, __VA_ARGS__)
47+
# define log_notice(ctx, ...) log_null(ctx, __VA_ARGS__)
4848
#endif
4949

50-
#define dbg(x, arg...) log_dbg(&(x)->ctx, ## arg)
51-
#define info(x, arg...) log_info(&(x)->ctx, ## arg)
52-
#define err(x, arg...) log_err(&(x)->ctx, ## arg)
53-
#define notice(x, arg...) log_notice(&(x)->ctx, ## arg)
50+
#define dbg(x, ...) log_dbg(&(x)->ctx, __VA_ARGS__)
51+
#define info(x, ...) log_info(&(x)->ctx, __VA_ARGS__)
52+
#define err(x, ...) log_err(&(x)->ctx, __VA_ARGS__)
53+
#define notice(x, ...) log_notice(&(x)->ctx, __VA_ARGS__)
5454

5555
#ifndef HAVE_SECURE_GETENV
5656
# ifdef HAVE___SECURE_GETENV

util/util.h

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <string.h>
2222

2323
#pragma GCC diagnostic ignored "-Wmissing-prototypes"
24+
#pragma GCC diagnostic ignored "-Wpedantic"
2425

2526
#ifdef __GNUC__
2627
#define NORETURN __attribute__((__noreturn__))

util/wrapper.c

+6-7
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,13 @@ char *xstrdup(const char *str)
3636
void *xrealloc(void *ptr, size_t size)
3737
{
3838
void *ret = realloc(ptr, size);
39-
if (!ret && !size)
40-
ret = realloc(ptr, 1);
39+
4140
if (!ret) {
42-
ret = realloc(ptr, size);
43-
if (!ret && !size)
44-
ret = realloc(ptr, 1);
45-
if (!ret)
46-
die("Out of memory, realloc failed");
41+
/* realloc() would free ptr if size == 0 */
42+
if (size)
43+
free(ptr);
44+
45+
die("Out of memory, realloc failed");
4746
}
4847
return ret;
4948
}

0 commit comments

Comments
 (0)