diff options
author | David Howells <dhowells@redhat.com> | 2011-07-27 14:47:03 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-07-27 15:50:45 -0400 |
commit | 09570f914914d2beb0db29c5a9c7344934f2fa8c (patch) | |
tree | a93900db5e607887aca3ef2cecc2426abe007d87 | |
parent | 5fd00b031530cc476240f654c078c930f1dcd6ea (diff) |
proc: make struct proc_dir_entry::name a terminal array rather than a pointer
Since __proc_create() appends the name it is given to the end of the PDE
structure that it allocates, there isn't a need to store a name pointer.
Instead we can just replace the name pointer with a terminal char array of
_unspecified_ length. The compiler will simply append the string to statically
defined variables of PDE type overlapping any hole at the end of the structure
and, unlike specifying an explicitly _zero_ length array, won't give a warning
if you try to statically initialise it with a string of more than zero length.
Also, whilst we're at it:
(1) Move namelen to end just prior to name and reduce it to a single byte
(name shouldn't be longer than NAME_MAX).
(2) Move pde_unload_lock two places further on so that if it's four bytes in
size on a 64-bit machine, it won't cause an unused hole in the PDE struct.
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | fs/proc/generic.c | 3 | ||||
-rw-r--r-- | fs/proc/proc_net.c | 4 | ||||
-rw-r--r-- | fs/proc/root.c | 2 | ||||
-rw-r--r-- | include/linux/proc_fs.h | 6 |
4 files changed, 7 insertions, 8 deletions
diff --git a/fs/proc/generic.c b/fs/proc/generic.c index f1637f17c37c..9d99131d0d65 100644 --- a/fs/proc/generic.c +++ b/fs/proc/generic.c | |||
@@ -620,8 +620,7 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent, | |||
620 | if (!ent) goto out; | 620 | if (!ent) goto out; |
621 | 621 | ||
622 | memset(ent, 0, sizeof(struct proc_dir_entry)); | 622 | memset(ent, 0, sizeof(struct proc_dir_entry)); |
623 | memcpy(((char *) ent) + sizeof(struct proc_dir_entry), fn, len + 1); | 623 | memcpy(ent->name, fn, len + 1); |
624 | ent->name = ((char *) ent) + sizeof(*ent); | ||
625 | ent->namelen = len; | 624 | ent->namelen = len; |
626 | ent->mode = mode; | 625 | ent->mode = mode; |
627 | ent->nlink = nlink; | 626 | ent->nlink = nlink; |
diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c index 9020ac15baaa..f738024ccc8e 100644 --- a/fs/proc/proc_net.c +++ b/fs/proc/proc_net.c | |||
@@ -197,15 +197,15 @@ static __net_init int proc_net_ns_init(struct net *net) | |||
197 | int err; | 197 | int err; |
198 | 198 | ||
199 | err = -ENOMEM; | 199 | err = -ENOMEM; |
200 | netd = kzalloc(sizeof(*netd), GFP_KERNEL); | 200 | netd = kzalloc(sizeof(*netd) + 4, GFP_KERNEL); |
201 | if (!netd) | 201 | if (!netd) |
202 | goto out; | 202 | goto out; |
203 | 203 | ||
204 | netd->data = net; | 204 | netd->data = net; |
205 | netd->nlink = 2; | 205 | netd->nlink = 2; |
206 | netd->name = "net"; | ||
207 | netd->namelen = 3; | 206 | netd->namelen = 3; |
208 | netd->parent = &proc_root; | 207 | netd->parent = &proc_root; |
208 | memcpy(netd->name, "net", 4); | ||
209 | 209 | ||
210 | err = -EEXIST; | 210 | err = -EEXIST; |
211 | net_statd = proc_net_mkdir(net, "stat", netd); | 211 | net_statd = proc_net_mkdir(net, "stat", netd); |
diff --git a/fs/proc/root.c b/fs/proc/root.c index d6c3b416529b..9a8a2b77b874 100644 --- a/fs/proc/root.c +++ b/fs/proc/root.c | |||
@@ -186,13 +186,13 @@ static const struct inode_operations proc_root_inode_operations = { | |||
186 | struct proc_dir_entry proc_root = { | 186 | struct proc_dir_entry proc_root = { |
187 | .low_ino = PROC_ROOT_INO, | 187 | .low_ino = PROC_ROOT_INO, |
188 | .namelen = 5, | 188 | .namelen = 5, |
189 | .name = "/proc", | ||
190 | .mode = S_IFDIR | S_IRUGO | S_IXUGO, | 189 | .mode = S_IFDIR | S_IRUGO | S_IXUGO, |
191 | .nlink = 2, | 190 | .nlink = 2, |
192 | .count = ATOMIC_INIT(1), | 191 | .count = ATOMIC_INIT(1), |
193 | .proc_iops = &proc_root_inode_operations, | 192 | .proc_iops = &proc_root_inode_operations, |
194 | .proc_fops = &proc_root_operations, | 193 | .proc_fops = &proc_root_operations, |
195 | .parent = &proc_root, | 194 | .parent = &proc_root, |
195 | .name = "/proc", | ||
196 | }; | 196 | }; |
197 | 197 | ||
198 | int pid_ns_prepare_proc(struct pid_namespace *ns) | 198 | int pid_ns_prepare_proc(struct pid_namespace *ns) |
diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h index 650af6deaf8f..643b96c7a94f 100644 --- a/include/linux/proc_fs.h +++ b/include/linux/proc_fs.h | |||
@@ -50,8 +50,6 @@ typedef int (write_proc_t)(struct file *file, const char __user *buffer, | |||
50 | 50 | ||
51 | struct proc_dir_entry { | 51 | struct proc_dir_entry { |
52 | unsigned int low_ino; | 52 | unsigned int low_ino; |
53 | unsigned int namelen; | ||
54 | const char *name; | ||
55 | mode_t mode; | 53 | mode_t mode; |
56 | nlink_t nlink; | 54 | nlink_t nlink; |
57 | uid_t uid; | 55 | uid_t uid; |
@@ -73,9 +71,11 @@ struct proc_dir_entry { | |||
73 | write_proc_t *write_proc; | 71 | write_proc_t *write_proc; |
74 | atomic_t count; /* use count */ | 72 | atomic_t count; /* use count */ |
75 | int pde_users; /* number of callers into module in progress */ | 73 | int pde_users; /* number of callers into module in progress */ |
76 | spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */ | ||
77 | struct completion *pde_unload_completion; | 74 | struct completion *pde_unload_completion; |
78 | struct list_head pde_openers; /* who did ->open, but not ->release */ | 75 | struct list_head pde_openers; /* who did ->open, but not ->release */ |
76 | spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */ | ||
77 | u8 namelen; | ||
78 | char name[]; | ||
79 | }; | 79 | }; |
80 | 80 | ||
81 | enum kcore_type { | 81 | enum kcore_type { |