Add checkpatch.pl to presubmit tests.
Change-Id: I235ea140f5f54dc8b22f1c69dcff5e99a34ff602
diff --git a/Makefile b/Makefile
index 0b1851c..a872b0b 100644
--- a/Makefile
+++ b/Makefile
@@ -19,6 +19,9 @@
NINJA ?= $(PREBUILTS)/ninja/ninja
export PATH := $(PREBUILTS)/clang/bin:$(PATH)
+CHECKPATCH := $(PWD)/third_party/linux/scripts/checkpatch.pl \
+ --ignore BRACES,SPDX_LICENSE_TAG,VOLATILE,SPLIT_STRING,AVOID_EXTERNS,USE_SPINLOCK_T,NEW_TYPEDEFS,INITIALISED_STATIC,FILE_PATH_CHANGES,EMBEDDED_FUNCTION_NAME --quiet
+
# Select the project to build.
PROJECT ?= reference
@@ -50,6 +53,13 @@
@find project/ -name \*.c -o -name \*.cc -o -name \*.h | xargs clang-format -style file -i
@find . \( -name \*.gn -o -name \*.gni \) | xargs -n1 $(GN) format
+.PHONY: checkpatch
+checkpatch:
+ @find src/ -name \*.c -o -name \*.h | xargs $(CHECKPATCH) -f
+ @find inc/ -name \*.c -o -name \*.h | xargs $(CHECKPATCH) -f
+ # TODO: enable for test/
+ @find project/ -name \*.c -o -name \*.h | xargs $(CHECKPATCH) -f
+
# see .clang-tidy.
.PHONY: tidy
tidy: $(OUT_DIR)/build.ninja
diff --git a/inc/hf/std.h b/inc/hf/std.h
index 39d3d08..c872fd4 100644
--- a/inc/hf/std.h
+++ b/inc/hf/std.h
@@ -65,8 +65,12 @@
#define htole32(v) __builtin_bswap32(v)
#define htole64(v) __builtin_bswap64(v)
-#else /* __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ && \
- __BYTE_ORDER__ != __ORDER_BIG_ENDIAN__ */
+#else
+
+/*
+ * __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ &&
+ * __BYTE_ORDER__ != __ORDER_BIG_ENDIAN__
+ */
#error "Unsupported byte order"
diff --git a/inc/vmapi/hf/abi.h b/inc/vmapi/hf/abi.h
index 2e4ec7b..6f43360 100644
--- a/inc/vmapi/hf/abi.h
+++ b/inc/vmapi/hf/abi.h
@@ -93,6 +93,7 @@
static inline uint64_t hf_vcpu_run_return_encode(struct hf_vcpu_run_return res)
{
uint64_t ret = res.code & 0xff;
+
switch (res.code) {
case HF_VCPU_RUN_WAKE_UP:
ret |= (uint64_t)res.wake_up.vm_id << 32;
@@ -107,6 +108,7 @@
default:
break;
}
+
return ret;
}
diff --git a/kokoro/ubuntu/build.sh b/kokoro/ubuntu/build.sh
index c7951e4..8d53d7b 100755
--- a/kokoro/ubuntu/build.sh
+++ b/kokoro/ubuntu/build.sh
@@ -84,6 +84,8 @@
exit 1
fi
+make checkpatch
+
#
# Step 5: make sure there's not lint.
#
diff --git a/project/reference b/project/reference
index ad27769..2851947 160000
--- a/project/reference
+++ b/project/reference
@@ -1 +1 @@
-Subproject commit ad27769360362f6b93f44b5709ec97dc825c829e
+Subproject commit 2851947a299989c05261edafe96e85f25c38458a
diff --git a/src/api.c b/src/api.c
index 8ff3b60..7341bfc 100644
--- a/src/api.c
+++ b/src/api.c
@@ -274,7 +274,7 @@
/**
* Check that the mode indicates memory that is valid, owned and exclusive.
*/
-bool static api_mode_valid_owned_and_exclusive(int mode)
+static bool api_mode_valid_owned_and_exclusive(int mode)
{
return (mode & (MM_MODE_INVALID | MM_MODE_UNOWNED | MM_MODE_SHARED)) ==
0;
diff --git a/src/arch/aarch64/msr.h b/src/arch/aarch64/msr.h
index 3989342..b77461c 100644
--- a/src/arch/aarch64/msr.h
+++ b/src/arch/aarch64/msr.h
@@ -27,5 +27,9 @@
__v; \
})
-#define write_msr(name, value) \
- __asm__ volatile("msr " #name ", %x0" : : "rZ"((uintreg_t)(value)))
+#define write_msr(name, value) \
+ __extension__({ \
+ __asm__ volatile("msr " #name ", %x0" \
+ : \
+ : "rZ"((uintreg_t)(value))); \
+ })
diff --git a/src/dlog.c b/src/dlog.c
index 322c054..1ce5566 100644
--- a/src/dlog.c
+++ b/src/dlog.c
@@ -53,9 +53,11 @@
static size_t print_raw_string(const char *str)
{
const char *c = str;
+
while (*c != '\0') {
arch_putchar(*c++);
}
+
return c - str;
}
diff --git a/src/fdt.c b/src/fdt.c
index cb7e524..697983e 100644
--- a/src/fdt.c
+++ b/src/fdt.c
@@ -72,6 +72,7 @@
static bool fdt_tokenizer_uint32(struct fdt_tokenizer *t, uint32_t *res)
{
const char *next = t->cur + sizeof(*res);
+
if (next > t->end) {
return false;
}
@@ -99,6 +100,7 @@
size_t size)
{
const char *next = t->cur + size;
+
if (next > t->end) {
return false;
}
@@ -113,6 +115,7 @@
static bool fdt_tokenizer_str(struct fdt_tokenizer *t, const char **res)
{
const char *p;
+
for (p = t->cur; p < t->end; p++) {
if (!*p) {
/* Found the end of the string. */
@@ -221,6 +224,7 @@
const char *name;
const char *buf;
uint32_t size;
+
while (fdt_next_property(t, &name, &buf, &size)) {
/* do nothing */
}
@@ -396,6 +400,7 @@
/* TODO: Clean this up. */
uint8_t *begin = (uint8_t *)hdr + be32toh(hdr->off_mem_rsvmap);
struct fdt_reserve_entry *e = (struct fdt_reserve_entry *)begin;
+
hdr->totalsize = htobe32(be32toh(hdr->totalsize) +
sizeof(struct fdt_reserve_entry));
hdr->off_dt_struct = htobe32(be32toh(hdr->off_dt_struct) +
diff --git a/src/std.c b/src/std.c
index 036c563..45263c8 100644
--- a/src/std.c
+++ b/src/std.c
@@ -19,9 +19,11 @@
void *memset(void *s, int c, size_t n)
{
char *p = (char *)s;
+
while (n--) {
*p++ = c;
}
+
return s;
}
@@ -31,9 +33,11 @@
size_t strlen(const char *str)
{
const char *p = str;
+
while (*p) {
p++;
}
+
return p - str;
}
diff --git a/src/vm.c b/src/vm.c
index 4a14eae..40aa294 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -76,6 +76,7 @@
void vm_start_vcpu(struct vm *vm, size_t index, ipaddr_t entry, uintreg_t arg)
{
struct vcpu *vcpu = &vm->vcpus[index];
+
if (index < vm->vcpu_count) {
arch_regs_set_pc_arg(&vcpu->regs, entry, arg);
vcpu_on(vcpu);