3ca7d2ef2b7fcb5b32b5c75fea76aa83e110adb3
[openembedded.git] /
1 From 412656ce83a2605119dc1a7bc5492a13240dc666 Mon Sep 17 00:00:00 2001
2 From: Ben Hutchings <ben@decadent.org.uk>
3 Date: Sat, 19 Dec 2009 14:43:01 +0000
4 Subject: [PATCH 6/9] modules: Skip empty sections when exporting section notes
5
6 Commit 35dead4 "modules: don't export section names of empty sections
7 via sysfs" changed the set of sections that have attributes, but did
8 not change the iteration over these attributes in add_notes_attrs().
9 This can lead to add_notes_attrs() creating attributes with the wrong
10 names or with null name pointers.
11
12 Introduce a sect_empty() function and use it in both add_sect_attrs()
13 and add_notes_attrs().
14
15 Reported-by: Martin Michlmayr <tbm@cyrius.com>
16 Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
17 Tested-by: Martin Michlmayr <tbm@cyrius.com>
18 Cc: stable@kernel.org
19 Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
20 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
21 Signed-off-by: Sanjeev Premi <premi@ti.com>
22 ---
23  kernel/module.c |   17 ++++++++++-------
24  1 files changed, 10 insertions(+), 7 deletions(-)
25
26 diff --git a/kernel/module.c b/kernel/module.c
27 index 12afc5a..a1b4a43 100644
28 --- a/kernel/module.c
29 +++ b/kernel/module.c
30 @@ -996,6 +996,12 @@ static const struct kernel_symbol *resolve_symbol(Elf_Shdr *sechdrs,
31   * J. Corbet <corbet@lwn.net>
32   */
33  #if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS)
34 +
35 +static inline bool sect_empty(const Elf_Shdr *sect)
36 +{
37 +       return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
38 +}
39 +
40  struct module_sect_attr
41  {
42         struct module_attribute mattr;
43 @@ -1037,8 +1043,7 @@ static void add_sect_attrs(struct module *mod, unsigned int nsect,
44  
45         /* Count loaded sections and allocate structures */
46         for (i = 0; i < nsect; i++)
47 -               if (sechdrs[i].sh_flags & SHF_ALLOC
48 -                   && sechdrs[i].sh_size)
49 +               if (!sect_empty(&sechdrs[i]))
50                         nloaded++;
51         size[0] = ALIGN(sizeof(*sect_attrs)
52                         + nloaded * sizeof(sect_attrs->attrs[0]),
53 @@ -1056,9 +1061,7 @@ static void add_sect_attrs(struct module *mod, unsigned int nsect,
54         sattr = &sect_attrs->attrs[0];
55         gattr = &sect_attrs->grp.attrs[0];
56         for (i = 0; i < nsect; i++) {
57 -               if (! (sechdrs[i].sh_flags & SHF_ALLOC))
58 -                       continue;
59 -               if (!sechdrs[i].sh_size)
60 +               if (sect_empty(&sechdrs[i]))
61                         continue;
62                 sattr->address = sechdrs[i].sh_addr;
63                 sattr->name = kstrdup(secstrings + sechdrs[i].sh_name,
64 @@ -1142,7 +1145,7 @@ static void add_notes_attrs(struct module *mod, unsigned int nsect,
65         /* Count notes sections and allocate structures.  */
66         notes = 0;
67         for (i = 0; i < nsect; i++)
68 -               if ((sechdrs[i].sh_flags & SHF_ALLOC) &&
69 +               if (!sect_empty(&sechdrs[i]) &&
70                     (sechdrs[i].sh_type == SHT_NOTE))
71                         ++notes;
72  
73 @@ -1158,7 +1161,7 @@ static void add_notes_attrs(struct module *mod, unsigned int nsect,
74         notes_attrs->notes = notes;
75         nattr = &notes_attrs->attrs[0];
76         for (loaded = i = 0; i < nsect; ++i) {
77 -               if (!(sechdrs[i].sh_flags & SHF_ALLOC))
78 +               if (sect_empty(&sechdrs[i]))
79                         continue;
80                 if (sechdrs[i].sh_type == SHT_NOTE) {
81                         nattr->attr.name = mod->sect_attrs->attrs[loaded].name;
82 -- 
83 1.6.2.4
84