From 03f02c7657f7948ab980280c54c9366f962b1474 Mon Sep 17 00:00:00 2001 From: Nadia Derbey Date: Thu, 18 Oct 2007 23:40:51 -0700 Subject: 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 Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- ipc/shm.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'ipc/shm.c') diff --git a/ipc/shm.c b/ipc/shm.c index 8241264941a2..e2de16efe10d 100644 --- a/ipc/shm.c +++ b/ipc/shm.c @@ -139,13 +139,17 @@ void __init shm_init (void) static inline struct shmid_kernel *shm_lock(struct ipc_namespace *ns, int id) { - return (struct shmid_kernel *) ipc_lock(&shm_ids(ns), id); + struct kern_ipc_perm *ipcp = ipc_lock(&shm_ids(ns), id); + + return container_of(ipcp, struct shmid_kernel, shm_perm); } static inline struct shmid_kernel *shm_lock_check(struct ipc_namespace *ns, int id) { - return (struct shmid_kernel *) ipc_lock_check(&shm_ids(ns), id); + struct kern_ipc_perm *ipcp = ipc_lock_check(&shm_ids(ns), id); + + return container_of(ipcp, struct shmid_kernel, shm_perm); } static inline void shm_rmid(struct ipc_namespace *ns, struct shmid_kernel *s) @@ -424,14 +428,21 @@ no_file: return error; } -static inline int shm_security(void *shp, int shmflg) +static inline int shm_security(struct kern_ipc_perm *ipcp, int shmflg) { - return security_shm_associate((struct shmid_kernel *) shp, shmflg); + struct shmid_kernel *shp; + + shp = container_of(ipcp, struct shmid_kernel, shm_perm); + return security_shm_associate(shp, shmflg); } -static inline int shm_more_checks(void *shp, struct ipc_params *params) +static inline int shm_more_checks(struct kern_ipc_perm *ipcp, + struct ipc_params *params) { - if (((struct shmid_kernel *)shp)->shm_segsz < params->u.size) + struct shmid_kernel *shp; + + shp = container_of(ipcp, struct shmid_kernel, shm_perm); + if (shp->shm_segsz < params->u.size) return -EINVAL; return 0; -- cgit v1.2.1