Skip to content

Commit

Permalink
module: Move module_assert_mutex_or_preempt() to internal.h
Browse files Browse the repository at this point in the history
No functional change.

This patch migrates module_assert_mutex_or_preempt() to internal.h.
So, the aforementiond function can be used outside of main/or core
module code yet will remain restricted for internal use only.

Signed-off-by: Aaron Tomlin <atomlin@redhat.com>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
  • Loading branch information
Aaron Tomlin authored and Luis Chamberlain committed May 12, 2022
1 parent c14e522 commit 6fb0538
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
12 changes: 12 additions & 0 deletions kernel/module/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/rculist.h>
#include <linux/rcupdate.h>

#ifndef ARCH_SHF_SMALL
#define ARCH_SHF_SMALL 0
Expand Down Expand Up @@ -102,6 +103,17 @@ long module_get_offset(struct module *mod, unsigned int *size, Elf_Shdr *sechdr,
char *module_flags(struct module *mod, char *buf);
size_t module_flags_taint(unsigned long taints, char *buf);

static inline void module_assert_mutex_or_preempt(void)
{
#ifdef CONFIG_LOCKDEP
if (unlikely(!debug_locks))
return;

WARN_ON_ONCE(!rcu_read_lock_sched_held() &&
!lockdep_is_held(&module_mutex));
#endif
}

static inline unsigned long kernel_symbol_value(const struct kernel_symbol *sym)
{
#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
Expand Down
11 changes: 0 additions & 11 deletions kernel/module/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,6 @@ static void mod_update_bounds(struct module *mod)
#endif
}

static void module_assert_mutex_or_preempt(void)
{
#ifdef CONFIG_LOCKDEP
if (unlikely(!debug_locks))
return;

WARN_ON_ONCE(!rcu_read_lock_sched_held() &&
!lockdep_is_held(&module_mutex));
#endif
}

/* Block module loading/unloading? */
int modules_disabled = 0;
core_param(nomodule, modules_disabled, bint, 0);
Expand Down

0 comments on commit 6fb0538

Please sign in to comment.