Skip to content

Commit ffb4512

Browse files
Alexey DobriyanLinus Torvalds
authored andcommitted
Simplify kallsyms_lookup()
Several kallsyms_lookup() pass dummy arguments but only need, say, module's name. Make kallsyms_lookup() accept NULLs where possible. Also, makes picture clearer about what interfaces are needed for all symbol resolving business. Signed-off-by: Alexey Dobriyan <adobriyan@sw.ru> Cc: Rusty Russell <rusty@rustcorp.com.au> Acked-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent ea07890 commit ffb4512

10 files changed

Lines changed: 20 additions & 28 deletions

File tree

‎arch/parisc/kernel/unwind.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,8 @@ static void unwind_frame_regs(struct unwind_frame_info *info)
216216
/* Handle some frequent special cases.... */
217217
{
218218
char symname[KSYM_NAME_LEN+1];
219-
char *modname;
220-
unsigned long symsize, offset;
221219

222-
kallsyms_lookup(info->ip, &symsize, &offset,
223-
&modname, symname);
220+
kallsyms_lookup(info->ip, NULL, NULL, NULL, symname);
224221

225222
dbg("info->ip = 0x%lx, name = %s\n", info->ip, symname);
226223

‎arch/powerpc/xmon/xmon.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,15 +1217,14 @@ static void get_function_bounds(unsigned long pc, unsigned long *startp,
12171217
{
12181218
unsigned long size, offset;
12191219
const char *name;
1220-
char *modname;
12211220

12221221
*startp = *endp = 0;
12231222
if (pc == 0)
12241223
return;
12251224
if (setjmp(bus_error_jmp) == 0) {
12261225
catch_memory_errors = 1;
12271226
sync();
1228-
name = kallsyms_lookup(pc, &size, &offset, &modname, tmpstr);
1227+
name = kallsyms_lookup(pc, &size, &offset, NULL, tmpstr);
12291228
if (name != NULL) {
12301229
*startp = pc - offset;
12311230
*endp = pc - offset + size;

‎arch/sh64/kernel/unwind.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ static int lookup_prev_stack_frame(unsigned long fp, unsigned long pc,
4646
struct pt_regs *regs)
4747
{
4848
const char *sym;
49-
char *modname, namebuf[128];
50-
unsigned long offset, size;
49+
char namebuf[128];
50+
unsigned long offset;
5151
unsigned long prologue = 0;
5252
unsigned long fp_displacement = 0;
5353
unsigned long fp_prev = 0;
5454
unsigned long offset_r14 = 0, offset_r18 = 0;
5555
int i, found_prologue_end = 0;
5656

57-
sym = kallsyms_lookup(pc, &size, &offset, &modname, namebuf);
57+
sym = kallsyms_lookup(pc, NULL, &offset, NULL, namebuf);
5858
if (!sym)
5959
return -EINVAL;
6060

‎fs/proc/base.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,13 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
278278
*/
279279
static int proc_pid_wchan(struct task_struct *task, char *buffer)
280280
{
281-
char *modname;
282281
const char *sym_name;
283-
unsigned long wchan, size, offset;
282+
unsigned long wchan;
284283
char namebuf[KSYM_NAME_LEN+1];
285284

286285
wchan = get_wchan(task);
287286

288-
sym_name = kallsyms_lookup(wchan, &size, &offset, &modname, namebuf);
287+
sym_name = kallsyms_lookup(wchan, NULL, NULL, NULL, namebuf);
289288
if (sym_name)
290289
return sprintf(buffer, "%s", sym_name);
291290
return sprintf(buffer, "%lu", wchan);

‎kernel/kallsyms.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,10 @@ static unsigned long get_symbol_pos(unsigned long addr,
214214
symbol_end = (unsigned long)_etext;
215215
}
216216

217-
*symbolsize = symbol_end - symbol_start;
218-
*offset = addr - symbol_start;
217+
if (symbolsize)
218+
*symbolsize = symbol_end - symbol_start;
219+
if (offset)
220+
*offset = addr - symbol_start;
219221

220222
return low;
221223
}

‎kernel/kprobes.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -868,13 +868,13 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
868868
struct kprobe *p, *kp;
869869
const char *sym = NULL;
870870
unsigned int i = *(loff_t *) v;
871-
unsigned long size, offset = 0;
871+
unsigned long offset = 0;
872872
char *modname, namebuf[128];
873873

874874
head = &kprobe_table[i];
875875
preempt_disable();
876876
hlist_for_each_entry_rcu(p, node, head, hlist) {
877-
sym = kallsyms_lookup((unsigned long)p->addr, &size,
877+
sym = kallsyms_lookup((unsigned long)p->addr, NULL,
878878
&offset, &modname, namebuf);
879879
if (p->pre_handler == aggr_pre_handler) {
880880
list_for_each_entry_rcu(kp, &p->list, list)

‎kernel/lockdep.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,7 @@ static const char *usage_str[] =
340340

341341
const char * __get_key_name(struct lockdep_subclass_key *key, char *str)
342342
{
343-
unsigned long offs, size;
344-
char *modname;
345-
346-
return kallsyms_lookup((unsigned long)key, &size, &offs, &modname, str);
343+
return kallsyms_lookup((unsigned long)key, NULL, NULL, NULL, str);
347344
}
348345

349346
void

‎kernel/module.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,8 +2098,10 @@ static const char *get_ksymbol(struct module *mod,
20982098
if (!best)
20992099
return NULL;
21002100

2101-
*size = nextval - mod->symtab[best].st_value;
2102-
*offset = addr - mod->symtab[best].st_value;
2101+
if (size)
2102+
*size = nextval - mod->symtab[best].st_value;
2103+
if (offset)
2104+
*offset = addr - mod->symtab[best].st_value;
21032105
return mod->strtab + mod->symtab[best].st_name;
21042106
}
21052107

‎kernel/time/timer_list.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,9 @@ static void print_name_offset(struct seq_file *m, void *sym)
4040
{
4141
unsigned long addr = (unsigned long)sym;
4242
char namebuf[KSYM_NAME_LEN+1];
43-
unsigned long size, offset;
4443
const char *sym_name;
45-
char *modname;
4644

47-
sym_name = kallsyms_lookup(addr, &size, &offset, &modname, namebuf);
45+
sym_name = kallsyms_lookup(addr, NULL, NULL, NULL, namebuf);
4846
if (sym_name)
4947
SEQ_printf(m, "%s", sym_name);
5048
else

‎kernel/time/timer_stats.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,9 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
258258
static void print_name_offset(struct seq_file *m, unsigned long addr)
259259
{
260260
char namebuf[KSYM_NAME_LEN+1];
261-
unsigned long size, offset;
262261
const char *sym_name;
263-
char *modname;
264262

265-
sym_name = kallsyms_lookup(addr, &size, &offset, &modname, namebuf);
263+
sym_name = kallsyms_lookup(addr, NULL, NULL, NULL, namebuf);
266264
if (sym_name)
267265
seq_printf(m, "%s", sym_name);
268266
else

0 commit comments

Comments
 (0)