refactor(core): the display driver functions' API has been reviewed. The data types have been adapted to fit the actual data passed/used/returned. Since the backlight driver has undergone the similar change, the display driver code has been adapted to respect the changes.
What changed, and why it matters
This commit is a straightforward code cleanup (refactor) in the Trezor firmware's display driver. It changes the data types used for backlight levels from signed integers (int) to unsigned 8-bit values (uint8_t), and changes the display_set_backlight function to return true/false (bool) instead of the brightness level. There is no indication this fixes a security bug or introduces a vulnerability.
No security action required. Treat as normal maintenance/refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors the display/backlight driver API across multiple platform-specific implementations. Key changes: display_set_backlight now returns bool (success/failure) instead of int (set level); backlight level parameters and stored state change from int to uint8_t; syscall stubs and dispatch updated to match. The unix driver drops an always-true range check (level >= 0 && level <= 255) because uint8_t is inherently 0-255. No functional security behavior changes are evident.
Changed components
core/embed/io/display driver (multiple platforms)core/embed/sys/syscall/stm32/syscall_dispatch.ccore/embed/sys/syscall/stm32/syscall_stubs.cInspect captured patch +36 / −36
diff --git a/core/embed/io/display/display_utils.c b/core/embed/io/display/display_utils.c
index c2e7384b1..647f19b1b 100644
--- a/core/embed/io/display/display_utils.c
+++ b/core/embed/io/display/display_utils.c
@@ -22,7 +22,7 @@
#include <io/display.h>
#include <sys/systick.h>
-void display_fade(int start, int end, int delay) {
+void display_fade(uint8_t start, uint8_t end, int delay) {
#ifdef USE_BACKLIGHT
if (display_get_backlight() == end) {
return;
diff --git a/core/embed/io/display/inc/io/display.h b/core/embed/io/display/inc/io/display.h
index 264d4e649..fb04fba8e 100644
--- a/core/embed/io/display/inc/io/display.h
+++ b/core/embed/io/display/inc/io/display.h
@@ -80,14 +80,14 @@ void display_set_unpriv_access(bool unpriv);
//
// The default backligt level is 0. Without settings it
// to some higher value the displayed pixels are not visible.
-// Beware that his also applies to the emulator.
+// Beware that this also applies to the emulator.
//
-// Returns the set level (usually the same value or the
-// closest value to the `level` argument)
-int display_set_backlight(int level);
+// Returns the boolean value. "True" - successful function execution.
+// "False" - a problem occurred.
+bool display_set_backlight(uint8_t level);
// Gets current display level ranging from 0 (off)..255 (maximum).
-int display_get_backlight(void);
+uint8_t display_get_backlight(void);
// Sets the display orientation.
//
diff --git a/core/embed/io/display/inc/io/display_utils.h b/core/embed/io/display/inc/io/display_utils.h
index 810a749ee..ca8c79815 100644
--- a/core/embed/io/display/inc/io/display_utils.h
+++ b/core/embed/io/display/inc/io/display_utils.h
@@ -25,7 +25,7 @@
* @param end Target backlight level (0-255)
* @param delay Total duration of the fade effect in milliseconds
*/
-void display_fade(int start, int end, int delay);
+void display_fade(uint8_t start, uint8_t end, int delay);
/**
* @brief Starts recording the display output to files
diff --git a/core/embed/io/display/ltdc_dsi/display_driver.c b/core/embed/io/display/ltdc_dsi/display_driver.c
index 7da367f5d..65941024b 100644
--- a/core/embed/io/display/ltdc_dsi/display_driver.c
+++ b/core/embed/io/display/ltdc_dsi/display_driver.c
@@ -442,11 +442,11 @@ void display_deinit(display_content_mode_t mode) {
memset(drv, 0, sizeof(display_driver_t));
}
-int display_set_backlight(int level) {
+bool display_set_backlight(uint8_t level) {
display_driver_t *drv = &g_display_driver;
if (!drv->initialized) {
- return 0;
+ return false;
}
#ifdef USE_BACKLIGHT
@@ -458,11 +458,11 @@ int display_set_backlight(int level) {
#else
// Just emulation, not doing anything
drv->backlight_level = level;
- return level;
+ return true;
#endif
}
-int display_get_backlight(void) {
+uint8_t display_get_backlight(void) {
display_driver_t *drv = &g_display_driver;
if (!drv->initialized) {
diff --git a/core/embed/io/display/ltdc_dsi/display_internal.h b/core/embed/io/display/ltdc_dsi/display_internal.h
index ec92e195f..e5db3f4a6 100644
--- a/core/embed/io/display/ltdc_dsi/display_internal.h
+++ b/core/embed/io/display/ltdc_dsi/display_internal.h
@@ -52,7 +52,7 @@ typedef struct {
// Current display orientation (0, 90, 180, 270)
int orientation_angle;
// Current backlight level ranging from 0 to 255
- int backlight_level;
+ uint8_t backlight_level;
// The current frame buffer selector
DSI_HandleTypeDef hlcd_dsi;
diff --git a/core/embed/io/display/st-7789/display_driver.c b/core/embed/io/display/st-7789/display_driver.c
index b6777f5bc..3e1e5179c 100644
--- a/core/embed/io/display/st-7789/display_driver.c
+++ b/core/embed/io/display/st-7789/display_driver.c
@@ -131,11 +131,11 @@ void display_deinit(display_content_mode_t mode) {
drv->initialized = false;
}
-int display_set_backlight(int level) {
+bool display_set_backlight(uint8_t level) {
display_driver_t* drv = &g_display_driver;
if (!drv->initialized) {
- return 0;
+ return false;
}
#ifndef BOARDLOADER
@@ -148,7 +148,7 @@ int display_set_backlight(int level) {
return backlight_set(level);
}
-int display_get_backlight(void) { return backlight_get(); }
+uint8_t display_get_backlight(void) { return backlight_get(); }
int display_set_orientation(int angle) {
display_driver_t* drv = &g_display_driver;
diff --git a/core/embed/io/display/stm32f429i-disc1/display_driver.c b/core/embed/io/display/stm32f429i-disc1/display_driver.c
index d4ac62a33..fa2330788 100644
--- a/core/embed/io/display/stm32f429i-disc1/display_driver.c
+++ b/core/embed/io/display/stm32f429i-disc1/display_driver.c
@@ -42,7 +42,7 @@ typedef struct {
// Current display orientation (0, 90, 180, 270)
int orientation_angle;
// Current backlight level ranging from 0 to 255
- int backlight_level;
+ uint8_t backlight_level;
} display_driver_t;
// Display driver instance
@@ -83,19 +83,19 @@ void display_deinit(display_content_mode_t mode) {
drv->initialized = false;
}
-int display_set_backlight(int level) {
+bool display_set_backlight(uint8_t level) {
display_driver_t *drv = &g_display_driver;
if (!drv->initialized) {
- return 0;
+ return false;
}
// Just emulation, not doing anything
drv->backlight_level = level;
- return level;
+ return true;
}
-int display_get_backlight(void) {
+uint8_t display_get_backlight(void) {
display_driver_t *drv = &g_display_driver;
if (!drv->initialized) {
diff --git a/core/embed/io/display/unix/display_driver.c b/core/embed/io/display/unix/display_driver.c
index 44c13f4d5..677afaad3 100644
--- a/core/embed/io/display/unix/display_driver.c
+++ b/core/embed/io/display/unix/display_driver.c
@@ -69,7 +69,7 @@ typedef struct {
// Current display orientation (0 or 180)
int orientation_angle;
// Current backlight level ranging from 0 to 255
- int backlight_level;
+ uint8_t backlight_level;
SDL_Window *window;
SDL_Renderer *renderer;
@@ -229,26 +229,26 @@ void display_deinit(display_content_mode_t mode) {
drv->initialized = false;
}
-int display_set_backlight(int level) {
+bool display_set_backlight(uint8_t level) {
display_driver_t *drv = &g_display_driver;
if (!drv->initialized) {
- return 0;
+ return false;
}
#if !USE_BACKLIGHT
level = 255;
#endif
- if (drv->backlight_level != level && level >= 0 && level <= 255) {
+ if (drv->backlight_level != level) {
drv->backlight_level = level;
display_refresh();
}
- return drv->backlight_level;
+ return true;
}
-int display_get_backlight(void) {
+uint8_t display_get_backlight(void) {
display_driver_t *drv = &g_display_driver;
if (!drv->initialized) {
diff --git a/core/embed/io/display/vg-2864/display_driver.c b/core/embed/io/display/vg-2864/display_driver.c
index 4f9992fb8..3f4896f36 100644
--- a/core/embed/io/display/vg-2864/display_driver.c
+++ b/core/embed/io/display/vg-2864/display_driver.c
@@ -67,7 +67,7 @@ typedef struct {
// Current display orientation (0 or 180)
int orientation_angle;
// Current backlight level ranging from 0 to 255
- int backlight_level;
+ uint8_t backlight_level;
} display_driver_t;
// Display driver instance
@@ -340,18 +340,18 @@ void display_set_unpriv_access(bool unpriv) {
}
#endif // USE_TRUSTZONE
-int display_set_backlight(int level) {
+bool display_set_backlight(uint8_t level) {
display_driver_t *drv = &g_display_driver;
if (!drv->initialized) {
- return 0;
+ return false;
}
drv->backlight_level = 255;
- return drv->backlight_level;
+ return true;
}
-int display_get_backlight(void) {
+uint8_t display_get_backlight(void) {
display_driver_t *drv = &g_display_driver;
if (!drv->initialized) {
diff --git a/core/embed/sys/syscall/stm32/syscall_dispatch.c b/core/embed/sys/syscall/stm32/syscall_dispatch.c
index 3b845c92b..145f1d577 100644
--- a/core/embed/sys/syscall/stm32/syscall_dispatch.c
+++ b/core/embed/sys/syscall/stm32/syscall_dispatch.c
@@ -213,7 +213,7 @@ __attribute((no_stack_protector)) void syscall_handler(uint32_t *args,
} break;
case SYSCALL_DISPLAY_SET_BACKLIGHT: {
- int level = (int)args[0];
+ uint8_t level = (uint8_t)args[0];
args[0] = display_set_backlight(level);
} break;
diff --git a/core/embed/sys/syscall/stm32/syscall_stubs.c b/core/embed/sys/syscall/stm32/syscall_stubs.c
index fac5e44a3..77d0d313b 100644
--- a/core/embed/sys/syscall/stm32/syscall_stubs.c
+++ b/core/embed/sys/syscall/stm32/syscall_stubs.c
@@ -166,12 +166,12 @@ void notify_send(notification_event_t event) {
#include <io/display.h>
-int display_set_backlight(int level) {
- return (int)syscall_invoke1((uint32_t)level, SYSCALL_DISPLAY_SET_BACKLIGHT);
+bool display_set_backlight(uint8_t level) {
+ return (bool)syscall_invoke1((uint32_t)level, SYSCALL_DISPLAY_SET_BACKLIGHT);
}
-int display_get_backlight(void) {
- return (int)syscall_invoke0(SYSCALL_DISPLAY_GET_BACKLIGHT);
+uint8_t display_get_backlight(void) {
+ return (uint8_t)syscall_invoke0(SYSCALL_DISPLAY_GET_BACKLIGHT);
}
int display_set_orientation(int angle) {
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.