From 0e6c493fec53c9a7268aaa73d9b99c3717d5d96f Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Fri, 22 Jan 2021 12:54:34 -0800 Subject: [PATCH] cppcheck: integrete cppcheck In order for cppcheck to perform a proper analysis it needs to be aware of how the sources are compiled (source files, include paths/files, extra defines, etc). All the needed information is available from the Makefiles and can be leveraged with a generic cppcheck Makefile target. So let's add one. Additional minor changes: * Removing the cppcheck-suppressions.txt file. With cppcheck 2.3 and these changes it appears to no longer be needed. Some inline suppressions were also removed since they appear not to be needed. We can add them back if it turns out they're needed for older versions of cppcheck. * Added the ax_count_cpus m4 macro to detect at configure time how many processors are available in order to run multiple cppcheck jobs. This value is also now used as a replacement for nproc when executing the kernel interface checks. * "PHONY =" line moved in to the Rules.am file which is included at the top of all Makefile.am's. This is just convenient becase it allows us to use the += syntax to add phony targets. * One upside of this integration worth mentioning is it now allows `make cppcheck` to be run in any directory to check that subtree. * For the moment, cppcheck is not run against the FreeBSD specific kernel sources. The cppcheck-FreeBSD target will need to be implemented and testing on FreeBSD to support this. Reviewed-by: Ryan Moeller Signed-off-by: Brian Behlendorf Closes #11508 --- Makefile.am | 13 ++-- cmd/Makefile.am | 10 +++ cmd/mount_zfs/Makefile.am | 2 + cmd/raidz_test/Makefile.am | 2 + cmd/zdb/Makefile.am | 2 + cmd/zed/Makefile.am | 2 + cmd/zfs/Makefile.am | 2 + cmd/zfs_ids_to_path/Makefile.am | 2 + cmd/zgenhostid/Makefile.am | 2 + cmd/zhack/Makefile.am | 2 + cmd/zinject/Makefile.am | 2 + cmd/zpool/Makefile.am | 2 + cmd/zpool_influxdb/Makefile.am | 2 + cmd/zstream/Makefile.am | 2 + cmd/ztest/Makefile.am | 2 + cmd/zvol_id/Makefile.am | 2 + config/CppCheck.am | 11 ++++ config/Rules.am | 1 + config/always-cppcheck.m4 | 6 ++ config/ax_count_cpus.m4 | 101 ++++++++++++++++++++++++++++++ config/zfs-build.m4 | 10 +-- cppcheck-suppressions.txt | 8 --- lib/Makefile.am | 10 ++- lib/libavl/Makefile.am | 2 + lib/libefi/Makefile.am | 2 + lib/libicp/Makefile.am | 2 + lib/libnvpair/Makefile.am | 3 +- lib/libshare/Makefile.am | 2 + lib/libspl/Makefile.am | 9 +++ lib/libtpool/Makefile.am | 2 + lib/libunicode/Makefile.am | 2 + lib/libuutil/Makefile.am | 3 +- lib/libzfs/Makefile.am | 3 +- lib/libzfs_core/Makefile.am | 3 +- lib/libzfsbootenv/Makefile.am | 3 +- lib/libzpool/Makefile.am | 2 + lib/libzstd/Makefile.am | 2 + lib/libzutil/Makefile.am | 2 + module/Makefile.in | 22 ++++++- module/lua/ldebug.c | 1 - module/lua/ldo.c | 1 - module/os/linux/spl/spl-generic.c | 2 - 42 files changed, 236 insertions(+), 30 deletions(-) create mode 100644 config/CppCheck.am create mode 100644 config/always-cppcheck.m4 create mode 100644 config/ax_count_cpus.m4 delete mode 100644 cppcheck-suppressions.txt diff --git a/Makefile.am b/Makefile.am index 436b78d762..b7cc4ce856 100644 --- a/Makefile.am +++ b/Makefile.am @@ -25,7 +25,6 @@ endif AUTOMAKE_OPTIONS = foreign EXTRA_DIST = autogen.sh copy-builtin -EXTRA_DIST += cppcheck-suppressions.txt EXTRA_DIST += config/config.awk config/rpm.am config/deb.am config/tgz.am EXTRA_DIST += META AUTHORS COPYRIGHT LICENSE NEWS NOTICE README.md EXTRA_DIST += CODE_OF_CONDUCT.md @@ -204,13 +203,13 @@ vcscheck: PHONY += lint lint: cppcheck paxcheck +CPPCHECKDIRS = cmd lib module PHONY += cppcheck -cppcheck: - @if type cppcheck > /dev/null 2>&1; then \ - cppcheck --quiet --force --error-exitcode=2 --inline-suppr \ - --suppressions-list=${top_srcdir}/cppcheck-suppressions.txt \ - -UHAVE_SSE2 -UHAVE_AVX512F -UHAVE_UIO_ZEROCOPY \ - ${top_srcdir}; \ +cppcheck: $(CPPCHECKDIRS) + @if test -n "$(CPPCHECK)"; then \ + set -e ; for dir in $(CPPCHECKDIRS) ; do \ + $(MAKE) -C $$dir cppcheck ; \ + done \ else \ echo "skipping cppcheck because cppcheck is not installed"; \ fi diff --git a/cmd/Makefile.am b/cmd/Makefile.am index d99d1dc382..473fcb0e07 100644 --- a/cmd/Makefile.am +++ b/cmd/Makefile.am @@ -2,10 +2,20 @@ SUBDIRS = zfs zpool zdb zhack zinject zstream zstreamdump ztest SUBDIRS += fsck_zfs vdev_id raidz_test zfs_ids_to_path SUBDIRS += zpool_influxdb +CPPCHECKDIRS = zfs zpool zdb zhack zinject zstream ztest +CPPCHECKDIRS += raidz_test zfs_ids_to_path zpool_influxdb + if USING_PYTHON SUBDIRS += arcstat arc_summary dbufstat endif if BUILD_LINUX SUBDIRS += mount_zfs zed zgenhostid zvol_id zvol_wait +CPPCHECKDIRS += mount_zfs zed zgenhostid zvol_id endif + +PHONY = cppcheck +cppcheck: $(CPPCHECKDIRS) + set -e ; for dir in $(CPPCHECKDIRS) ; do \ + $(MAKE) -C $$dir cppcheck ; \ + done diff --git a/cmd/mount_zfs/Makefile.am b/cmd/mount_zfs/Makefile.am index 6c4d6ff79f..3957602d27 100644 --- a/cmd/mount_zfs/Makefile.am +++ b/cmd/mount_zfs/Makefile.am @@ -18,3 +18,5 @@ mount_zfs_LDADD = \ $(abs_top_builddir)/lib/libnvpair/libnvpair.la mount_zfs_LDADD += $(LTLIBINTL) + +include $(top_srcdir)/config/CppCheck.am diff --git a/cmd/raidz_test/Makefile.am b/cmd/raidz_test/Makefile.am index 72c914e641..983ff25dc9 100644 --- a/cmd/raidz_test/Makefile.am +++ b/cmd/raidz_test/Makefile.am @@ -18,3 +18,5 @@ raidz_test_LDADD = \ $(abs_top_builddir)/lib/libzfs_core/libzfs_core.la raidz_test_LDADD += -lm + +include $(top_srcdir)/config/CppCheck.am diff --git a/cmd/zdb/Makefile.am b/cmd/zdb/Makefile.am index b325cb060b..c5858c2980 100644 --- a/cmd/zdb/Makefile.am +++ b/cmd/zdb/Makefile.am @@ -14,3 +14,5 @@ zdb_LDADD = \ $(abs_top_builddir)/lib/libzpool/libzpool.la \ $(abs_top_builddir)/lib/libzfs_core/libzfs_core.la \ $(abs_top_builddir)/lib/libnvpair/libnvpair.la + +include $(top_srcdir)/config/CppCheck.am diff --git a/cmd/zed/Makefile.am b/cmd/zed/Makefile.am index 4bd8ac4a53..7d2fe124fb 100644 --- a/cmd/zed/Makefile.am +++ b/cmd/zed/Makefile.am @@ -47,3 +47,5 @@ zed_LDADD += -lrt $(LIBUDEV_LIBS) $(LIBUUID_LIBS) zed_LDFLAGS = -pthread EXTRA_DIST = agents/README.md + +include $(top_srcdir)/config/CppCheck.am diff --git a/cmd/zfs/Makefile.am b/cmd/zfs/Makefile.am index dec5920381..1ead457f0f 100644 --- a/cmd/zfs/Makefile.am +++ b/cmd/zfs/Makefile.am @@ -21,3 +21,5 @@ zfs_LDADD += $(LTLIBINTL) if BUILD_FREEBSD zfs_LDADD += -lgeom -ljail endif + +include $(top_srcdir)/config/CppCheck.am diff --git a/cmd/zfs_ids_to_path/Makefile.am b/cmd/zfs_ids_to_path/Makefile.am index 176eeb3c72..5494267640 100644 --- a/cmd/zfs_ids_to_path/Makefile.am +++ b/cmd/zfs_ids_to_path/Makefile.am @@ -7,3 +7,5 @@ zfs_ids_to_path_SOURCES = \ zfs_ids_to_path_LDADD = \ $(abs_top_builddir)/lib/libzfs/libzfs.la + +include $(top_srcdir)/config/CppCheck.am diff --git a/cmd/zgenhostid/Makefile.am b/cmd/zgenhostid/Makefile.am index 87a42de5f9..4526a90a1d 100644 --- a/cmd/zgenhostid/Makefile.am +++ b/cmd/zgenhostid/Makefile.am @@ -3,3 +3,5 @@ include $(top_srcdir)/config/Rules.am sbin_PROGRAMS = zgenhostid zgenhostid_SOURCES = zgenhostid.c + +include $(top_srcdir)/config/CppCheck.am diff --git a/cmd/zhack/Makefile.am b/cmd/zhack/Makefile.am index 5cddac32b5..23f03ffd82 100644 --- a/cmd/zhack/Makefile.am +++ b/cmd/zhack/Makefile.am @@ -12,3 +12,5 @@ zhack_LDADD = \ $(abs_top_builddir)/lib/libzpool/libzpool.la \ $(abs_top_builddir)/lib/libzfs_core/libzfs_core.la \ $(abs_top_builddir)/lib/libnvpair/libnvpair.la + +include $(top_srcdir)/config/CppCheck.am diff --git a/cmd/zinject/Makefile.am b/cmd/zinject/Makefile.am index 091d92cd60..40f382c661 100644 --- a/cmd/zinject/Makefile.am +++ b/cmd/zinject/Makefile.am @@ -11,3 +11,5 @@ zinject_LDADD = \ $(abs_top_builddir)/lib/libzfs/libzfs.la \ $(abs_top_builddir)/lib/libzfs_core/libzfs_core.la \ $(abs_top_builddir)/lib/libnvpair/libnvpair.la + +include $(top_srcdir)/config/CppCheck.am diff --git a/cmd/zpool/Makefile.am b/cmd/zpool/Makefile.am index c0378b1369..fb03e99a30 100644 --- a/cmd/zpool/Makefile.am +++ b/cmd/zpool/Makefile.am @@ -34,6 +34,8 @@ zpool_LDADD += -lgeom endif zpool_LDADD += -lm $(LIBBLKID_LIBS) $(LIBUUID_LIBS) +include $(top_srcdir)/config/CppCheck.am + zpoolconfdir = $(sysconfdir)/zfs/zpool.d zpoolexecdir = $(zfsexecdir)/zpool.d diff --git a/cmd/zpool_influxdb/Makefile.am b/cmd/zpool_influxdb/Makefile.am index 28e94d616e..a59217570b 100644 --- a/cmd/zpool_influxdb/Makefile.am +++ b/cmd/zpool_influxdb/Makefile.am @@ -9,3 +9,5 @@ zpool_influxdb_LDADD = \ $(top_builddir)/lib/libspl/libspl.la \ $(top_builddir)/lib/libnvpair/libnvpair.la \ $(top_builddir)/lib/libzfs/libzfs.la + +include $(top_srcdir)/config/CppCheck.am diff --git a/cmd/zstream/Makefile.am b/cmd/zstream/Makefile.am index 5e2ac5d69f..69e1adbcbd 100644 --- a/cmd/zstream/Makefile.am +++ b/cmd/zstream/Makefile.am @@ -13,3 +13,5 @@ zstream_LDADD = \ $(abs_top_builddir)/lib/libzfs/libzfs.la \ $(abs_top_builddir)/lib/libzfs_core/libzfs_core.la \ $(abs_top_builddir)/lib/libnvpair/libnvpair.la + +include $(top_srcdir)/config/CppCheck.am diff --git a/cmd/ztest/Makefile.am b/cmd/ztest/Makefile.am index 6042b44d1d..d5e335e6d2 100644 --- a/cmd/ztest/Makefile.am +++ b/cmd/ztest/Makefile.am @@ -21,3 +21,5 @@ ztest_LDADD = \ ztest_LDADD += -lm ztest_LDFLAGS = -pthread + +include $(top_srcdir)/config/CppCheck.am diff --git a/cmd/zvol_id/Makefile.am b/cmd/zvol_id/Makefile.am index 8f9f3053ce..bb7e31a059 100644 --- a/cmd/zvol_id/Makefile.am +++ b/cmd/zvol_id/Makefile.am @@ -8,3 +8,5 @@ udev_PROGRAMS = zvol_id zvol_id_SOURCES = \ zvol_id_main.c + +include $(top_srcdir)/config/CppCheck.am diff --git a/config/CppCheck.am b/config/CppCheck.am new file mode 100644 index 0000000000..13c633c600 --- /dev/null +++ b/config/CppCheck.am @@ -0,0 +1,11 @@ +# +# Default rules for running cppcheck against the the user space components. +# + +PHONY += cppcheck + +CPPCHECKFLAGS = --std=c99 --quiet --max-configs=1 --error-exitcode=2 +CPPCHECKFLAGS += --inline-suppr -U_KERNEL + +cppcheck: + $(CPPCHECK) -j$(CPU_COUNT) $(CPPCHECKFLAGS) $(DEFAULT_INCLUDES) $(SOURCES) diff --git a/config/Rules.am b/config/Rules.am index b02511a052..e9cd134ede 100644 --- a/config/Rules.am +++ b/config/Rules.am @@ -3,6 +3,7 @@ # should include these rules and override or extend them as needed. # +PHONY = DEFAULT_INCLUDES = \ -include $(top_builddir)/zfs_config.h \ -I$(top_builddir)/include \ diff --git a/config/always-cppcheck.m4 b/config/always-cppcheck.m4 new file mode 100644 index 0000000000..c7c134a3e8 --- /dev/null +++ b/config/always-cppcheck.m4 @@ -0,0 +1,6 @@ +dnl # +dnl # Check if cppcheck is available. +dnl # +AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CPPCHECK], [ + AC_CHECK_PROG([CPPCHECK], [cppcheck], [cppcheck]) +]) diff --git a/config/ax_count_cpus.m4 b/config/ax_count_cpus.m4 new file mode 100644 index 0000000000..5db8925534 --- /dev/null +++ b/config/ax_count_cpus.m4 @@ -0,0 +1,101 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_count_cpus.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_COUNT_CPUS([ACTION-IF-DETECTED],[ACTION-IF-NOT-DETECTED]) +# +# DESCRIPTION +# +# Attempt to count the number of logical processor cores (including +# virtual and HT cores) currently available to use on the machine and +# place detected value in CPU_COUNT variable. +# +# On successful detection, ACTION-IF-DETECTED is executed if present. If +# the detection fails, then ACTION-IF-NOT-DETECTED is triggered. The +# default ACTION-IF-NOT-DETECTED is to set CPU_COUNT to 1. +# +# LICENSE +# +# Copyright (c) 2014,2016 Karlson2k (Evgeny Grin) +# Copyright (c) 2012 Brian Aker +# Copyright (c) 2008 Michael Paul Bailey +# Copyright (c) 2008 Christophe Tournayre +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 22 + + AC_DEFUN([AX_COUNT_CPUS],[dnl + AC_REQUIRE([AC_CANONICAL_HOST])dnl + AC_REQUIRE([AC_PROG_EGREP])dnl + AC_MSG_CHECKING([the number of available CPUs]) + CPU_COUNT="0" + + # Try generic methods + + # 'getconf' is POSIX utility, but '_NPROCESSORS_ONLN' and + # 'NPROCESSORS_ONLN' are platform-specific + command -v getconf >/dev/null 2>&1 && \ + CPU_COUNT=`getconf _NPROCESSORS_ONLN 2>/dev/null || getconf NPROCESSORS_ONLN 2>/dev/null` || CPU_COUNT="0" + AS_IF([[test "$CPU_COUNT" -gt "0" 2>/dev/null || ! command -v nproc >/dev/null 2>&1]],[[: # empty]],[dnl + # 'nproc' is part of GNU Coreutils and is widely available + CPU_COUNT=`OMP_NUM_THREADS='' nproc 2>/dev/null` || CPU_COUNT=`nproc 2>/dev/null` || CPU_COUNT="0" + ])dnl + + AS_IF([[test "$CPU_COUNT" -gt "0" 2>/dev/null]],[[: # empty]],[dnl + # Try platform-specific preferred methods + AS_CASE([[$host_os]],dnl + [[*linux*]],[[CPU_COUNT=`lscpu -p 2>/dev/null | $EGREP -e '^@<:@0-9@:>@+,' -c` || CPU_COUNT="0"]],dnl + [[*darwin*]],[[CPU_COUNT=`sysctl -n hw.logicalcpu 2>/dev/null` || CPU_COUNT="0"]],dnl + [[freebsd*]],[[command -v sysctl >/dev/null 2>&1 && CPU_COUNT=`sysctl -n kern.smp.cpus 2>/dev/null` || CPU_COUNT="0"]],dnl + [[netbsd*]], [[command -v sysctl >/dev/null 2>&1 && CPU_COUNT=`sysctl -n hw.ncpuonline 2>/dev/null` || CPU_COUNT="0"]],dnl + [[solaris*]],[[command -v psrinfo >/dev/null 2>&1 && CPU_COUNT=`psrinfo 2>/dev/null | $EGREP -e '^@<:@0-9@:>@.*on-line' -c 2>/dev/null` || CPU_COUNT="0"]],dnl + [[mingw*]],[[CPU_COUNT=`ls -qpU1 /proc/registry/HKEY_LOCAL_MACHINE/HARDWARE/DESCRIPTION/System/CentralProcessor/ 2>/dev/null | $EGREP -e '^@<:@0-9@:>@+/' -c` || CPU_COUNT="0"]],dnl + [[msys*]],[[CPU_COUNT=`ls -qpU1 /proc/registry/HKEY_LOCAL_MACHINE/HARDWARE/DESCRIPTION/System/CentralProcessor/ 2>/dev/null | $EGREP -e '^@<:@0-9@:>@+/' -c` || CPU_COUNT="0"]],dnl + [[cygwin*]],[[CPU_COUNT=`ls -qpU1 /proc/registry/HKEY_LOCAL_MACHINE/HARDWARE/DESCRIPTION/System/CentralProcessor/ 2>/dev/null | $EGREP -e '^@<:@0-9@:>@+/' -c` || CPU_COUNT="0"]]dnl + )dnl + ])dnl + + AS_IF([[test "$CPU_COUNT" -gt "0" 2>/dev/null || ! command -v sysctl >/dev/null 2>&1]],[[: # empty]],[dnl + # Try less preferred generic method + # 'hw.ncpu' exist on many platforms, but not on GNU/Linux + CPU_COUNT=`sysctl -n hw.ncpu 2>/dev/null` || CPU_COUNT="0" + ])dnl + + AS_IF([[test "$CPU_COUNT" -gt "0" 2>/dev/null]],[[: # empty]],[dnl + # Try platform-specific fallback methods + # They can be less accurate and slower then preferred methods + AS_CASE([[$host_os]],dnl + [[*linux*]],[[CPU_COUNT=`$EGREP -e '^processor' -c /proc/cpuinfo 2>/dev/null` || CPU_COUNT="0"]],dnl + [[*darwin*]],[[CPU_COUNT=`system_profiler SPHardwareDataType 2>/dev/null | $EGREP -i -e 'number of cores:'|cut -d : -f 2 -s|tr -d ' '` || CPU_COUNT="0"]],dnl + [[freebsd*]],[[CPU_COUNT=`dmesg 2>/dev/null| $EGREP -e '^cpu@<:@0-9@:>@+: '|sort -u|$EGREP -e '^' -c` || CPU_COUNT="0"]],dnl + [[netbsd*]], [[CPU_COUNT=`command -v cpuctl >/dev/null 2>&1 && cpuctl list 2>/dev/null| $EGREP -e '^@<:@0-9@:>@+ .* online ' -c` || \ + CPU_COUNT=`dmesg 2>/dev/null| $EGREP -e '^cpu@<:@0-9@:>@+ at'|sort -u|$EGREP -e '^' -c` || CPU_COUNT="0"]],dnl + [[solaris*]],[[command -v kstat >/dev/null 2>&1 && CPU_COUNT=`kstat -m cpu_info -s state -p 2>/dev/null | $EGREP -c -e 'on-line'` || \ + CPU_COUNT=`kstat -m cpu_info 2>/dev/null | $EGREP -c -e 'module: cpu_info'` || CPU_COUNT="0"]],dnl + [[mingw*]],[AS_IF([[CPU_COUNT=`reg query 'HKLM\\Hardware\\Description\\System\\CentralProcessor' 2>/dev/null | $EGREP -e '\\\\@<:@0-9@:>@+$' -c`]],dnl + [[: # empty]],[[test "$NUMBER_OF_PROCESSORS" -gt "0" 2>/dev/null && CPU_COUNT="$NUMBER_OF_PROCESSORS"]])],dnl + [[msys*]],[[test "$NUMBER_OF_PROCESSORS" -gt "0" 2>/dev/null && CPU_COUNT="$NUMBER_OF_PROCESSORS"]],dnl + [[cygwin*]],[[test "$NUMBER_OF_PROCESSORS" -gt "0" 2>/dev/null && CPU_COUNT="$NUMBER_OF_PROCESSORS"]]dnl + )dnl + ])dnl + + AS_IF([[test "x$CPU_COUNT" != "x0" && test "$CPU_COUNT" -gt 0 2>/dev/null]],[dnl + AC_MSG_RESULT([[$CPU_COUNT]]) + m4_ifvaln([$1],[$1],)dnl + ],[dnl + m4_ifval([$2],[dnl + AS_UNSET([[CPU_COUNT]]) + AC_MSG_RESULT([[unable to detect]]) + $2 + ], [dnl + CPU_COUNT="1" + AC_MSG_RESULT([[unable to detect (assuming 1)]]) + ])dnl + ])dnl + ])dnl diff --git a/config/zfs-build.m4 b/config/zfs-build.m4 index f0eb47035d..305d0c6936 100644 --- a/config/zfs-build.m4 +++ b/config/zfs-build.m4 @@ -153,6 +153,9 @@ AC_DEFUN([ZFS_AC_DEBUG_KMEM_TRACKING], [ ]) AC_DEFUN([ZFS_AC_CONFIG_ALWAYS], [ + AX_COUNT_CPUS([]) + AC_SUBST(CPU_COUNT) + ZFS_AC_CONFIG_ALWAYS_CC_NO_UNUSED_BUT_SET_VARIABLE ZFS_AC_CONFIG_ALWAYS_CC_NO_BOOL_COMPARE ZFS_AC_CONFIG_ALWAYS_CC_FRAME_LARGER_THAN @@ -167,6 +170,7 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS], [ ZFS_AC_CONFIG_ALWAYS_PYTHON ZFS_AC_CONFIG_ALWAYS_PYZFS ZFS_AC_CONFIG_ALWAYS_SED + ZFS_AC_CONFIG_ALWAYS_CPPCHECK ]) AC_DEFUN([ZFS_AC_CONFIG], [ @@ -191,12 +195,10 @@ AC_DEFUN([ZFS_AC_CONFIG], [ ZFS_AC_CONFIG_ALWAYS - AM_COND_IF([BUILD_LINUX], [ - AC_ARG_VAR([TEST_JOBS], - [simultaneous jobs during configure (defaults to $(nproc))]) + AC_ARG_VAR([TEST_JOBS], [simultaneous jobs during configure]) if test "x$ac_cv_env_TEST_JOBS_set" != "xset"; then - TEST_JOBS=$(nproc) + TEST_JOBS=$CPU_COUNT fi AC_SUBST(TEST_JOBS) ]) diff --git a/cppcheck-suppressions.txt b/cppcheck-suppressions.txt deleted file mode 100644 index 8a0a1b830e..0000000000 --- a/cppcheck-suppressions.txt +++ /dev/null @@ -1,8 +0,0 @@ -preprocessorErrorDirective:./module/zfs/vdev_raidz_math_avx512f.c:243 -preprocessorErrorDirective:./module/zfs/vdev_raidz_math_sse2.c:266 -uninitvar:module/os/freebsd/zfs/vdev_geom.c -uninitvar:module/os/freebsd/zfs/zfs_vfsops.c -uninitvar:module/os/freebsd/spl/spl_zone.c -uninitvar:lib/libzutil/os/freebsd/zutil_import_os.c -*:module/zstd/lib/zstd.c -*:module/zstd/lib/zstd.h diff --git a/lib/Makefile.am b/lib/Makefile.am index 685c7b6695..db7a3fa31d 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,9 +1,12 @@ # NB: GNU Automake Manual, Chapter 8.3.5: Libtool Convenience Libraries # These nine libraries are intermediary build components. SUBDIRS = libavl libicp libshare libspl libtpool libzstd +CPPCHECKDIRS = libavl libicp libnvpair libshare libspl libtpool libunicode +CPPCHECKDIRS += libuutil libzfs libzfs_core libzfsbootenv libzpool libzutil if BUILD_LINUX SUBDIRS += libefi +CPPCHECKDIRS += libefi endif # libnvpair is installed as part of the final build product @@ -23,7 +26,7 @@ DISTLIBS += libnvpair # is only linked against by ztest and zdb and no stable ABI is provided. ABILIBS = libnvpair libuutil libzfs_core libzfs libzfsbootenv -PHONY = checkabi storeabi +PHONY = checkabi storeabi cppcheck checkabi: $(ABILIBS) set -e ; for dir in $(ABILIBS) ; do \ $(MAKE) -C $$dir checkabi ; \ @@ -33,3 +36,8 @@ storeabi: $(ABILIBS) set -e ; for dir in $(ABILIBS) ; do \ $(MAKE) -C $$dir storeabi ; \ done + +cppcheck: $(CPPCHECKDIRS) + set -e ; for dir in $(CPPCHECKDIRS) ; do \ + $(MAKE) -C $$dir cppcheck ; \ + done diff --git a/lib/libavl/Makefile.am b/lib/libavl/Makefile.am index 6087b1d2f4..2e0a431c77 100644 --- a/lib/libavl/Makefile.am +++ b/lib/libavl/Makefile.am @@ -12,3 +12,5 @@ KERNEL_C = \ nodist_libavl_la_SOURCES = \ $(KERNEL_C) + +include $(top_srcdir)/config/CppCheck.am diff --git a/lib/libefi/Makefile.am b/lib/libefi/Makefile.am index fab6c8d477..b26f7a6dcd 100644 --- a/lib/libefi/Makefile.am +++ b/lib/libefi/Makefile.am @@ -10,3 +10,5 @@ USER_C = \ libefi_la_SOURCES = $(USER_C) libefi_la_LIBADD = $(LIBUUID_LIBS) $(ZLIB_LIBS) + +include $(top_srcdir)/config/CppCheck.am diff --git a/lib/libicp/Makefile.am b/lib/libicp/Makefile.am index 6d3c65ea32..0b87a988c0 100644 --- a/lib/libicp/Makefile.am +++ b/lib/libicp/Makefile.am @@ -71,3 +71,5 @@ KERNEL_ASM = $(ASM_SOURCES_AS) nodist_libicp_la_SOURCES = \ $(KERNEL_C) \ $(KERNEL_ASM) + +include $(top_srcdir)/config/CppCheck.am diff --git a/lib/libnvpair/Makefile.am b/lib/libnvpair/Makefile.am index 7840e099bb..a3e1fa307f 100644 --- a/lib/libnvpair/Makefile.am +++ b/lib/libnvpair/Makefile.am @@ -1,5 +1,4 @@ include $(top_srcdir)/config/Rules.am -PHONY = VPATH = \ $(top_srcdir)/module/nvpair \ @@ -42,5 +41,7 @@ endif libnvpair_la_LDFLAGS += -version-info 3:0:0 +include $(top_srcdir)/config/CppCheck.am + # Library ABI EXTRA_DIST = libnvpair.abi libnvpair.suppr diff --git a/lib/libshare/Makefile.am b/lib/libshare/Makefile.am index e730ee3bea..7cef13c3da 100644 --- a/lib/libshare/Makefile.am +++ b/lib/libshare/Makefile.am @@ -23,3 +23,5 @@ USER_C += \ endif libshare_la_SOURCES = $(USER_C) + +include $(top_srcdir)/config/CppCheck.am diff --git a/lib/libspl/Makefile.am b/lib/libspl/Makefile.am index fc4f27c64e..d27932aff9 100644 --- a/lib/libspl/Makefile.am +++ b/lib/libspl/Makefile.am @@ -55,3 +55,12 @@ libspl_la_LIBADD = \ libspl_assert.la libspl_la_LIBADD += $(LIBCLOCK_GETTIME) + +include $(top_srcdir)/config/CppCheck.am + +# Override the default SOURCES which includes TARGET_CPU_ATOMIC_SOURCE +# in order to always evaluate the generic asm-generic/atomic.c source. +CPPCHECKSRC = $(USER_C) asm-generic/atomic.c +cppcheck: + $(CPPCHECK) -j$(CPU_COUNT) $(CPPCHECKFLAGS) --force \ + $(DEFAULT_INCLUDES) $(CPPCHECKSRC) diff --git a/lib/libtpool/Makefile.am b/lib/libtpool/Makefile.am index 22bfa4b23a..aa8bde32f9 100644 --- a/lib/libtpool/Makefile.am +++ b/lib/libtpool/Makefile.am @@ -7,3 +7,5 @@ USER_C = \ thread_pool_impl.h libtpool_la_SOURCES = $(USER_C) + +include $(top_srcdir)/config/CppCheck.am diff --git a/lib/libunicode/Makefile.am b/lib/libunicode/Makefile.am index fa9dd359d2..b82975f68e 100644 --- a/lib/libunicode/Makefile.am +++ b/lib/libunicode/Makefile.am @@ -13,3 +13,5 @@ KERNEL_C = \ nodist_libunicode_la_SOURCES = \ $(KERNEL_C) + +include $(top_srcdir)/config/CppCheck.am diff --git a/lib/libuutil/Makefile.am b/lib/libuutil/Makefile.am index 5e7cf5419d..16d5023451 100644 --- a/lib/libuutil/Makefile.am +++ b/lib/libuutil/Makefile.am @@ -1,5 +1,4 @@ include $(top_srcdir)/config/Rules.am -PHONY = lib_LTLIBRARIES = libuutil.la @@ -32,5 +31,7 @@ endif libuutil_la_LDFLAGS += -version-info 3:0:0 +include $(top_srcdir)/config/CppCheck.am + # Library ABI EXTRA_DIST = libuutil.abi libuutil.suppr diff --git a/lib/libzfs/Makefile.am b/lib/libzfs/Makefile.am index cd80ef7195..621021a121 100644 --- a/lib/libzfs/Makefile.am +++ b/lib/libzfs/Makefile.am @@ -1,5 +1,4 @@ include $(top_srcdir)/config/Rules.am -PHONY = VPATH = \ $(top_srcdir)/module/icp \ @@ -90,6 +89,8 @@ endif libzfs_la_LDFLAGS += -version-info 4:0:0 +include $(top_srcdir)/config/CppCheck.am + # Library ABI EXTRA_DIST = libzfs.abi libzfs.suppr diff --git a/lib/libzfs_core/Makefile.am b/lib/libzfs_core/Makefile.am index 760cadddeb..67e554dc87 100644 --- a/lib/libzfs_core/Makefile.am +++ b/lib/libzfs_core/Makefile.am @@ -1,5 +1,4 @@ include $(top_srcdir)/config/Rules.am -PHONY = pkgconfig_DATA = libzfs_core.pc @@ -30,5 +29,7 @@ endif libzfs_core_la_LDFLAGS += -version-info 3:0:0 +include $(top_srcdir)/config/CppCheck.am + # Library ABI EXTRA_DIST = libzfs_core.abi libzfs_core.suppr diff --git a/lib/libzfsbootenv/Makefile.am b/lib/libzfsbootenv/Makefile.am index 51ab48f543..984df0b8a3 100644 --- a/lib/libzfsbootenv/Makefile.am +++ b/lib/libzfsbootenv/Makefile.am @@ -1,5 +1,4 @@ include $(top_srcdir)/config/Rules.am -PHONY = pkgconfig_DATA = libzfsbootenv.pc @@ -34,5 +33,7 @@ endif libzfsbootenv_la_LDFLAGS += -version-info 1:0:0 +include $(top_srcdir)/config/CppCheck.am + # Library ABI EXTRA_DIST = libzfsbootenv.abi libzfsbootenv.suppr diff --git a/lib/libzpool/Makefile.am b/lib/libzpool/Makefile.am index 7aa7e80985..04ef34ebfa 100644 --- a/lib/libzpool/Makefile.am +++ b/lib/libzpool/Makefile.am @@ -235,3 +235,5 @@ if TARGET_CPU_POWERPC vdev_raidz_math_powerpc_altivec.$(OBJEXT): CFLAGS += -maltivec vdev_raidz_math_powerpc_altivec.l$(OBJEXT): CFLAGS += -maltivec endif + +include $(top_srcdir)/config/CppCheck.am diff --git a/lib/libzstd/Makefile.am b/lib/libzstd/Makefile.am index df31d8b23d..c9ed7e2aaf 100644 --- a/lib/libzstd/Makefile.am +++ b/lib/libzstd/Makefile.am @@ -19,3 +19,5 @@ lib/zstd.l$(OBJEXT): CFLAGS += -fno-tree-vectorize -include $(top_srcdir)/module zfs_zstd.$(OBJEXT): CFLAGS += -include $(top_srcdir)/module/zstd/include/zstd_compat_wrapper.h zfs_zstd.l$(OBJEXT): CFLAGS += -include $(top_srcdir)/module/zstd/include/zstd_compat_wrapper.h + +include $(top_srcdir)/config/CppCheck.am diff --git a/lib/libzutil/Makefile.am b/lib/libzutil/Makefile.am index 9cfb0de058..2f0357e9f9 100644 --- a/lib/libzutil/Makefile.am +++ b/lib/libzutil/Makefile.am @@ -50,3 +50,5 @@ libzutil_la_LIBADD += \ endif libzutil_la_LIBADD += -lm $(LIBBLKID_LIBS) $(LIBUDEV_LIBS) + +include $(top_srcdir)/config/CppCheck.am diff --git a/module/Makefile.in b/module/Makefile.in index 0ee2c44722..69caf48570 100644 --- a/module/Makefile.in +++ b/module/Makefile.in @@ -14,7 +14,8 @@ check: modules modules-Linux modules-FreeBSD modules-unknown \ clean clean-Linux clean-FreeBSD \ modules_install modules_install-Linux modules_install-FreeBSD \ - modules_uninstall modules_uninstall-Linux modules_uninstall-FreeBSD + modules_uninstall modules_uninstall-Linux modules_uninstall-FreeBSD \ + cppcheck cppcheck-Linux cppcheck-FreeBSD # Filter out options that FreeBSD make doesn't understand getflags = ( \ @@ -106,6 +107,25 @@ modules_uninstall-FreeBSD: modules_uninstall: modules_uninstall-@ac_system@ +cppcheck-Linux: + @CPPCHECK@ -j@CPU_COUNT@ --std=c99 --quiet --force --error-exitcode=2 \ + --inline-suppr --suppress=noValidConfiguration \ + --enable=warning,information -D_KERNEL \ + --include=@LINUX_OBJ@/include/generated/autoconf.h \ + --include=@top_srcdir@/zfs_config.h \ + --config-exclude=@LINUX_OBJ@/include \ + -I @LINUX_OBJ@/include \ + -I @top_srcdir@/include/os/linux/kernel \ + -I @top_srcdir@/include/os/linux/spl \ + -I @top_srcdir@/include/os/linux/zfs \ + -I @top_srcdir@/include \ + avl icp lua nvpair spl unicode zcommon zfs zstd os/linux + +cppcheck-FreeBSD: + @true + +cppcheck: cppcheck-@ac_system@ + distdir: (cd @srcdir@ && find $(ZFS_MODULES) os -name '*.[chS]') | \ while read path; do \ diff --git a/module/lua/ldebug.c b/module/lua/ldebug.c index 2e1efa4e72..da005c4437 100644 --- a/module/lua/ldebug.c +++ b/module/lua/ldebug.c @@ -324,7 +324,6 @@ static void kname (Proto *p, int pc, int c, const char **name) { if (ISK(c)) { /* is 'c' a constant? */ TValue *kvalue = &p->k[INDEXK(c)]; if (ttisstring(kvalue)) { /* literal constant? */ - // cppcheck-suppress autoVariables *name = svalue(kvalue); /* it is its own name */ return; } diff --git a/module/lua/ldo.c b/module/lua/ldo.c index 474fe659bc..f3c3dcb4d8 100644 --- a/module/lua/ldo.c +++ b/module/lua/ldo.c @@ -196,7 +196,6 @@ int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { struct lua_longjmp lj; lj.status = LUA_OK; lj.previous = L->errorJmp; /* chain new error handler */ - // cppcheck-suppress autoVariables L->errorJmp = &lj; LUAI_TRY(L, &lj, (*f)(L, ud); diff --git a/module/os/linux/spl/spl-generic.c b/module/os/linux/spl/spl-generic.c index 1da7618185..36fdff72a1 100644 --- a/module/os/linux/spl/spl-generic.c +++ b/module/os/linux/spl/spl-generic.c @@ -284,9 +284,7 @@ int64_t __divdi3(int64_t u, int64_t v) { int64_t q, t; - // cppcheck-suppress shiftTooManyBitsSigned q = __udivdi3(abs64(u), abs64(v)); - // cppcheck-suppress shiftTooManyBitsSigned t = (u ^ v) >> 63; // If u, v have different return ((q ^ t) - t); // signs, negate q. }