The (alleged) users of the module addresses are the same: kernel profiling. So just expose the same helper and format macros, and unify the logic.
Showing the changes to kernel/module.c (1 of 3 files). Show all
Unified · Split
| @@ -4147,6 +4147,7 @@ static int m_show(struct seq_file *m, void *p) · 4146 unmodified lines | ||
| 4147 | 4147 | { |
| 4148 | 4148 | struct module *mod = list_entry(p, struct module, list); |
| 4149 | 4149 | char buf[MODULE_FLAGS_BUF_SIZE]; |
| 4150 | + unsigned long value; | |
| 4150 | 4151 | |
| 4151 | 4152 | /* We always ignore unformed modules. */ |
| 4152 | 4153 | if (mod->state == MODULE_STATE_UNFORMED) |
| @@ -4162,7 +4163,8 @@ static int m_show(struct seq_file *m, void *p) · 9 unmodified lines | ||
| 4162 | 4163 | mod->state == MODULE_STATE_COMING ? "Loading" : |
| 4163 | 4164 | "Live"); |
| 4164 | 4165 | /* Used by oprofile and other similar tools. */ |
| 4165 | − seq_printf(m, " 0x%pK", mod->core_layout.base); | |
| 4166 | + value = m->private ? 0 : (unsigned long)mod->core_layout.base; | |
| 4167 | + seq_printf(m, " 0x" KALLSYM_FMT, value); | |
| 4166 | 4168 | |
| 4167 | 4169 | /* Taints info */ |
| 4168 | 4170 | if (mod->taints) |
| @@ -4184,9 +4186,23 @@ static const struct seq_operations modules_op = { · 15 unmodified lines | ||
| 4184 | 4186 | .show = m_show |
| 4185 | 4187 | }; |
| 4186 | 4188 | |
| 4189 | +/* | |
| 4190 | + * This also sets the "private" pointer to non-NULL if the | |
| 4191 | + * kernel pointers should be hidden (so you can just test | |
| 4192 | + * "m->private" to see if you should keep the values private). | |
| 4193 | + * | |
| 4194 | + * We use the same logic as for /proc/kallsyms. | |
| 4195 | + */ | |
| 4187 | 4196 | static int modules_open(struct inode *inode, struct file *file) |
| 4188 | 4197 | { |
| 4189 | − return seq_open(file, &modules_op); | |
| 4198 | + int err = seq_open(file, &modules_op); | |
| 4199 | + | |
| 4200 | + if (!err) { | |
| 4201 | + struct seq_file *m = file->private_data; | |
| 4202 | + m->private = kallsyms_show_value() ? NULL : (void *)8ul; | |
| 4203 | + } | |
| 4204 | + | |
| 4205 | + return 0; | |
| 4190 | 4206 | } |
| 4191 | 4207 | |
| 4192 | 4208 | static const struct file_operations proc_modules_operations = { |