diff options
author | Tom Rini <trini@konsulko.com> | 2025-05-16 11:05:27 -0600 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2025-05-16 11:05:27 -0600 |
commit | 126a88d49bcae04bbfc0d6723097cd6341355ade (patch) | |
tree | fbcd1e0d77448c1f604b2c2ecb668fdf3efa0c1b /common/cyclic.c | |
parent | 9cd88f0eab903997754b2f9e021156b6084052ee (diff) | |
parent | 6f0a3cd7bcdd4ce25b5ad253a6ebad88d4b94fbe (diff) |
Merge tag 'u-boot-watchdog-20250516' of https://source.denx.de/u-boot/custodians/u-boot-watchdog
CI: https://dev.azure.com/sr0718/u-boot/_build/results?buildId=393&view=results
- make cyclic_(un)register idempotent
Diffstat (limited to 'common/cyclic.c')
-rw-r--r-- | common/cyclic.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/common/cyclic.c b/common/cyclic.c index b695f092f52..ec952a01ee1 100644 --- a/common/cyclic.c +++ b/common/cyclic.c @@ -28,9 +28,23 @@ struct hlist_head *cyclic_get_list(void) return (struct hlist_head *)&gd->cyclic_list; } +static bool cyclic_is_registered(const struct cyclic_info *cyclic) +{ + const struct cyclic_info *c; + + hlist_for_each_entry(c, cyclic_get_list(), list) { + if (c == cyclic) + return true; + } + + return false; +} + void cyclic_register(struct cyclic_info *cyclic, cyclic_func_t func, uint64_t delay_us, const char *name) { + cyclic_unregister(cyclic); + memset(cyclic, 0, sizeof(*cyclic)); /* Store values in struct */ @@ -43,6 +57,9 @@ void cyclic_register(struct cyclic_info *cyclic, cyclic_func_t func, void cyclic_unregister(struct cyclic_info *cyclic) { + if (!cyclic_is_registered(cyclic)) + return; + hlist_del(&cyclic->list); } |