Merge branch 'for-linus' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/jikos...
[muen/linux.git] / kernel / livepatch / core.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LIVEPATCH_CORE_H
3 #define _LIVEPATCH_CORE_H
4
5 #include <linux/livepatch.h>
6
7 extern struct mutex klp_mutex;
8
9 static inline bool klp_is_object_loaded(struct klp_object *obj)
10 {
11         return !obj->name || obj->mod;
12 }
13
14 static inline int klp_pre_patch_callback(struct klp_object *obj)
15 {
16         int ret = 0;
17
18         if (obj->callbacks.pre_patch)
19                 ret = (*obj->callbacks.pre_patch)(obj);
20
21         obj->callbacks.post_unpatch_enabled = !ret;
22
23         return ret;
24 }
25
26 static inline void klp_post_patch_callback(struct klp_object *obj)
27 {
28         if (obj->callbacks.post_patch)
29                 (*obj->callbacks.post_patch)(obj);
30 }
31
32 static inline void klp_pre_unpatch_callback(struct klp_object *obj)
33 {
34         if (obj->callbacks.pre_unpatch)
35                 (*obj->callbacks.pre_unpatch)(obj);
36 }
37
38 static inline void klp_post_unpatch_callback(struct klp_object *obj)
39 {
40         if (obj->callbacks.post_unpatch_enabled &&
41             obj->callbacks.post_unpatch)
42                 (*obj->callbacks.post_unpatch)(obj);
43
44         obj->callbacks.post_unpatch_enabled = false;
45 }
46
47 #endif /* _LIVEPATCH_CORE_H */