Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(battery): prevent bus fault when battery does not exist #2099

Merged
merged 1 commit into from
Jan 9, 2024

Conversation

xudongzheng
Copy link
Contributor

zmk_battery_start_reporting() may be called from battery_event_listener(), which will result in a bus fault when attempting to read a battery that does not exist such as on a dongle.

zmk_battery_start_reporting() may be called from battery_event_listener(), which
will result in a bus fault when attempting to read a battery that does not exist
such as on a dongle.
@xudongzheng xudongzheng requested a review from a team as a code owner January 6, 2024 20:04
@@ -87,7 +87,9 @@ static void zmk_battery_timer(struct k_timer *timer) {
K_TIMER_DEFINE(battery_timer, zmk_battery_timer, NULL);

static void zmk_battery_start_reporting() {
k_timer_start(&battery_timer, K_NO_WAIT, K_SECONDS(CONFIG_ZMK_BATTERY_REPORT_INTERVAL));
if (device_is_ready(battery)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable, although I'm surprised that startup even succeeds when the init function below this fails with an error code using this same check.

Copy link
Contributor Author

@xudongzheng xudongzheng Jan 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the early return in the init function prevents zmk_battery_start_reporting() from being called on startup.

Also Zephyr doesn't actually handle the SYS_INIT() return values.

@petejohanson petejohanson merged commit 6bf4870 into zmkfirmware:main Jan 9, 2024
45 checks passed
@xudongzheng xudongzheng deleted the battery-fault-pr branch January 9, 2024 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants