From fa2fc871d2e4dc1e6d2d3c5f040e2d8ff272abcb Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Thu, 24 Jun 2021 12:55:06 -0400 Subject: [PATCH] swtpm: Fix issues raised by -Wextra Signed-off-by: Stefan Berger --- include/Makefile.am | 2 ++ include/compiler_dependencies.h | 17 +++++++++++++++++ src/swtpm/Makefile.am | 1 + src/swtpm/common.h | 6 ++++-- src/swtpm/cuse_tpm.c | 18 +++++++++++------- src/swtpm/mainloop.c | 3 ++- src/swtpm/swtpm_nvfile.c | 3 ++- 7 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 include/compiler_dependencies.h diff --git a/include/Makefile.am b/include/Makefile.am index 584cf4b..80c1c34 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -7,7 +7,9 @@ SUBDIRS = swtpm noinst_HEADERS = \ + compiler_dependencies.h \ sys_dependencies.h EXTRA_DIST = \ + compiler_dependencies.h \ sys_dependencies.h diff --git a/include/compiler_dependencies.h b/include/compiler_dependencies.h new file mode 100644 index 0000000..97129f1 --- /dev/null +++ b/include/compiler_dependencies.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * compiler_dependencies.h: Compiler-dependent defines etc. + * + * Author: Stefan Berger, stefanb@linux.ibm.com + * + * Copyright (c) IBM Corporation, 2021 + */ + +#ifndef _SWTPM_COMPILER_DEPENDENCIES_H +#define _SWTPM_COMPILER_DEPENDENCIES_H + +#ifdef __GNUC__ /* gcc and clang */ +# define SWTPM_ATTR_UNUSED __attribute__((unused)) +#endif + +#endif /* _SWTPM_COMPILER_DEPENDENCIES_H */ diff --git a/src/swtpm/Makefile.am b/src/swtpm/Makefile.am index 4c25a77..d7612c0 100644 --- a/src/swtpm/Makefile.am +++ b/src/swtpm/Makefile.am @@ -117,6 +117,7 @@ swtpm_cuse_SOURCES = \ swtpm_cuse_CFLAGS = \ -I$(top_builddir)/include \ + -I$(top_srcdir)/include \ -I$(top_srcdir)/include/swtpm \ $(GLIB_CFLAGS) \ $(LIBFUSE_CFLAGS) \ diff --git a/src/swtpm/common.h b/src/swtpm/common.h index e1c20a3..f284028 100644 --- a/src/swtpm/common.h +++ b/src/swtpm/common.h @@ -41,6 +41,8 @@ #include +#include "compiler_dependencies.h" + int handle_log_options(char *options); int handle_key_options(char *options); int handle_migration_key_options(char *options); @@ -56,8 +58,8 @@ int handle_flags_options(char *options, bool *need_init_cmd, #ifdef WITH_SECCOMP int handle_seccomp_options(char *options, unsigned int *seccomp_action); #else -static inline int handle_seccomp_options(char *options, - unsigned int *seccomp_action) +static inline int handle_seccomp_options(char *options SWTPM_ATTR_UNUSED, + unsigned int *seccomp_action SWTPM_ATTR_UNUSED) { return 0; } diff --git a/src/swtpm/cuse_tpm.c b/src/swtpm/cuse_tpm.c index c13e13e..1334979 100644 --- a/src/swtpm/cuse_tpm.c +++ b/src/swtpm/cuse_tpm.c @@ -245,7 +245,8 @@ static const char *usage = "\n"; static TPM_RESULT -ptm_io_getlocality(TPM_MODIFIER_INDICATOR *loc, uint32_t tpmnum) +ptm_io_getlocality(TPM_MODIFIER_INDICATOR *loc, + uint32_t tpmnum SWTPM_ATTR_UNUSED) { *loc = locality; return TPM_SUCCESS; @@ -396,7 +397,7 @@ static int cached_stateblob_copy(void *dest, size_t destlen, /* * worker_thread: the worker thread */ -static void worker_thread(gpointer data, gpointer user_data) +static void worker_thread(gpointer data, gpointer user_data SWTPM_ATTR_UNUSED) { struct thread_message *msg = (struct thread_message *)data; @@ -499,7 +500,8 @@ static void ptm_write_fatal_error_response(TPMLIB_TPMVersion l_tpmversion) /* * ptm_send_startup: Send a TPM/TPM2_Startup */ -static int ptm_send_startup(uint16_t startupType, TPMLIB_TPMVersion l_tpmversion) +static int ptm_send_startup(uint16_t startupType, + TPMLIB_TPMVersion l_tpmversion SWTPM_ATTR_UNUSED) { uint32_t command_length; unsigned char command[sizeof(struct tpm_startup)]; @@ -597,8 +599,8 @@ static void ptm_read_stateblob(fuse_req_t req, size_t size) * Depending on the current state of the transfer interface (read/write) * return either the results of TPM commands or a data of a TPM state blob. */ -static void ptm_read(fuse_req_t req, size_t size, off_t off, - struct fuse_file_info *fi) +static void ptm_read(fuse_req_t req, size_t size, off_t off SWTPM_ATTR_UNUSED, + struct fuse_file_info *fi SWTPM_ATTR_UNUSED) { switch (tx_state.state) { case TX_STATE_RW_COMMAND: @@ -918,7 +920,8 @@ cleanup: * on what is being transferred using the write() */ static void ptm_write(fuse_req_t req, const char *buf, size_t size, - off_t off, struct fuse_file_info *fi) + off_t off SWTPM_ATTR_UNUSED, + struct fuse_file_info *fi SWTPM_ATTR_UNUSED) { switch (tx_state.state) { case TX_STATE_RW_COMMAND: @@ -959,7 +962,8 @@ static void ptm_open(fuse_req_t req, struct fuse_file_info *fi) * needed buffer */ static void ptm_ioctl(fuse_req_t req, int cmd, void *arg, - struct fuse_file_info *fi, unsigned flags, + struct fuse_file_info *fi SWTPM_ATTR_UNUSED, + unsigned flags SWTPM_ATTR_UNUSED, const void *in_buf, size_t in_bufsz, size_t out_bufsz) { TPM_RESULT res = TPM_FAIL; diff --git a/src/swtpm/mainloop.c b/src/swtpm/mainloop.c index 04ffa6a..1a3420a 100644 --- a/src/swtpm/mainloop.c +++ b/src/swtpm/mainloop.c @@ -64,6 +64,7 @@ #include "mainloop.h" #include "utils.h" #include "sys_dependencies.h" +#include "compiler_dependencies.h" /* local variables */ static TPM_MODIFIER_INDICATOR locality; @@ -73,7 +74,7 @@ bool mainloop_terminate; TPM_RESULT mainloop_cb_get_locality(TPM_MODIFIER_INDICATOR *loc, - uint32_t tpmnum) + uint32_t tpmnum SWTPM_ATTR_UNUSED) { *loc = locality; diff --git a/src/swtpm/swtpm_nvfile.c b/src/swtpm/swtpm_nvfile.c index caa7433..8f13744 100644 --- a/src/swtpm/swtpm_nvfile.c +++ b/src/swtpm/swtpm_nvfile.c @@ -89,6 +89,7 @@ #include "tpmlib.h" #include "tlv.h" #include "utils.h" +#include "compiler_dependencies.h" /* local structures */ typedef struct { @@ -1394,7 +1395,7 @@ err_exit: TPM_RESULT SWTPM_NVRAM_SetStateBlob(unsigned char *data, uint32_t length, TPM_BOOL is_encrypted, - uint32_t tpm_number, + uint32_t tpm_number SWTPM_ATTR_UNUSED, uint32_t blobtype) { TPM_RESULT res;