Skip to content

Commit de976a5

Browse files
visitorckwG36maid
authored andcommitted
Constify error_desc and perror
The error_desc array and the perror pointer are never modified after initialization. Marking them as const moves the data to the read-only section, improving safety. Before: $ riscv-none-elf-size ./build/kernel/error.o text data bss dec hex filename 398 172 0 570 23a ./build/kernel/error.o After: $ riscv-none-elf-size ./build/kernel/error.o text data bss dec hex filename 570 0 0 570 23a ./build/kernel/error.o
1 parent d1ab25b commit de976a5

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

include/private/error.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ struct error_code {
3939
char *const desc;
4040
};
4141

42-
extern struct error_code *perror;
42+
extern const struct error_code * const perror;

kernel/error.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "private/error.h"
44

55
/* Ordered by enum value for quick linear search */
6-
static struct error_code error_desc[] = {
6+
static const struct error_code error_desc[] = {
77
{ERR_OK, "no error"},
88
{ERR_FAIL, "generic failure"},
99

@@ -35,4 +35,4 @@ static struct error_code error_desc[] = {
3535
{ERR_UNKNOWN, "unknown error"},
3636
};
3737

38-
struct error_code *perror = error_desc;
38+
const struct error_code * const perror = error_desc;

0 commit comments

Comments
 (0)