aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2022-01-07 20:50:16 +0200
committerKimplul <kimi.h.kuparinen@gmail.com>2022-01-07 20:50:16 +0200
commitacc26f85f32c68a51e5cc7b613cd0ea0b0630505 (patch)
tree90d68a8292360f0796509f1febc7b66b0a53f4aa
parent8d90fb3e4a5d02df75584016563ef84901967b9f (diff)
downloadkmi-acc26f85f32c68a51e5cc7b613cd0ea0b0630505.tar.gz
kmi-acc26f85f32c68a51e5cc7b613cd0ea0b0630505.zip
Use #if defined(...) when not guard clause
-rw-r--r--arch/riscv64/include/csr.h2
-rw-r--r--arch/riscv64/kernel/vmem.c4
-rw-r--r--common/bits.c6
-rw-r--r--common/debug.c6
-rw-r--r--common/fdt.c4
-rw-r--r--common/initrd.c20
-rw-r--r--include/apos/debug.h6
-rw-r--r--include/apos/initrd.h8
-rw-r--r--include/apos/types.h2
-rw-r--r--include/arch/vmem.h4
-rw-r--r--include/libfdt.h6
-rw-r--r--lib/fdt_dbg.c2
-rwxr-xr-xscripts/gen-deps4
13 files changed, 37 insertions, 37 deletions
diff --git a/arch/riscv64/include/csr.h b/arch/riscv64/include/csr.h
index 52db9c1..43c365b 100644
--- a/arch/riscv64/include/csr.h
+++ b/arch/riscv64/include/csr.h
@@ -42,7 +42,7 @@
#define SSTATUS_SPP (1 << 8)
/* directly lifted from Linux:/arch/riscv/include/asm/asm.h:9-13 */
-#ifdef __ASSEMBLY__
+#if defined(__ASSEMBLY__)
#define __ASM_STR(x) x
#else
#define __ASM_STR(x) #x
diff --git a/arch/riscv64/kernel/vmem.c b/arch/riscv64/kernel/vmem.c
index 0424948..9fd42dd 100644
--- a/arch/riscv64/kernel/vmem.c
+++ b/arch/riscv64/kernel/vmem.c
@@ -175,8 +175,8 @@ void populate_root_branch(struct vm_branch *b)
b->leaf[IO_PAGE] = (struct vm_branch *)to_pte(0, flags);
}
-#ifdef DEBUG
-int setup_kernel_io(struct vm_branch *b, vm_t paddr)
+#if defined(DEBUG)
+vm_t setup_kernel_io(struct vm_branch *b, vm_t paddr)
{
/* assume Sv39 for now */
pm_t gigapage = paddr / MM_GPAGE_SIZE;
diff --git a/common/bits.c b/common/bits.c
index ca99ed2..b9814f6 100644
--- a/common/bits.c
+++ b/common/bits.c
@@ -4,13 +4,13 @@
#include <apos/builtin.h>
#undef __bswap16
-__weak uint16_t __bswap16(uint16_t u)
+__weak uint16_t __bswap16(const uint16_t u)
{
return (u & 0xff00) >> 8 | (u & 0x00ff) << 8;
}
#undef __bswap32
-__weak uint32_t __bswap32(uint32_t u)
+__weak uint32_t __bswap32(const uint32_t u)
{
return (u & 0xff000000) >> 24 |
(u & 0x00ff0000) >> 8 |
@@ -19,7 +19,7 @@ __weak uint32_t __bswap32(uint32_t u)
}
#undef __bswap64
-__weak uint64_t __bswap64(uint64_t u)
+__weak uint64_t __bswap64(const uint64_t u)
{
return (u & 0xff00000000000000ULL) >> 56 |
(u & 0x00ff000000000000ULL) >> 40 |
diff --git a/common/debug.c b/common/debug.c
index aab5abc..330a3ed 100644
--- a/common/debug.c
+++ b/common/debug.c
@@ -7,13 +7,13 @@
#include <libfdt.h>
#include <stdarg.h>
-#ifdef DEBUG
+#if defined(DEBUG)
static struct dbg_info {
pm_t dbg_ptr;
enum serial_dev dev;
} dbg_info = (struct dbg_info){0};
-void init_dbg(void *fdt)
+void init_dbg(const void *fdt)
{
dbg_info = dbg_from_fdt(fdt);
}
@@ -88,7 +88,7 @@ static enum serial_dev __serial_dev_enum(const char *dev_name)
return -1;
}
-struct dbg_info dbg_from_fdt(void *fdt)
+struct dbg_info dbg_from_fdt(const void *fdt)
{
int chosen_offset = fdt_path_offset(fdt, "/chosen");
const char *stdout = fdt_getprop(fdt, chosen_offset, "stdout-path", NULL);
diff --git a/common/fdt.c b/common/fdt.c
index f76ad64..7cec3a4 100644
--- a/common/fdt.c
+++ b/common/fdt.c
@@ -1,6 +1,6 @@
#include <libfdt.h>
-struct cell_info get_cellinfo(void *fdt, int offset)
+struct cell_info get_cellinfo(const void *fdt, const int offset)
{
return (struct cell_info){
fdt_size_cells(fdt, offset),
@@ -9,7 +9,7 @@ struct cell_info get_cellinfo(void *fdt, int offset)
}
/* how "reg" is interpreted depends on the parent node */
-struct cell_info get_reginfo(void *fdt, const char *path)
+struct cell_info get_reginfo(const void *fdt, const char *path)
{
const char *i = strrchr(path, '/');
if(!i)
diff --git a/common/initrd.c b/common/initrd.c
index 691685a..7b5fa6c 100644
--- a/common/initrd.c
+++ b/common/initrd.c
@@ -31,7 +31,7 @@ static struct cpio_header *__next_entry(struct cpio_header *cp)
return (struct cpio_header *)(((char *)cp) + blen + tlen);
}
-static struct cpio_header *__find_file(char *c, char* fname, size_t fname_len)
+static struct cpio_header *__find_file(const char *c, const char* fname, size_t fname_len)
{
struct cpio_header *cp = (struct cpio_header *)c;
for(; cp; cp = __next_entry(cp)){
@@ -53,7 +53,7 @@ static struct cpio_header *__find_file(char *c, char* fname, size_t fname_len)
return 0;
}
-pm_t get_initrdtop(void *fdt)
+pm_t get_initrdtop(const void *fdt)
{
int chosen_offset = fdt_path_offset(fdt, "/chosen");
struct cell_info ci = get_cellinfo(fdt, chosen_offset);
@@ -65,10 +65,10 @@ pm_t get_initrdtop(void *fdt)
return (pm_t)__va(fdt_load_int_ptr(ci.addr_cells, initrd_end_ptr));
}
-pm_t get_initrdbase(void *fdt)
+pm_t get_initrdbase(const void *fdt)
{
- int chosen_offset = fdt_path_offset(fdt, "/chosen");
- struct cell_info ci = get_cellinfo(fdt, chosen_offset);
+ const int chosen_offset = fdt_path_offset(fdt, "/chosen");
+ const struct cell_info ci = get_cellinfo(fdt, chosen_offset);
void *initrd_base_ptr = (void *)fdt_getprop(fdt, chosen_offset,
"linux,initrd-start", NULL);
@@ -79,14 +79,14 @@ pm_t get_initrdbase(void *fdt)
static char init_n[] = "init";
static size_t init_nlen = ARRAY_SIZE(init_n) - 1; /* ignore trailing NULL */
-size_t get_init_size(void *fdt)
+size_t get_init_size(const void *fdt)
{
char *c = (char *)get_initrdbase(fdt);
struct cpio_header *cp = __find_file(c, init_n, init_nlen);
return convnum(cp->c_filesize, 8, 16);
}
-vm_t get_init_base(void *fdt)
+vm_t get_init_base(const void *fdt)
{
char *c = (char *)get_initrdbase(fdt);
struct cpio_header *cp = __find_file(c, init_n, init_nlen);
@@ -94,11 +94,11 @@ vm_t get_init_base(void *fdt)
return ((vm_t)cp) + align_up(sizeof(struct cpio_header) + name_len, 4);
}
-void move_init(void *fdt, void *target)
+void move_init(const void *fdt, void *target)
{
- char *c = (char *)get_initrdbase(fdt);
+ const char *c = (const char *)get_initrdbase(fdt);
- struct cpio_header *cp = __find_file(c, init_n, init_nlen);
+ const struct cpio_header *cp = __find_file(c, init_n, init_nlen);
size_t name_len = convnum(cp->c_namesize, 8, 16);
size_t file_len = convnum(cp->c_filesize, 8, 16);
diff --git a/include/apos/debug.h b/include/apos/debug.h
index a9e5d46..ec591ef 100644
--- a/include/apos/debug.h
+++ b/include/apos/debug.h
@@ -5,7 +5,7 @@
#include <apos/pmem.h>
#include <arch/vmem.h>
-#ifdef DEBUG
+#if defined(DEBUG)
enum serial_dev {
/* only the NS16550A and compatible at the moment */
NS16550A,
@@ -13,13 +13,13 @@ enum serial_dev {
void __fmt(1, 2) dbg(const char *fmt, ...);
-void init_dbg(void *fdt);
+void init_dbg(const void *fdt);
void setup_dmap_dbg();
void setup_io_dbg(struct vm_branch *b);
void setup_dbg(pm_t pt, enum serial_dev dev);
-struct dbg_info dbg_from_fdt(void *fdt);
+struct dbg_info dbg_from_fdt(const void *fdt);
#define COMMON_FORMAT "[%s] %s:%d\n\t"
#define COMMON_ARGS(s) s, __FILE__, __LINE__
diff --git a/include/apos/initrd.h b/include/apos/initrd.h
index 4b28ba8..17ed94c 100644
--- a/include/apos/initrd.h
+++ b/include/apos/initrd.h
@@ -5,10 +5,10 @@
#include <apos/pmem.h>
#include <apos/vmem.h>
-size_t get_init_size(void *fdt);
-vm_t get_init_base(void *fdt);
+size_t get_init_size(const void *fdt);
+vm_t get_init_base(const void *fdt);
-pm_t get_initrdtop(void *fdt);
-pm_t get_initrdbase(void *fdt);
+pm_t get_initrdtop(const void *fdt);
+pm_t get_initrdbase(const void *fdt);
#endif /* APOS_INITRD_H */
diff --git a/include/apos/types.h b/include/apos/types.h
index 2d9bef1..9b90611 100644
--- a/include/apos/types.h
+++ b/include/apos/types.h
@@ -58,7 +58,7 @@ typedef intmax_t ssize_t;
#define SCHAR_MIN (-__SCHAR_MAX - 1)
#define UCHAR_MAX (2 * __SCHAR_MAX__ - 1)
-#ifdef __CHAR_UNSIGNED__
+#if defined(__CHAR_UNSIGNED__)
#define CHAR_MIN 0
#define CHAR_MAX UCHAR_MAX
#else
diff --git a/include/arch/vmem.h b/include/arch/vmem.h
index 17fa13d..ddb0e54 100644
--- a/include/arch/vmem.h
+++ b/include/arch/vmem.h
@@ -18,8 +18,8 @@ void flush_tlb_all();
void populate_root_branch(struct vm_branch *b);
struct vm_branch *init_vmem(void *fdt);
-#ifdef DEBUG
-stat_t setup_kernel_io(struct vm_branch *b, vm_t paddr);
+#if defined(DEBUG)
+vm_t setup_kernel_io(struct vm_branch *b, vm_t paddr);
#endif
#endif /* APOS_ARCH_PAGES_H */
diff --git a/include/libfdt.h b/include/libfdt.h
index 304abb7..602cdcb 100644
--- a/include/libfdt.h
+++ b/include/libfdt.h
@@ -9,11 +9,11 @@ struct cell_info {
uint32_t addr_cells;
};
-struct cell_info get_cellinfo(void *fdt, int offset);
-struct cell_info get_reginfo(void *fdt, const char *path);
+struct cell_info get_cellinfo(const void *fdt, const int offset);
+struct cell_info get_reginfo(const void *fdt, const char *path);
#if defined(DEBUG)
-void __dbg_fdt(void *fdt, int node_offset, int depth);
+void __dbg_fdt(const void *fdt, int node_offset, int depth);
#define dbg_fdt(fdt) __dbg_fdt(fdt, 0, 0)
#else
#define dbg_fdt(...)
diff --git a/lib/fdt_dbg.c b/lib/fdt_dbg.c
index 1dd8007..aa4f1fe 100644
--- a/lib/fdt_dbg.c
+++ b/lib/fdt_dbg.c
@@ -89,7 +89,7 @@ static void __print_prop_value(const void *data, int len)
}
}
-void __dbg_fdt(void *fdt, int node_offset, int depth)
+void __dbg_fdt(const void *fdt, int node_offset, int depth)
{
int node = 0;
fdt_for_each_subnode(node, fdt, node_offset){
diff --git a/scripts/gen-deps b/scripts/gen-deps
index bdc1626..bcfb15d 100755
--- a/scripts/gen-deps
+++ b/scripts/gen-deps
@@ -22,8 +22,8 @@ genrule () {
gencommon "${1}"
echo " \$(COMPILE) -c \$< -o \$@" >> deps.mk
- echo "${lint}: ${s}" >> deps.mk
- echo " \$(LINT) -c \$<" >> deps.mk
+ echo "${lint}: ${s}" >> deps.mk
+ echo " \$(LINT) -c \$< -o /dev/null" >> deps.mk
}
case "${1}" in