From 198e79f0e8f0b24c1e36ab6032d348f40de20262 Mon Sep 17 00:00:00 2001 From: Dominik Sliwa Date: Fri, 22 Dec 2017 12:07:34 +0000 Subject: backports: bluetooth: Support 4.9 kernels Signed-off-by: Dominik Sliwa --- compat/backport-4.0.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'compat/backport-4.0.c') diff --git a/compat/backport-4.0.c b/compat/backport-4.0.c index eb95082..7f86c69 100644 --- a/compat/backport-4.0.c +++ b/compat/backport-4.0.c @@ -17,6 +17,7 @@ #include #include #include +#include static __always_inline long __get_user_pages_locked(struct task_struct *tsk, struct mm_struct *mm, @@ -375,3 +376,35 @@ ftrace_print_array_seq(struct trace_seq *p, const void *buf, int buf_len, return ret; } EXPORT_SYMBOL(ftrace_print_array_seq); + +/** + * kfree_const - conditionally free memory + * @x: pointer to the memory + * + * Function calls kfree only if @x is not in .rodata section. + */ +void kfree_const(const void *x) +{ + /* if (!is_kernel_rodata((unsigned long)x)) */ + kfree(x); +} +EXPORT_SYMBOL(kfree_const); + +/* +* kstrdup_const - conditionally duplicate an existing const string +* @s: the string to duplicate +* @gfp: the GFP mask used in the kmalloc() call when allocating memory +* +* Function returns source string if it is in .rodata section otherwise it +* fallbacks to kstrdup. +* Strings allocated by kstrdup_const should be freed by kfree_const. +*/ + +const char *kstrdup_const(const char *s, gfp_t gfp) +{ +/* if (is_kernel_rodata((unsigned long)s)) + * return s; + */ + return kstrdup(s, gfp); +} +EXPORT_SYMBOL(kstrdup_const); -- cgit v1.2.3