Commit dff98e73 authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Tomasz Zawadzki
Browse files

check_format: test for sizeof() usage in *ext_opts structs



This is a very basic test that will check that people don't do stuff
like:

struct spdk_foo foo;
foo.size = sizeof(struct spdk_foo);

in structures that should use SPDK_SIZEOF() to calculate their size.

The check is very basic and it won't find stuff like:

foo.size = sizeof(foo);

but should be enough catch a lot, while not producing much false
positives at the same time.

Signed-off-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Change-Id: Ic32a12530c71ee12003ba884f4f5574467f232d8
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/18603


Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarMichal Berger <michal.berger@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
parent 5681a8a6
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -382,6 +382,22 @@ function check_include_style() {
	return $rc
}

function check_opts_structs() {
	local IFS="|" out types=(
		spdk_nvme_ns_cmd_ext_io_opts
		spdk_dif_ctx_init_ext_opts
	)

	if out=$(git grep -InE "(\.|->)size[[:space:]]*=[[:space:]]*sizeof\(struct (${types[*]})\)"); then
		cat <<- WARN
			Found incorrect *ext_opts struct usage.  Use SPDK_SIZEOF() to calculate its size.

			$out
		WARN
		return 1
	fi
}

function check_python_style() {
	local rc=0

@@ -787,6 +803,7 @@ check_eof || rc=1
check_posix_includes || rc=1
check_naming_conventions || rc=1
check_include_style || rc=1
check_opts_structs || rc=1
check_python_style || rc=1
check_bash_style || rc=1
check_bash_static_analysis || rc=1