aboutsummaryrefslogtreecommitdiffstats
path: root/security/selinux/hooks.c
diff options
context:
space:
mode:
authorJames Morris <jmorris@namei.org>2005-10-30 17:59:21 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2005-10-30 20:37:11 -0500
commit89d155ef62e5e0c10e4b37aaa5056f0beafe10e6 (patch)
tree7de1f357efd619000970526ca2688f79b9022417 /security/selinux/hooks.c
parent0d078f6f96809c95c69b99d6605a502b0ac63d3d (diff)
[PATCH] SELinux: convert to kzalloc
This patch converts SELinux code from kmalloc/memset to the new kazalloc unction. On i386, this results in a text saving of over 1K. Before: text data bss dec hex filename 86319 4642 15236 106197 19ed5 security/selinux/built-in.o After: text data bss dec hex filename 85278 4642 15236 105156 19ac4 security/selinux/built-in.o Signed-off-by: James Morris <jmorris@namei.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'security/selinux/hooks.c')
-rw-r--r--security/selinux/hooks.c24
1 files changed, 8 insertions, 16 deletions
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 447a1e0f48cb..8cd33b2cd865 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -122,11 +122,10 @@ static int task_alloc_security(struct task_struct *task)
122{ 122{
123 struct task_security_struct *tsec; 123 struct task_security_struct *tsec;
124 124
125 tsec = kmalloc(sizeof(struct task_security_struct), GFP_KERNEL); 125 tsec = kzalloc(sizeof(struct task_security_struct), GFP_KERNEL);
126 if (!tsec) 126 if (!tsec)
127 return -ENOMEM; 127 return -ENOMEM;
128 128
129 memset(tsec, 0, sizeof(struct task_security_struct));
130 tsec->magic = SELINUX_MAGIC; 129 tsec->magic = SELINUX_MAGIC;
131 tsec->task = task; 130 tsec->task = task;
132 tsec->osid = tsec->sid = tsec->ptrace_sid = SECINITSID_UNLABELED; 131 tsec->osid = tsec->sid = tsec->ptrace_sid = SECINITSID_UNLABELED;
@@ -151,11 +150,10 @@ static int inode_alloc_security(struct inode *inode)
151 struct task_security_struct *tsec = current->security; 150 struct task_security_struct *tsec = current->security;
152 struct inode_security_struct *isec; 151 struct inode_security_struct *isec;
153 152
154 isec = kmalloc(sizeof(struct inode_security_struct), GFP_KERNEL); 153 isec = kzalloc(sizeof(struct inode_security_struct), GFP_KERNEL);
155 if (!isec) 154 if (!isec)
156 return -ENOMEM; 155 return -ENOMEM;
157 156
158 memset(isec, 0, sizeof(struct inode_security_struct));
159 init_MUTEX(&isec->sem); 157 init_MUTEX(&isec->sem);
160 INIT_LIST_HEAD(&isec->list); 158 INIT_LIST_HEAD(&isec->list);
161 isec->magic = SELINUX_MAGIC; 159 isec->magic = SELINUX_MAGIC;
@@ -193,11 +191,10 @@ static int file_alloc_security(struct file *file)
193 struct task_security_struct *tsec = current->security; 191 struct task_security_struct *tsec = current->security;
194 struct file_security_struct *fsec; 192 struct file_security_struct *fsec;
195 193
196 fsec = kmalloc(sizeof(struct file_security_struct), GFP_ATOMIC); 194 fsec = kzalloc(sizeof(struct file_security_struct), GFP_ATOMIC);
197 if (!fsec) 195 if (!fsec)
198 return -ENOMEM; 196 return -ENOMEM;
199 197
200 memset(fsec, 0, sizeof(struct file_security_struct));
201 fsec->magic = SELINUX_MAGIC; 198 fsec->magic = SELINUX_MAGIC;
202 fsec->file = file; 199 fsec->file = file;
203 if (tsec && tsec->magic == SELINUX_MAGIC) { 200 if (tsec && tsec->magic == SELINUX_MAGIC) {
@@ -227,11 +224,10 @@ static int superblock_alloc_security(struct super_block *sb)
227{ 224{
228 struct superblock_security_struct *sbsec; 225 struct superblock_security_struct *sbsec;
229 226
230 sbsec = kmalloc(sizeof(struct superblock_security_struct), GFP_KERNEL); 227 sbsec = kzalloc(sizeof(struct superblock_security_struct), GFP_KERNEL);
231 if (!sbsec) 228 if (!sbsec)
232 return -ENOMEM; 229 return -ENOMEM;
233 230
234 memset(sbsec, 0, sizeof(struct superblock_security_struct));
235 init_MUTEX(&sbsec->sem); 231 init_MUTEX(&sbsec->sem);
236 INIT_LIST_HEAD(&sbsec->list); 232 INIT_LIST_HEAD(&sbsec->list);
237 INIT_LIST_HEAD(&sbsec->isec_head); 233 INIT_LIST_HEAD(&sbsec->isec_head);
@@ -269,11 +265,10 @@ static int sk_alloc_security(struct sock *sk, int family, gfp_t priority)
269 if (family != PF_UNIX) 265 if (family != PF_UNIX)
270 return 0; 266 return 0;
271 267
272 ssec = kmalloc(sizeof(*ssec), priority); 268 ssec = kzalloc(sizeof(*ssec), priority);
273 if (!ssec) 269 if (!ssec)
274 return -ENOMEM; 270 return -ENOMEM;
275 271
276 memset(ssec, 0, sizeof(*ssec));
277 ssec->magic = SELINUX_MAGIC; 272 ssec->magic = SELINUX_MAGIC;
278 ssec->sk = sk; 273 ssec->sk = sk;
279 ssec->peer_sid = SECINITSID_UNLABELED; 274 ssec->peer_sid = SECINITSID_UNLABELED;
@@ -1483,11 +1478,10 @@ static int selinux_bprm_alloc_security(struct linux_binprm *bprm)
1483{ 1478{
1484 struct bprm_security_struct *bsec; 1479 struct bprm_security_struct *bsec;
1485 1480
1486 bsec = kmalloc(sizeof(struct bprm_security_struct), GFP_KERNEL); 1481 bsec = kzalloc(sizeof(struct bprm_security_struct), GFP_KERNEL);
1487 if (!bsec) 1482 if (!bsec)
1488 return -ENOMEM; 1483 return -ENOMEM;
1489 1484
1490 memset(bsec, 0, sizeof *bsec);
1491 bsec->magic = SELINUX_MAGIC; 1485 bsec->magic = SELINUX_MAGIC;
1492 bsec->bprm = bprm; 1486 bsec->bprm = bprm;
1493 bsec->sid = SECINITSID_UNLABELED; 1487 bsec->sid = SECINITSID_UNLABELED;
@@ -3599,11 +3593,10 @@ static int ipc_alloc_security(struct task_struct *task,
3599 struct task_security_struct *tsec = task->security; 3593 struct task_security_struct *tsec = task->security;
3600 struct ipc_security_struct *isec; 3594 struct ipc_security_struct *isec;
3601 3595
3602 isec = kmalloc(sizeof(struct ipc_security_struct), GFP_KERNEL); 3596 isec = kzalloc(sizeof(struct ipc_security_struct), GFP_KERNEL);
3603 if (!isec) 3597 if (!isec)
3604 return -ENOMEM; 3598 return -ENOMEM;
3605 3599
3606 memset(isec, 0, sizeof(struct ipc_security_struct));
3607 isec->magic = SELINUX_MAGIC; 3600 isec->magic = SELINUX_MAGIC;
3608 isec->sclass = sclass; 3601 isec->sclass = sclass;
3609 isec->ipc_perm = perm; 3602 isec->ipc_perm = perm;
@@ -3631,11 +3624,10 @@ static int msg_msg_alloc_security(struct msg_msg *msg)
3631{ 3624{
3632 struct msg_security_struct *msec; 3625 struct msg_security_struct *msec;
3633 3626
3634 msec = kmalloc(sizeof(struct msg_security_struct), GFP_KERNEL); 3627 msec = kzalloc(sizeof(struct msg_security_struct), GFP_KERNEL);
3635 if (!msec) 3628 if (!msec)
3636 return -ENOMEM; 3629 return -ENOMEM;
3637 3630
3638 memset(msec, 0, sizeof(struct msg_security_struct));
3639 msec->magic = SELINUX_MAGIC; 3631 msec->magic = SELINUX_MAGIC;
3640 msec->msg = msg; 3632 msec->msg = msg;
3641 msec->sid = SECINITSID_UNLABELED; 3633 msec->sid = SECINITSID_UNLABELED;