diff options
author | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2005-06-01 03:07:27 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-06-01 10:54:14 -0400 |
commit | 5f64f73957f6cae3222f97f2599199ee562f7f3f (patch) | |
tree | 115e11766270637d3c9b2e9e0366b127af7a1fd6 /fs | |
parent | f93ea2349832c040bdf66dc7495aa87bfe3394b8 (diff) |
[PATCH] ppc32/ppc64: cleanup /proc/device-tree
This cleans up the /proc/device-tree representation of the Open Firmware
device-tree on ppc and ppc64. It does the following things:
- Workaround an issue in some Apple device-trees where a property may
exist with the same name as a child node of the parent. We now
simply "drop" the property instead of creating duplicate entries in
/proc with random result...
- Do not try to chop off the "@0" at the end of a node name whose unit
address is 0. This is not useful, inconsistent, and the code was
buggy and didn't always work anyway.
- Do not create symlinks for the short name and unit address parts of a
node. These were never really used, bloated the memory footprint of
the device-tree with useless struct proc_dir_entry and their matching
dentry and inode cache bloat.
This results in smaller code, smaller memory footprint, and a more
accurate view of the tree presented to userland.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/proc/proc_devtree.c | 105 |
1 files changed, 38 insertions, 67 deletions
diff --git a/fs/proc/proc_devtree.c b/fs/proc/proc_devtree.c index 67423c696c0a..6fd57f154197 100644 --- a/fs/proc/proc_devtree.c +++ b/fs/proc/proc_devtree.c | |||
@@ -12,15 +12,8 @@ | |||
12 | #include <asm/uaccess.h> | 12 | #include <asm/uaccess.h> |
13 | 13 | ||
14 | #ifndef HAVE_ARCH_DEVTREE_FIXUPS | 14 | #ifndef HAVE_ARCH_DEVTREE_FIXUPS |
15 | static inline void set_node_proc_entry(struct device_node *np, struct proc_dir_entry *de) | 15 | static inline void set_node_proc_entry(struct device_node *np, |
16 | { | 16 | struct proc_dir_entry *de) |
17 | } | ||
18 | |||
19 | static void inline set_node_name_link(struct device_node *np, struct proc_dir_entry *de) | ||
20 | { | ||
21 | } | ||
22 | |||
23 | static void inline set_node_addr_link(struct device_node *np, struct proc_dir_entry *de) | ||
24 | { | 17 | { |
25 | } | 18 | } |
26 | #endif | 19 | #endif |
@@ -58,89 +51,67 @@ static int property_read_proc(char *page, char **start, off_t off, | |||
58 | /* | 51 | /* |
59 | * Process a node, adding entries for its children and its properties. | 52 | * Process a node, adding entries for its children and its properties. |
60 | */ | 53 | */ |
61 | void proc_device_tree_add_node(struct device_node *np, struct proc_dir_entry *de) | 54 | void proc_device_tree_add_node(struct device_node *np, |
55 | struct proc_dir_entry *de) | ||
62 | { | 56 | { |
63 | struct property *pp; | 57 | struct property *pp; |
64 | struct proc_dir_entry *ent; | 58 | struct proc_dir_entry *ent; |
65 | struct device_node *child, *sib; | 59 | struct device_node *child; |
66 | const char *p, *at; | 60 | struct proc_dir_entry *list = NULL, **lastp; |
67 | int l; | 61 | const char *p; |
68 | struct proc_dir_entry *list, **lastp, *al; | ||
69 | 62 | ||
70 | set_node_proc_entry(np, de); | 63 | set_node_proc_entry(np, de); |
71 | lastp = &list; | 64 | lastp = &list; |
72 | for (pp = np->properties; pp != 0; pp = pp->next) { | 65 | for (child = NULL; (child = of_get_next_child(np, child));) { |
73 | /* | ||
74 | * Unfortunately proc_register puts each new entry | ||
75 | * at the beginning of the list. So we rearrange them. | ||
76 | */ | ||
77 | ent = create_proc_read_entry(pp->name, strncmp(pp->name, "security-", 9) ? | ||
78 | S_IRUGO : S_IRUSR, de, property_read_proc, pp); | ||
79 | if (ent == 0) | ||
80 | break; | ||
81 | if (!strncmp(pp->name, "security-", 9)) | ||
82 | ent->size = 0; /* don't leak number of password chars */ | ||
83 | else | ||
84 | ent->size = pp->length; | ||
85 | *lastp = ent; | ||
86 | lastp = &ent->next; | ||
87 | } | ||
88 | child = NULL; | ||
89 | while ((child = of_get_next_child(np, child))) { | ||
90 | p = strrchr(child->full_name, '/'); | 66 | p = strrchr(child->full_name, '/'); |
91 | if (!p) | 67 | if (!p) |
92 | p = child->full_name; | 68 | p = child->full_name; |
93 | else | 69 | else |
94 | ++p; | 70 | ++p; |
95 | /* chop off '@0' if the name ends with that */ | ||
96 | l = strlen(p); | ||
97 | if (l > 2 && p[l-2] == '@' && p[l-1] == '0') | ||
98 | l -= 2; | ||
99 | ent = proc_mkdir(p, de); | 71 | ent = proc_mkdir(p, de); |
100 | if (ent == 0) | 72 | if (ent == 0) |
101 | break; | 73 | break; |
102 | *lastp = ent; | 74 | *lastp = ent; |
75 | ent->next = NULL; | ||
103 | lastp = &ent->next; | 76 | lastp = &ent->next; |
104 | proc_device_tree_add_node(child, ent); | 77 | proc_device_tree_add_node(child, ent); |
105 | 78 | } | |
106 | /* | 79 | of_node_put(child); |
107 | * If we left the address part on the name, consider | 80 | for (pp = np->properties; pp != 0; pp = pp->next) { |
108 | * adding symlinks from the name and address parts. | ||
109 | */ | ||
110 | if (p[l] != 0 || (at = strchr(p, '@')) == 0) | ||
111 | continue; | ||
112 | |||
113 | /* | 81 | /* |
114 | * If this is the first node with a given name property, | 82 | * Yet another Apple device-tree bogosity: on some machines, |
115 | * add a symlink with the name property as its name. | 83 | * they have properties & nodes with the same name. Those |
84 | * properties are quite unimportant for us though, thus we | ||
85 | * simply "skip" them here, but we do have to check. | ||
116 | */ | 86 | */ |
117 | sib = NULL; | 87 | for (ent = list; ent != NULL; ent = ent->next) |
118 | while ((sib = of_get_next_child(np, sib)) && sib != child) | 88 | if (!strcmp(ent->name, pp->name)) |
119 | if (sib->name && strcmp(sib->name, child->name) == 0) | ||
120 | break; | ||
121 | if (sib == child && strncmp(p, child->name, l) != 0) { | ||
122 | al = proc_symlink(child->name, de, ent->name); | ||
123 | if (al == 0) { | ||
124 | of_node_put(sib); | ||
125 | break; | 89 | break; |
126 | } | 90 | if (ent != NULL) { |
127 | set_node_name_link(child, al); | 91 | printk(KERN_WARNING "device-tree: property \"%s\" name" |
128 | *lastp = al; | 92 | " conflicts with node in %s\n", pp->name, |
129 | lastp = &al->next; | 93 | np->full_name); |
94 | continue; | ||
130 | } | 95 | } |
131 | of_node_put(sib); | 96 | |
132 | /* | 97 | /* |
133 | * Add another directory with the @address part as its name. | 98 | * Unfortunately proc_register puts each new entry |
99 | * at the beginning of the list. So we rearrange them. | ||
134 | */ | 100 | */ |
135 | al = proc_symlink(at, de, ent->name); | 101 | ent = create_proc_read_entry(pp->name, |
136 | if (al == 0) | 102 | strncmp(pp->name, "security-", 9) |
103 | ? S_IRUGO : S_IRUSR, de, | ||
104 | property_read_proc, pp); | ||
105 | if (ent == 0) | ||
137 | break; | 106 | break; |
138 | set_node_addr_link(child, al); | 107 | if (!strncmp(pp->name, "security-", 9)) |
139 | *lastp = al; | 108 | ent->size = 0; /* don't leak number of password chars */ |
140 | lastp = &al->next; | 109 | else |
110 | ent->size = pp->length; | ||
111 | ent->next = NULL; | ||
112 | *lastp = ent; | ||
113 | lastp = &ent->next; | ||
141 | } | 114 | } |
142 | of_node_put(child); | ||
143 | *lastp = NULL; | ||
144 | de->subdir = list; | 115 | de->subdir = list; |
145 | } | 116 | } |
146 | 117 | ||