drm/modes: Fix drm_mode_vrefres() docs
[drm/drm-misc.git] / kernel / module / version.c
blob53f43ac5a73e9d537a9e95ff97728a51fad0e797
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Module version support
5 * Copyright (C) 2008 Rusty Russell
6 */
8 #include <linux/module.h>
9 #include <linux/string.h>
10 #include <linux/printk.h>
11 #include "internal.h"
13 int check_version(const struct load_info *info,
14 const char *symname,
15 struct module *mod,
16 const s32 *crc)
18 Elf_Shdr *sechdrs = info->sechdrs;
19 unsigned int versindex = info->index.vers;
20 unsigned int i, num_versions;
21 struct modversion_info *versions;
23 /* Exporting module didn't supply crcs? OK, we're already tainted. */
24 if (!crc)
25 return 1;
27 /* No versions at all? modprobe --force does this. */
28 if (versindex == 0)
29 return try_to_force_load(mod, symname) == 0;
31 versions = (void *)sechdrs[versindex].sh_addr;
32 num_versions = sechdrs[versindex].sh_size
33 / sizeof(struct modversion_info);
35 for (i = 0; i < num_versions; i++) {
36 u32 crcval;
38 if (strcmp(versions[i].name, symname) != 0)
39 continue;
41 crcval = *crc;
42 if (versions[i].crc == crcval)
43 return 1;
44 pr_debug("Found checksum %X vs module %lX\n",
45 crcval, versions[i].crc);
46 goto bad_version;
49 /* Broken toolchain. Warn once, then let it go.. */
50 pr_warn_once("%s: no symbol version for %s\n", info->name, symname);
51 return 1;
53 bad_version:
54 pr_warn("%s: disagrees about version of symbol %s\n", info->name, symname);
55 return 0;
58 int check_modstruct_version(const struct load_info *info,
59 struct module *mod)
61 struct find_symbol_arg fsa = {
62 .name = "module_layout",
63 .gplok = true,
67 * Since this should be found in kernel (which can't be removed), no
68 * locking is necessary -- use preempt_disable() to placate lockdep.
70 preempt_disable();
71 if (!find_symbol(&fsa)) {
72 preempt_enable();
73 BUG();
75 preempt_enable();
76 return check_version(info, "module_layout", mod, fsa.crc);
79 /* First part is kernel version, which we ignore if module has crcs. */
80 int same_magic(const char *amagic, const char *bmagic,
81 bool has_crcs)
83 if (has_crcs) {
84 amagic += strcspn(amagic, " ");
85 bmagic += strcspn(bmagic, " ");
87 return strcmp(amagic, bmagic) == 0;
91 * Generate the signature for all relevant module structures here.
92 * If these change, we don't want to try to parse the module.
94 void module_layout(struct module *mod,
95 struct modversion_info *ver,
96 struct kernel_param *kp,
97 struct kernel_symbol *ks,
98 struct tracepoint * const *tp)
101 EXPORT_SYMBOL(module_layout);