diff options
author | Nadia Derbey <Nadia.Derbey@bull.net> | 2007-10-19 02:40:51 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-10-19 14:53:46 -0400 |
commit | 03f02c7657f7948ab980280c54c9366f962b1474 (patch) | |
tree | 7b1f564772077db0aed1e3c5a79ae77d2c1d2307 /ipc | |
parent | 023a53557ea0e987b002e9a844242ef0b0aa1eb3 (diff) |
Storing ipcs into IDRs
This patch converts casts of struct kern_ipc_perm to
. struct msg_queue
. struct sem_array
. struct shmid_kernel
into the equivalent container_of() macro. It improves code maintenance
because the code need not change if kern_ipc_perm is no longer at the
beginning of the containing struct.
Signed-off-by: Nadia Derbey <Nadia.Derbey@bull.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'ipc')
-rw-r--r-- | ipc/msg.c | 14 | ||||
-rw-r--r-- | ipc/sem.c | 23 | ||||
-rw-r--r-- | ipc/shm.c | 23 | ||||
-rw-r--r-- | ipc/util.h | 4 |
4 files changed, 46 insertions, 18 deletions
@@ -138,13 +138,17 @@ void __init msg_init(void) | |||
138 | 138 | ||
139 | static inline struct msg_queue *msg_lock(struct ipc_namespace *ns, int id) | 139 | static inline struct msg_queue *msg_lock(struct ipc_namespace *ns, int id) |
140 | { | 140 | { |
141 | return (struct msg_queue *) ipc_lock(&msg_ids(ns), id); | 141 | struct kern_ipc_perm *ipcp = ipc_lock(&msg_ids(ns), id); |
142 | |||
143 | return container_of(ipcp, struct msg_queue, q_perm); | ||
142 | } | 144 | } |
143 | 145 | ||
144 | static inline struct msg_queue *msg_lock_check(struct ipc_namespace *ns, | 146 | static inline struct msg_queue *msg_lock_check(struct ipc_namespace *ns, |
145 | int id) | 147 | int id) |
146 | { | 148 | { |
147 | return (struct msg_queue *) ipc_lock_check(&msg_ids(ns), id); | 149 | struct kern_ipc_perm *ipcp = ipc_lock_check(&msg_ids(ns), id); |
150 | |||
151 | return container_of(ipcp, struct msg_queue, q_perm); | ||
148 | } | 152 | } |
149 | 153 | ||
150 | static inline void msg_rmid(struct ipc_namespace *ns, struct msg_queue *s) | 154 | static inline void msg_rmid(struct ipc_namespace *ns, struct msg_queue *s) |
@@ -274,9 +278,11 @@ static void freeque(struct ipc_namespace *ns, struct msg_queue *msq) | |||
274 | ipc_rcu_putref(msq); | 278 | ipc_rcu_putref(msq); |
275 | } | 279 | } |
276 | 280 | ||
277 | static inline int msg_security(void *msq, int msgflg) | 281 | static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg) |
278 | { | 282 | { |
279 | return security_msg_queue_associate((struct msg_queue *) msq, msgflg); | 283 | struct msg_queue *msq = container_of(ipcp, struct msg_queue, q_perm); |
284 | |||
285 | return security_msg_queue_associate(msq, msgflg); | ||
280 | } | 286 | } |
281 | 287 | ||
282 | asmlinkage long sys_msgget(key_t key, int msgflg) | 288 | asmlinkage long sys_msgget(key_t key, int msgflg) |
@@ -176,13 +176,17 @@ void __init sem_init (void) | |||
176 | 176 | ||
177 | static inline struct sem_array *sem_lock(struct ipc_namespace *ns, int id) | 177 | static inline struct sem_array *sem_lock(struct ipc_namespace *ns, int id) |
178 | { | 178 | { |
179 | return (struct sem_array *) ipc_lock(&sem_ids(ns), id); | 179 | struct kern_ipc_perm *ipcp = ipc_lock(&sem_ids(ns), id); |
180 | |||
181 | return container_of(ipcp, struct sem_array, sem_perm); | ||
180 | } | 182 | } |
181 | 183 | ||
182 | static inline struct sem_array *sem_lock_check(struct ipc_namespace *ns, | 184 | static inline struct sem_array *sem_lock_check(struct ipc_namespace *ns, |
183 | int id) | 185 | int id) |
184 | { | 186 | { |
185 | return (struct sem_array *) ipc_lock_check(&sem_ids(ns), id); | 187 | struct kern_ipc_perm *ipcp = ipc_lock_check(&sem_ids(ns), id); |
188 | |||
189 | return container_of(ipcp, struct sem_array, sem_perm); | ||
186 | } | 190 | } |
187 | 191 | ||
188 | static inline void sem_rmid(struct ipc_namespace *ns, struct sem_array *s) | 192 | static inline void sem_rmid(struct ipc_namespace *ns, struct sem_array *s) |
@@ -277,14 +281,21 @@ static int newary(struct ipc_namespace *ns, struct ipc_params *params) | |||
277 | } | 281 | } |
278 | 282 | ||
279 | 283 | ||
280 | static inline int sem_security(void *sma, int semflg) | 284 | static inline int sem_security(struct kern_ipc_perm *ipcp, int semflg) |
281 | { | 285 | { |
282 | return security_sem_associate((struct sem_array *) sma, semflg); | 286 | struct sem_array *sma; |
287 | |||
288 | sma = container_of(ipcp, struct sem_array, sem_perm); | ||
289 | return security_sem_associate(sma, semflg); | ||
283 | } | 290 | } |
284 | 291 | ||
285 | static inline int sem_more_checks(void *sma, struct ipc_params *params) | 292 | static inline int sem_more_checks(struct kern_ipc_perm *ipcp, |
293 | struct ipc_params *params) | ||
286 | { | 294 | { |
287 | if (params->u.nsems > ((struct sem_array *)sma)->sem_nsems) | 295 | struct sem_array *sma; |
296 | |||
297 | sma = container_of(ipcp, struct sem_array, sem_perm); | ||
298 | if (params->u.nsems > sma->sem_nsems) | ||
288 | return -EINVAL; | 299 | return -EINVAL; |
289 | 300 | ||
290 | return 0; | 301 | return 0; |
@@ -139,13 +139,17 @@ void __init shm_init (void) | |||
139 | 139 | ||
140 | static inline struct shmid_kernel *shm_lock(struct ipc_namespace *ns, int id) | 140 | static inline struct shmid_kernel *shm_lock(struct ipc_namespace *ns, int id) |
141 | { | 141 | { |
142 | return (struct shmid_kernel *) ipc_lock(&shm_ids(ns), id); | 142 | struct kern_ipc_perm *ipcp = ipc_lock(&shm_ids(ns), id); |
143 | |||
144 | return container_of(ipcp, struct shmid_kernel, shm_perm); | ||
143 | } | 145 | } |
144 | 146 | ||
145 | static inline struct shmid_kernel *shm_lock_check(struct ipc_namespace *ns, | 147 | static inline struct shmid_kernel *shm_lock_check(struct ipc_namespace *ns, |
146 | int id) | 148 | int id) |
147 | { | 149 | { |
148 | return (struct shmid_kernel *) ipc_lock_check(&shm_ids(ns), id); | 150 | struct kern_ipc_perm *ipcp = ipc_lock_check(&shm_ids(ns), id); |
151 | |||
152 | return container_of(ipcp, struct shmid_kernel, shm_perm); | ||
149 | } | 153 | } |
150 | 154 | ||
151 | static inline void shm_rmid(struct ipc_namespace *ns, struct shmid_kernel *s) | 155 | static inline void shm_rmid(struct ipc_namespace *ns, struct shmid_kernel *s) |
@@ -424,14 +428,21 @@ no_file: | |||
424 | return error; | 428 | return error; |
425 | } | 429 | } |
426 | 430 | ||
427 | static inline int shm_security(void *shp, int shmflg) | 431 | static inline int shm_security(struct kern_ipc_perm *ipcp, int shmflg) |
428 | { | 432 | { |
429 | return security_shm_associate((struct shmid_kernel *) shp, shmflg); | 433 | struct shmid_kernel *shp; |
434 | |||
435 | shp = container_of(ipcp, struct shmid_kernel, shm_perm); | ||
436 | return security_shm_associate(shp, shmflg); | ||
430 | } | 437 | } |
431 | 438 | ||
432 | static inline int shm_more_checks(void *shp, struct ipc_params *params) | 439 | static inline int shm_more_checks(struct kern_ipc_perm *ipcp, |
440 | struct ipc_params *params) | ||
433 | { | 441 | { |
434 | if (((struct shmid_kernel *)shp)->shm_segsz < params->u.size) | 442 | struct shmid_kernel *shp; |
443 | |||
444 | shp = container_of(ipcp, struct shmid_kernel, shm_perm); | ||
445 | if (shp->shm_segsz < params->u.size) | ||
435 | return -EINVAL; | 446 | return -EINVAL; |
436 | 447 | ||
437 | return 0; | 448 | return 0; |
diff --git a/ipc/util.h b/ipc/util.h index c4b0a9865bf5..2a03d8cc6a01 100644 --- a/ipc/util.h +++ b/ipc/util.h | |||
@@ -61,8 +61,8 @@ struct ipc_params { | |||
61 | */ | 61 | */ |
62 | struct ipc_ops { | 62 | struct ipc_ops { |
63 | int (*getnew) (struct ipc_namespace *, struct ipc_params *); | 63 | int (*getnew) (struct ipc_namespace *, struct ipc_params *); |
64 | int (*associate) (void *, int); | 64 | int (*associate) (struct kern_ipc_perm *, int); |
65 | int (*more_checks) (void *, struct ipc_params *); | 65 | int (*more_checks) (struct kern_ipc_perm *, struct ipc_params *); |
66 | }; | 66 | }; |
67 | 67 | ||
68 | struct seq_file; | 68 | struct seq_file; |