From 23cbdcc9711ad7ca211385f2263a1d51e5fbffd2 Mon Sep 17 00:00:00 2001 From: Travis Geiselbrecht Date: Sun, 5 Oct 2025 15:27:43 -0700 Subject: [PATCH] [ubsan] switch external array declarations to a proper array This fixes a ubsan warning where it thinks you are walking off the end of a symbol. No functional change. --- app/app.c | 12 ++++++------ dev/driver.c | 8 ++++---- top/init.c | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/app.c b/app/app.c index a48bb2cf..e78701a7 100644 --- a/app/app.c +++ b/app/app.c @@ -13,8 +13,8 @@ #include #include -extern const struct app_descriptor __start_apps __WEAK; -extern const struct app_descriptor __stop_apps __WEAK; +extern const struct app_descriptor __start_apps[] __WEAK; +extern const struct app_descriptor __stop_apps[] __WEAK; static void start_app(const struct app_descriptor *app, bool detach); @@ -23,13 +23,13 @@ void apps_init(void) { const struct app_descriptor *app; /* call all the init routines */ - for (app = &__start_apps; app != &__stop_apps; app++) { + for (app = __start_apps; app != __stop_apps; app++) { if (app->init) app->init(app); } /* start any that want to start on boot */ - for (app = &__start_apps; app != &__stop_apps; app++) { + for (app = __start_apps; app != __stop_apps; app++) { if (app->entry && (app->flags & APP_FLAG_NO_AUTOSTART) == 0) { start_app(app, true); } @@ -67,7 +67,7 @@ status_t app_start_by_name(const char *name, bool detached) { const struct app_descriptor *app; /* find the app and call it */ - for (app = &__start_apps; app != &__stop_apps; app++) { + for (app = __start_apps; app != __stop_apps; app++) { if (!strcmp(app->name, name)) { start_app(app, detached); return NO_ERROR; @@ -80,7 +80,7 @@ status_t app_start_by_name(const char *name, bool detached) { static void list_apps(void) { const struct app_descriptor *app; - for (app = &__start_apps; app != &__stop_apps; app++) { + for (app = __start_apps; app != __stop_apps; app++) { printf("%s\n", app->name); } } diff --git a/dev/driver.c b/dev/driver.c index 9599b1db..cedb56c7 100644 --- a/dev/driver.c +++ b/dev/driver.c @@ -12,13 +12,13 @@ #include /* static list of devices constructed with DEVICE_INSTANCE macros */ -extern struct device __start_devices __WEAK; -extern struct device __stop_devices __WEAK; +extern struct device __start_devices[] __WEAK; +extern struct device __stop_devices[] __WEAK; status_t device_init_all(void) { status_t res = NO_ERROR; - for (struct device *dev = &__start_devices; dev != &__stop_devices; dev++) { + for (struct device *dev = __start_devices; dev != __stop_devices; dev++) { if (dev->flags & DEVICE_FLAG_AUTOINIT) { status_t code = device_init(dev); @@ -37,7 +37,7 @@ status_t device_init_all(void) { status_t device_fini_all(void) { status_t res = NO_ERROR; - for (struct device *dev = &__start_devices; dev != &__stop_devices; dev++) { + for (struct device *dev = __start_devices; dev != __stop_devices; dev++) { status_t code = device_fini(dev); if (code < 0) { diff --git a/top/init.c b/top/init.c index c75287f1..0bbe55b2 100644 --- a/top/init.c +++ b/top/init.c @@ -25,8 +25,8 @@ #define EARLIEST_TRACE_LEVEL LK_INIT_LEVEL_TARGET_EARLY #endif -extern const struct lk_init_struct __start_lk_init __WEAK; -extern const struct lk_init_struct __stop_lk_init __WEAK; +extern const struct lk_init_struct __start_lk_init[] __WEAK; +extern const struct lk_init_struct __stop_lk_init[] __WEAK; void lk_init_level(enum lk_init_flags required_flag, uint16_t start_level, uint16_t stop_level) { LTRACEF("flags %#x, start_level %#hx, stop_level %#hx\n", @@ -41,7 +41,7 @@ void lk_init_level(enum lk_init_flags required_flag, uint16_t start_level, uint1 const struct lk_init_struct *found = NULL; bool seen_last = false; - for (const struct lk_init_struct *ptr = &__start_lk_init; ptr != &__stop_lk_init; ptr++) { + for (const struct lk_init_struct *ptr = __start_lk_init; ptr != __stop_lk_init; ptr++) { LTRACEF("looking at %p (%s) level %#x, flags %#x, seen_last %d\n", ptr, ptr->name, ptr->level, ptr->flags, seen_last); if (ptr == last)