diff --git a/doc/patch-author-guide.md b/doc/patch-author-guide.md index 26daee30f..8133ad7c5 100644 --- a/doc/patch-author-guide.md +++ b/doc/patch-author-guide.md @@ -808,6 +808,41 @@ This can be done by replacing any usages of `static_branch_likely()`, `static_branch_unlikely()`, `static_key_true()`, and `static_key_false()` with `static_key_enabled()` in the patch file. +There is an example of using `static_key_enabled()` to replace the static key in the patch file: +This is an static key used in the patch file: +``` +static inline bool memcg_kmem_enabled(void) +{ + return static_branch_unlikely(&memcg_kmem_enabled_key); +} +``` + +We can use `static_key_enabled()` to rewrite the macros `static_branch_likely` as follows: +``` +#define static_branch_unlikely(x) unlikely(static_key_enabled(&(x)->key)) +``` + +However, using the following method to fix the static key error also work: +``` +static inline bool memcg_kmem_enabled(void) +{ + return unlikely(&(&memcg_kmem_enabled_key)->key); +} +``` + +Changing the definition in header file may cause too much changes in the object invoked this macros eventhough we have no changes effect them, + which is not a good choice to rewrite the original definition. +So, we can define a new function for our patch function to fix static_key. +``` +static inline bool memcg_kmem_enabled_new(void) +{ + return unlikely(&(&memcg_kmem_enabled_key)->key); +} +``` +The patch function invoke `memcg_kmem_enabled_new` can avoid changes to other extraneous functions. + + + ### Static calls Similarly, static calls are not supported when the corresponding static call