livepatch: Correctly call klp_post_unpatch_callback() in error paths
[sfrench/cifs-2.6.git] / kernel / livepatch / core.h
1 #ifndef _LIVEPATCH_CORE_H
2 #define _LIVEPATCH_CORE_H
3
4 #include <linux/livepatch.h>
5
6 extern struct mutex klp_mutex;
7
8 static inline bool klp_is_object_loaded(struct klp_object *obj)
9 {
10         return !obj->name || obj->mod;
11 }
12
13 static inline int klp_pre_patch_callback(struct klp_object *obj)
14 {
15         int ret = 0;
16
17         if (obj->callbacks.pre_patch)
18                 ret = (*obj->callbacks.pre_patch)(obj);
19
20         obj->callbacks.post_unpatch_enabled = !ret;
21
22         return ret;
23 }
24
25 static inline void klp_post_patch_callback(struct klp_object *obj)
26 {
27         if (obj->callbacks.post_patch)
28                 (*obj->callbacks.post_patch)(obj);
29 }
30
31 static inline void klp_pre_unpatch_callback(struct klp_object *obj)
32 {
33         if (obj->callbacks.pre_unpatch)
34                 (*obj->callbacks.pre_unpatch)(obj);
35 }
36
37 static inline void klp_post_unpatch_callback(struct klp_object *obj)
38 {
39         if (obj->callbacks.post_unpatch_enabled &&
40             obj->callbacks.post_unpatch)
41                 (*obj->callbacks.post_unpatch)(obj);
42
43         obj->callbacks.post_unpatch_enabled = false;
44 }
45
46 #endif /* _LIVEPATCH_CORE_H */