Return-Path: Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 13CD1C0032 for ; Fri, 25 Aug 2023 01:41:10 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id DAB1460BBA for ; Fri, 25 Aug 2023 01:41:09 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org DAB1460BBA Authentication-Results: smtp3.osuosl.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=doMwr7Fp X-Virus-Scanned: amavisd-new at osuosl.org X-Spam-Flag: NO X-Spam-Score: -2.1 X-Spam-Level: X-Spam-Status: No, score=-2.1 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Vg7UHcx6HCKq for ; Fri, 25 Aug 2023 01:41:04 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by smtp3.osuosl.org (Postfix) with ESMTPS id 5EEE360BA1 for ; Fri, 25 Aug 2023 01:41:04 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 5EEE360BA1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692927664; x=1724463664; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=hs2bmGg3jrquEIFS0FjjHf4fDJVXEBC3ZlmdGEItzHc=; b=doMwr7FpeF+X47jFFOUAB7kpKq1GLbBCZq9wlSt06bHrdB/sOj7EGBjC FNKadAuuL4l0tamxAOf7UTaYdeXr6iHiPlgsaRf6HKC2BhLjlne/uJowD BQ0V1VSKTLXbRTPIhBgyl0gmQBxK6Bt7sITG8RyrC2JgYuxL4on7z8gz7 O7QH0ps83BIcLlbZed36WRrfL43W6SeeqhtDmRWLvk4SfRgH7c4FDriVM RRqrJ1eChcJBKah+N/YSaLx59ZZEKlNSZUaO+0cz5tW+GNkYcS05SXb0D 9u+hh/ommOLn+U+60jV8MFjr+TkNISgzJDRBGGjtwX7QiTIQmQVAd4jxr Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10812"; a="359602940" X-IronPort-AV: E=Sophos;i="6.02,195,1688454000"; d="scan'208";a="359602940" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Aug 2023 18:40:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10812"; a="1068058156" X-IronPort-AV: E=Sophos;i="6.02,195,1688454000"; d="scan'208";a="1068058156" Received: from rthomas.sc.intel.com ([172.25.112.51]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Aug 2023 18:40:45 -0700 From: Ramesh Thomas To: accel-config@lists.linuxfoundation.org Date: Thu, 24 Aug 2023 18:37:49 -0700 Message-Id: <20230825013749.2389791-1-ramesh.thomas@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Accel-config] [PATCH v2] accel-config: Fixes for pedantic compiler warnings X-BeenThere: accel-config@lists.linuxfoundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: accel-config List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Aug 2023 01:41:10 -0000 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 --- v2: Fixed xrealloc() to call die() if realloc fails, without retrying with size==1 accfg/idxd.h | 42 ++++++++++++++++++++---------------------- accfg/lib/libaccfg.c | 20 +++++++++----------- ccan/list/list.h | 3 +++ ccan/minmax/minmax.h | 2 ++ test/accel_test.h | 2 ++ test/dsa.c | 4 ++-- test/dsa_test.c | 1 + test/iaa_test.c | 1 + util/log.h | 30 +++++++++++++++--------------- util/util.h | 1 + util/wrapper.c | 13 ++++++------- 11 files changed, 62 insertions(+), 57 deletions(-) diff --git a/accfg/idxd.h b/accfg/idxd.h index 19d5435..f8b0c9a 100644 --- a/accfg/idxd.h +++ b/accfg/idxd.h @@ -9,28 +9,26 @@ #include /* Driver command error status */ -enum idxd_scmd_stat { - IDXD_SCMD_DEV_ENABLED = 0x80000010, - IDXD_SCMD_DEV_NOT_ENABLED = 0x80000020, - IDXD_SCMD_WQ_ENABLED = 0x80000021, - IDXD_SCMD_DEV_DMA_ERR = 0x80020000, - IDXD_SCMD_WQ_NO_GRP = 0x80030000, - IDXD_SCMD_WQ_NO_NAME = 0x80040000, - IDXD_SCMD_WQ_NO_SVM = 0x80050000, - IDXD_SCMD_WQ_NO_THRESH = 0x80060000, - IDXD_SCMD_WQ_PORTAL_ERR = 0x80070000, - IDXD_SCMD_WQ_RES_ALLOC_ERR = 0x80080000, - IDXD_SCMD_PERCPU_ERR = 0x80090000, - IDXD_SCMD_DMA_CHAN_ERR = 0x800a0000, - IDXD_SCMD_CDEV_ERR = 0x800b0000, - IDXD_SCMD_WQ_NO_SWQ_SUPPORT = 0x800c0000, - IDXD_SCMD_WQ_NONE_CONFIGURED = 0x800d0000, - IDXD_SCMD_WQ_NO_SIZE = 0x800e0000, - IDXD_SCMD_WQ_NO_PRIV = 0x800f0000, - IDXD_SCMD_WQ_IRQ_ERR = 0x80100000, - IDXD_SCMD_WQ_NO_DRV_NAME = 0x80200000, - IDXD_SCMD_DEV_EVL_ERR = 0x80300000, -}; +#define IDXD_SCMD_DEV_ENABLED 0x80000010 +#define IDXD_SCMD_DEV_NOT_ENABLED 0x80000020 +#define IDXD_SCMD_WQ_ENABLED 0x80000021 +#define IDXD_SCMD_DEV_DMA_ERR 0x80020000 +#define IDXD_SCMD_WQ_NO_GRP 0x80030000 +#define IDXD_SCMD_WQ_NO_NAME 0x80040000 +#define IDXD_SCMD_WQ_NO_SVM 0x80050000 +#define IDXD_SCMD_WQ_NO_THRESH 0x80060000 +#define IDXD_SCMD_WQ_PORTAL_ERR 0x80070000 +#define IDXD_SCMD_WQ_RES_ALLOC_ERR 0x80080000 +#define IDXD_SCMD_PERCPU_ERR 0x80090000 +#define IDXD_SCMD_DMA_CHAN_ERR 0x800a0000 +#define IDXD_SCMD_CDEV_ERR 0x800b0000 +#define IDXD_SCMD_WQ_NO_SWQ_SUPPORT 0x800c0000 +#define IDXD_SCMD_WQ_NONE_CONFIGURED 0x800d0000 +#define IDXD_SCMD_WQ_NO_SIZE 0x800e0000 +#define IDXD_SCMD_WQ_NO_PRIV 0x800f0000 +#define IDXD_SCMD_WQ_IRQ_ERR 0x80100000 +#define IDXD_SCMD_WQ_NO_DRV_NAME 0x80200000 +#define IDXD_SCMD_DEV_EVL_ERR 0x80300000 #define IDXD_SCMD_SOFTERR_MASK 0x80000000 #define IDXD_SCMD_SOFTERR_SHIFT 16 diff --git a/accfg/lib/libaccfg.c b/accfg/lib/libaccfg.c index 292ce45..82e524f 100644 --- a/accfg/lib/libaccfg.c +++ b/accfg/lib/libaccfg.c @@ -66,10 +66,8 @@ static unsigned int accfg_device_compl_size[] = { [ACCFG_DEVICE_IAX] = 64, }; -enum { - ACCFG_CMD_STATUS_MAX = 0x45, - ACCFG_CMD_STATUS_ERROR = 0x80010000, -}; +#define ACCFG_CMD_STATUS_MAX 0x45 +#define ACCFG_CMD_STATUS_ERROR 0x80010000 #define SCMD_STAT(x) (((x) & ~IDXD_SCMD_SOFTERR_MASK) >> \ IDXD_SCMD_SOFTERR_SHIFT) @@ -1764,13 +1762,13 @@ ACCFG_EXPORT int accfg_group_get_##field( \ return group->field; \ } -accfg_group_get_field(group, read_buffers_reserved); -accfg_group_get_field(group, read_buffers_allowed); -accfg_group_get_field(group, use_read_buffer_limit); -accfg_group_get_field(group, traffic_class_a); -accfg_group_get_field(group, traffic_class_b); -accfg_group_get_field(group, desc_progress_limit); -accfg_group_get_field(group, batch_progress_limit); +accfg_group_get_field(group, read_buffers_reserved) +accfg_group_get_field(group, read_buffers_allowed) +accfg_group_get_field(group, use_read_buffer_limit) +accfg_group_get_field(group, traffic_class_a) +accfg_group_get_field(group, traffic_class_b) +accfg_group_get_field(group, desc_progress_limit) +accfg_group_get_field(group, batch_progress_limit) static void wqs_init(struct accfg_device *device) { diff --git a/ccan/list/list.h b/ccan/list/list.h index 68e3dea..6080e0b 100644 --- a/ccan/list/list.h +++ b/ccan/list/list.h @@ -8,6 +8,9 @@ #include #include +#pragma GCC diagnostic ignored "-Wpedantic" +#pragma GCC diagnostic ignored "-Wformat" + /** * struct list_node - an entry in a doubly-linked list * @next: next entry (self if empty) diff --git a/ccan/minmax/minmax.h b/ccan/minmax/minmax.h index 54f246c..c57b736 100644 --- a/ccan/minmax/minmax.h +++ b/ccan/minmax/minmax.h @@ -4,6 +4,8 @@ #include "config.h" +#pragma GCC diagnostic ignored "-Wpedantic" + #include #if !HAVE_STATEMENT_EXPR || !HAVE_TYPEOF diff --git a/test/accel_test.h b/test/accel_test.h index 3b41a78..6aabfde 100644 --- a/test/accel_test.h +++ b/test/accel_test.h @@ -6,6 +6,8 @@ #include #include "accfg_test.h" +#pragma GCC diagnostic ignored "-Wpedantic" + #define SHARED 1 #define DEDICATED 0 diff --git a/test/dsa.c b/test/dsa.c index 54000a8..5638147 100644 --- a/test/dsa.c +++ b/test/dsa.c @@ -223,7 +223,7 @@ int init_crcgen(struct task *tsk, int tflags, int opcode, unsigned long xfer_siz memset_pattern(tsk->src1, tsk->pattern, xfer_size); tsk->crc_seed = 0x12345678; if (tsk->test_flags & (unsigned int)(READ_CRC_SEED)) { - tsk->crc_seed_addr = aligned_alloc(ADDR_ALIGNMENT, sizeof(tsk->crc_seed)); + tsk->crc_seed_addr = aligned_alloc(ADDR_ALIGNMENT, sizeof(*tsk->crc_seed_addr)); *tsk->crc_seed_addr = tsk->crc_seed; tsk->crc_seed = 0x0; } @@ -253,7 +253,7 @@ int init_copy_crc(struct task *tsk, int tflags, int opcode, unsigned long xfer_s tsk->crc_seed = 0x12345678; if (tsk->test_flags & (unsigned int)(READ_CRC_SEED)) { - tsk->crc_seed_addr = aligned_alloc(ADDR_ALIGNMENT, sizeof(tsk->crc_seed)); + tsk->crc_seed_addr = aligned_alloc(ADDR_ALIGNMENT, sizeof(*tsk->crc_seed_addr)); *tsk->crc_seed_addr = tsk->crc_seed; tsk->crc_seed = 0x0; } diff --git a/test/dsa_test.c b/test/dsa_test.c index a4aad29..9f9d99b 100644 --- a/test/dsa_test.c +++ b/test/dsa_test.c @@ -13,6 +13,7 @@ #include "dsa.h" #define DSA_TEST_SIZE 20000 +#pragma GCC diagnostic ignored "-Wformat" static void usage(void) { diff --git a/test/iaa_test.c b/test/iaa_test.c index a1f529d..de9b860 100644 --- a/test/iaa_test.c +++ b/test/iaa_test.c @@ -9,6 +9,7 @@ #include "iaa.h" #define IAA_TEST_SIZE 20000 +#pragma GCC diagnostic ignored "-Wformat" static void usage(void) { diff --git a/util/log.h b/util/log.h index dc39e9b..2734c94 100644 --- a/util/log.h +++ b/util/log.h @@ -25,32 +25,32 @@ void log_init(struct log_ctx *ctx, const char *owner, const char *log_env); static inline void __attribute__((always_inline, format(printf, 2, 3))) log_null(struct log_ctx *ctx, const char *format, ...) {} -#define log_cond(ctx, prio, arg...) \ +#define log_cond(ctx, prio, ...) \ do { \ if ((ctx)->log_priority >= prio) \ - do_log(ctx, prio, __FILE__, __LINE__, __FUNCTION__, ## arg); \ + do_log(ctx, prio, __FILE__, __LINE__, __func__, __VA_ARGS__); \ } while (0) #ifdef ENABLE_LOGGING # ifdef ENABLE_DEBUG -# define log_dbg(ctx, arg...) log_cond(ctx, LOG_DEBUG, ## arg) +# define log_dbg(ctx, ...) log_cond(ctx, LOG_DEBUG, __VA_ARGS__) # else -# define log_dbg(ctx, arg...) log_null(ctx, ## arg) +# define log_dbg(ctx, ...) log_null(ctx, __VA_ARGS__) # endif -# define log_info(ctx, arg...) log_cond(ctx, LOG_INFO, ## arg) -# define log_err(ctx, arg...) log_cond(ctx, LOG_ERR, ## arg) -# define log_notice(ctx, arg...) log_cond(ctx, LOG_NOTICE, ## arg) +# define log_info(ctx, ...) log_cond(ctx, LOG_INFO, __VA_ARGS__) +# define log_err(ctx, ...) log_cond(ctx, LOG_ERR, __VA_ARGS__) +# define log_notice(ctx, ...) log_cond(ctx, LOG_NOTICE, __VA_ARGS__) #else -# define log_dbg(ctx, arg...) log_null(ctx, ## arg) -# define log_info(ctx, arg...) log_null(ctx, ## arg) -# define log_err(ctx, arg...) log_null(ctx, ## arg) -# define log_notice(ctx, arg...) log_null(ctx, ## arg) +# define log_dbg(ctx, ...) log_null(ctx, __VA_ARGS__) +# define log_info(ctx, ...) log_null(ctx, __VA_ARGS__) +# define log_err(ctx, ...) log_null(ctx, __VA_ARGS__) +# define log_notice(ctx, ...) log_null(ctx, __VA_ARGS__) #endif -#define dbg(x, arg...) log_dbg(&(x)->ctx, ## arg) -#define info(x, arg...) log_info(&(x)->ctx, ## arg) -#define err(x, arg...) log_err(&(x)->ctx, ## arg) -#define notice(x, arg...) log_notice(&(x)->ctx, ## arg) +#define dbg(x, ...) log_dbg(&(x)->ctx, __VA_ARGS__) +#define info(x, ...) log_info(&(x)->ctx, __VA_ARGS__) +#define err(x, ...) log_err(&(x)->ctx, __VA_ARGS__) +#define notice(x, ...) log_notice(&(x)->ctx, __VA_ARGS__) #ifndef HAVE_SECURE_GETENV # ifdef HAVE___SECURE_GETENV diff --git a/util/util.h b/util/util.h index 001707e..2573ee0 100644 --- a/util/util.h +++ b/util/util.h @@ -21,6 +21,7 @@ #include #pragma GCC diagnostic ignored "-Wmissing-prototypes" +#pragma GCC diagnostic ignored "-Wpedantic" #ifdef __GNUC__ #define NORETURN __attribute__((__noreturn__)) diff --git a/util/wrapper.c b/util/wrapper.c index b0de7bc..5460c7a 100644 --- a/util/wrapper.c +++ b/util/wrapper.c @@ -36,14 +36,13 @@ char *xstrdup(const char *str) void *xrealloc(void *ptr, size_t size) { void *ret = realloc(ptr, size); - if (!ret && !size) - ret = realloc(ptr, 1); + if (!ret) { - ret = realloc(ptr, size); - if (!ret && !size) - ret = realloc(ptr, 1); - if (!ret) - die("Out of memory, realloc failed"); + /* realloc() would free ptr if size == 0 */ + if (size) + free(ptr); + + die("Out of memory, realloc failed"); } return ret; } -- 2.34.1