Add more clang-tidy checks.
This adds all the generic checks. There are some more project specific
ones that could be selected but this is a good start and has already
found some lint errors.
Change-Id: I7bb9d9347f5270862c2ff586eb7c86feead9e4bb
diff --git a/.clang-tidy b/.clang-tidy
index 55d135e..f426a64 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -1,2 +1,2 @@
-Checks: 'readability-braces-around-statements'
+Checks: 'readability-*,portability-*,performance-*,misc-*,bugprone-*,modernize-*'
HeaderFilterRegex: '.*'
diff --git a/Makefile b/Makefile
index a41e0c8..fdcfd6c 100644
--- a/Makefile
+++ b/Makefile
@@ -103,8 +103,8 @@
@$(CC) $(COPTS) $(DEP_GEN) -MT $$@ -S -c $(ROOT_DIR)$(1) -o - | \
grep ^DEFINE_OFFSET -A1 | \
grep -v ^--$ | \
- sed 's/^DEFINE_OFFSET__\([^:]*\):/#define \1 \\/g' | \
- sed 's/\.xword//g' > $$@
+ sed 's/^DEFINE_OFFSET__\([^:]*\):/#define \1 \\/' | \
+ sed 's/\.[^\t][^\t]*//' > $$@
endef
#
@@ -166,11 +166,11 @@
# see .clang-format
format:
- find $(ROOT_DIR)src/ -name *.c -o -name *.h | xargs clang-format -style file -i
- find $(ROOT_DIR)inc/ -name *.c -o -name *.h | xargs clang-format -style file -i
+ @find $(ROOT_DIR)src/ -name *.c -o -name *.h | xargs clang-format -style file -i
+ @find $(ROOT_DIR)inc/ -name *.c -o -name *.h | xargs clang-format -style file -i
# see .clang-tidy
tidy:
- find $(ROOT_DIR)src/ -name *.c -exec clang-tidy {} -fix -- -target $(TARGET) $(COPTS) \;
+ @find $(ROOT_DIR)src/ -name *.c -exec clang-tidy {} -fix -- -target $(TARGET) $(COPTS) \;
-include $(patsubst %,%.d,$(GLOBAL_OBJS),$(GLOBAL_OFFSETS))
diff --git a/inc/cpu.h b/inc/cpu.h
index 0dc561b..58df21d 100644
--- a/inc/cpu.h
+++ b/inc/cpu.h
@@ -17,24 +17,24 @@
/* TODO: Update alignment such that cpus are in different cache lines. */
struct cpu {
- struct spinlock lock;
-
struct vcpu *current;
+ /* CPU identifier. Doesn't have to be contiguous. */
+ size_t id;
+
+ /* Pointer to bottom of the stack. */
+ void *stack_bottom;
+
/*
* Enabling/disabling irqs are counted per-cpu. They are enabled when
* the count is zero, and disabled when it's non-zero.
*/
uint32_t irq_disable_count;
+ struct spinlock lock;
+
/* Determines whether or not the cpu is currently on. */
bool is_on;
-
- /* CPU identifier. Doesn't have to be contiguous. */
- size_t id;
-
- /* Pointer to bottom of the stack. */
- void *stack_bottom;
};
void cpu_module_init(void);
@@ -47,7 +47,7 @@
void cpu_off(struct cpu *c);
void vcpu_init(struct vcpu *vcpu, struct vm *vm);
-void vcpu_on(struct vcpu *v);
-void vcpu_off(struct vcpu *v);
+void vcpu_on(struct vcpu *vcpu);
+void vcpu_off(struct vcpu *vcpu);
#endif /* _CPU_H */
diff --git a/inc/mm.h b/inc/mm.h
index 82066cd..9c129d4 100644
--- a/inc/mm.h
+++ b/inc/mm.h
@@ -34,7 +34,7 @@
bool mm_ptable_init(struct mm_ptable *t, int mode);
void mm_ptable_dump(struct mm_ptable *t);
-bool mm_ptable_map(struct mm_ptable *t, vaddr_t vaddr_begin, vaddr_t vaddr_end,
+bool mm_ptable_map(struct mm_ptable *t, vaddr_t begin, vaddr_t end,
paddr_t paddr, int mode);
bool mm_ptable_map_page(struct mm_ptable *t, vaddr_t va, paddr_t pa, int mode);
bool mm_ptable_unmap(struct mm_ptable *t, vaddr_t begin, vaddr_t end, int mode);
diff --git a/src/arch/aarch64/handler.c b/src/arch/aarch64/handler.c
index 8999403..94a9722 100644
--- a/src/arch/aarch64/handler.c
+++ b/src/arch/aarch64/handler.c
@@ -52,6 +52,8 @@
struct hvc_handler_return hvc_handler(size_t arg0, size_t arg1, size_t arg2,
size_t arg3)
{
+ (void)arg3;
+
struct hvc_handler_return ret;
ret.new = NULL;
diff --git a/src/arch/aarch64/mm.c b/src/arch/aarch64/mm.c
index d4898d4..f5dcdf1 100644
--- a/src/arch/aarch64/mm.c
+++ b/src/arch/aarch64/mm.c
@@ -43,7 +43,7 @@
#define STAGE2_WRITETHROUGH 2ull
#define STAGE2_WRITEBACK 3ull
-#define STAGE2_MEMATTR_NORMAL(outer, inner) ((outer << 2) | (inner))
+#define STAGE2_MEMATTR_NORMAL(outer, inner) (((outer) << 2) | (inner))
/* The following stage-2 memory attributes for device memory. */
#define STAGE2_MEMATTR_DEVICE_nGnRnE 0ull
diff --git a/src/arch/aarch64/msr.h b/src/arch/aarch64/msr.h
index 30916db..277ccea 100644
--- a/src/arch/aarch64/msr.h
+++ b/src/arch/aarch64/msr.h
@@ -10,9 +10,11 @@
__v; \
})
-#define write_msr(name, value) \
- do { \
- __asm volatile("msr " #name ", %x0" : : "rZ"((size_t)value)); \
+#define write_msr(name, value) \
+ do { \
+ __asm volatile("msr " #name ", %x0" \
+ : \
+ : "rZ"((size_t)(value))); \
} while (0)
#endif /* _MSR_H */
diff --git a/src/dlog.c b/src/dlog.c
index 38ccc85..5382096 100644
--- a/src/dlog.c
+++ b/src/dlog.c
@@ -163,7 +163,7 @@
/*
* Prints the given format string to the debug log.
*/
-void dlog(const char *str, ...)
+void dlog(const char *fmt, ...)
{
static struct spinlock sl = SPINLOCK_INIT;
const char *p;
@@ -172,11 +172,11 @@
int flags;
char buf[2];
- va_start(args, str);
+ va_start(args, fmt);
sl_lock(&sl);
- for (p = str; *p; p++) {
+ for (p = fmt; *p; p++) {
switch (*p) {
default:
arch_putchar(*p);
diff --git a/src/main.c b/src/main.c
index a23c7e8..e4957fd 100644
--- a/src/main.c
+++ b/src/main.c
@@ -280,7 +280,7 @@
}
/* Fail if it's not a number. */
- if (*it->next < '0' && *it->next > '9') {
+ if (*it->next < '0' || *it->next > '9') {
return false;
}
diff --git a/src/mm.c b/src/mm.c
index 8942ec5..6662bae 100644
--- a/src/mm.c
+++ b/src/mm.c
@@ -105,6 +105,9 @@
*/
static void mm_free_page_pte(pte_t pte, int level, bool sync)
{
+ (void)pte;
+ (void)level;
+ (void)sync;
/* TODO: Implement.
if (!arch_mm_pte_is_present(pte) || level < 1)
return;
@@ -309,6 +312,7 @@
void mm_ptable_defrag(struct mm_ptable *t)
{
/* TODO: Implement. */
+ (void)t;
}
/**