golioth / golioth-zephyr-sdk

Golioth SDK For Zephyr
https://www.golioth.io
Apache License 2.0
66 stars 19 forks source link

samples: dfu: ignore new 'desired' events when downloading has started #316

Closed mniestroj closed 1 year ago

mniestroj commented 1 year ago

At the point when 'desired' firmare information was received, subsequent operations in golioth_desired_update() callback modify data (like dfu->version) that is used by 'main' thread in the next steps following release of sem_downloading semaphore.

When a second (or next) 'desired' firmware event is received, then 'dfu->version' is already in use by 'main' thread and modifying it (e.g. with a call to golioth_fw_desired_parse()) creates a race condition of accessing dfu->version from multiple threads.

Make sure that once firmware downloading has started, there will be no more attempts to modify shared (between multiple threads) data like the desired version as well as the flash partition (by accessing struct flash_img_context and calling boot_request_upgrade()).

Note that even if new 'desired' manifest might include new firmware version (as compared to the previous one that was received), this case is unlikely (two different manifests would have to be received in very short time window) and such newer firmware will be handled during next boot (after firmware updates to intermediate version) anyway.

github-actions[bot] commented 1 year ago

Visit the preview URL for this PR (updated for commit 79c7cba):

https://golioth-zephyr-sdk-doxygen-dev--pr316-sample-dfu-suppr-8pg4fdz0.web.app

(expires Tue, 15 Nov 2022 16:21:35 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: a389eefadf4b4b68a539327b3459dd66c142cf49