/src/barebox/lib/notifier.c
Line | Count | Source |
1 | | // SPDX-License-Identifier: GPL-2.0-only |
2 | | |
3 | | #include <common.h> |
4 | | #include <linux/list.h> |
5 | | #include <notifier.h> |
6 | | |
7 | | int notifier_chain_register(struct notifier_head *nh, struct notifier_block *n) |
8 | 0 | { |
9 | 0 | list_add_tail(&n->list, &nh->blocks); |
10 | 0 | return 0; |
11 | 0 | } |
12 | | |
13 | | int notifier_chain_unregister(struct notifier_head *nh, struct notifier_block *n) |
14 | 0 | { |
15 | 0 | list_del(&n->list); |
16 | 0 | return 0; |
17 | 0 | } |
18 | | |
19 | | int notifier_call_chain(struct notifier_head *nh, unsigned long val, void *v) |
20 | 0 | { |
21 | 0 | struct notifier_block *entry, *tmp; |
22 | 0 | int ret = NOTIFY_DONE; |
23 | |
|
24 | 0 | list_for_each_entry_safe(entry, tmp, &nh->blocks, list) { |
25 | 0 | ret = entry->notifier_call(entry, val, v); |
26 | 0 | if (ret & NOTIFY_STOP_MASK) |
27 | 0 | break; |
28 | 0 | } |
29 | |
|
30 | 0 | return ret; |
31 | 0 | } |
32 | | |
33 | | /* |
34 | | * Notifier list for code which wants to be called at clock |
35 | | * frequency changes. |
36 | | */ |
37 | | static NOTIFIER_HEAD(clock_notifier_list); |
38 | | |
39 | | /** |
40 | | * clock_register_client - register a client notifier |
41 | | * @nb: notifier block to callback on events |
42 | | */ |
43 | | int clock_register_client(struct notifier_block *nb) |
44 | 0 | { |
45 | 0 | return notifier_chain_register(&clock_notifier_list, nb); |
46 | 0 | } |
47 | | |
48 | | /** |
49 | | * clock_register_client - unregister a client notifier |
50 | | * @nb: notifier block to callback on events |
51 | | */ |
52 | | int clock_unregister_client(struct notifier_block *nb) |
53 | 0 | { |
54 | 0 | return notifier_chain_unregister(&clock_notifier_list, nb); |
55 | 0 | } |
56 | | |
57 | | /** |
58 | | * clock_register_client - notify clients of clock frequency changes |
59 | | * |
60 | | */ |
61 | | int clock_notifier_call_chain(void) |
62 | 0 | { |
63 | 0 | return notifier_call_chain(&clock_notifier_list, 0, NULL); |
64 | 0 | } |