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>
diff --git a/ipc/shm.c b/ipc/shm.c
index 8241264..e2de16e 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -139,13 +139,17 @@
 
 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 @@
 	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;