Skip to content

Commit

Permalink
fix(pm): Use Zephyr created device slots.
Browse files Browse the repository at this point in the history
* Avoid overwriting random memory by using
  iterable section created by Zephyr PM.
  • Loading branch information
petejohanson committed Mar 28, 2024
1 parent d0e0ecb commit 41d8180
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 16 deletions.
4 changes: 0 additions & 4 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ set(ZEPHYR_EXTRA_MODULES "${ZMK_EXTRA_MODULES};${CMAKE_CURRENT_SOURCE_DIR}/modul
find_package(Zephyr REQUIRED HINTS ../zephyr)
project(zmk)

if(CONFIG_ZMK_PM_DEVICE_SUSPEND_RESUME)
zephyr_linker_sources(SECTIONS include/linker/zmk-pm-devices.ld)
endif()

zephyr_linker_sources(SECTIONS include/linker/zmk-behaviors.ld)
zephyr_linker_sources(RODATA include/linker/zmk-events.ld)

Expand Down
9 changes: 0 additions & 9 deletions app/include/linker/zmk-pm-devices.ld

This file was deleted.

6 changes: 3 additions & 3 deletions app/src/pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
// TODO: Tweak this to smarter runtime PM of subsystems on sleep.

#ifdef CONFIG_ZMK_PM_DEVICE_SUSPEND_RESUME
TYPE_SECTION_START_EXTERN(const struct device *, zmk_pm_device_slots);
TYPE_SECTION_START_EXTERN(const struct device *, pm_device_slots);

#if !defined(CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE)
/* Number of devices successfully suspended. */
Expand Down Expand Up @@ -57,7 +57,7 @@ int zmk_pm_suspend_devices(void) {
return ret;
}

TYPE_SECTION_START(zmk_pm_device_slots)[zmk_num_susp] = dev;
TYPE_SECTION_START(pm_device_slots)[zmk_num_susp] = dev;
zmk_num_susp++;
}

Expand All @@ -66,7 +66,7 @@ int zmk_pm_suspend_devices(void) {

void zmk_pm_resume_devices(void) {
for (int i = (zmk_num_susp - 1); i >= 0; i--) {
pm_device_action_run(TYPE_SECTION_START(zmk_pm_device_slots)[i], PM_DEVICE_ACTION_RESUME);
pm_device_action_run(TYPE_SECTION_START(pm_device_slots)[i], PM_DEVICE_ACTION_RESUME);
}

zmk_num_susp = 0;
Expand Down

0 comments on commit 41d8180

Please sign in to comment.