aboutsummaryrefslogtreecommitdiff
path: root/ipc/shm.c
diff options
context:
space:
mode:
authorNadia Derbey <Nadia.Derbey@bull.net>2007-10-18 23:40:53 -0700
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-19 11:53:47 -0700
commitf4566f04854d78acfc74b9acb029744acde9d033 (patch)
tree6fa631076d11511e2d9685b23c195835c31f4900 /ipc/shm.c
parent28028313134e9f11e49f74a4beaa47c91e5ebf06 (diff)
ipc: fix wrong comments
This patch fixes the wrong / obsolete comments in the ipc code. Also adds a missing lock around ipc_get_maxid() in shm_get_stat(). 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/shm.c')
-rw-r--r--ipc/shm.c39
1 files changed, 26 insertions, 13 deletions
diff --git a/ipc/shm.c b/ipc/shm.c
index e2de16efe10..f28f2a3163e 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -82,6 +82,10 @@ static void __shm_init_ns(struct ipc_namespace *ns, struct ipc_ids *ids)
ipc_init_ids(ids);
}
+/*
+ * Called with shm_ids.mutex and the shp structure locked.
+ * Only shm_ids.mutex remains locked on exit.
+ */
static void do_shm_rmid(struct ipc_namespace *ns, struct shmid_kernel *shp)
{
if (shp->shm_nattch){
@@ -182,6 +186,7 @@ static void shm_open(struct vm_area_struct *vma)
/*
* shm_destroy - free the struct shmid_kernel
*
+ * @ns: namespace
* @shp: struct to free
*
* It has to be called with shp and shm_ids.mutex locked,
@@ -343,6 +348,14 @@ static struct vm_operations_struct shm_vm_ops = {
#endif
};
+/**
+ * newseg - Create a new shared memory segment
+ * @ns: namespace
+ * @params: ptr to the structure that contains key, size and shmflg
+ *
+ * Called with shm_ids.mutex held
+ */
+
static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
{
key_t key = params->key;
@@ -428,6 +441,9 @@ no_file:
return error;
}
+/*
+ * Called with shm_ids.mutex and ipcp locked.
+ */
static inline int shm_security(struct kern_ipc_perm *ipcp, int shmflg)
{
struct shmid_kernel *shp;
@@ -436,6 +452,9 @@ static inline int shm_security(struct kern_ipc_perm *ipcp, int shmflg)
return security_shm_associate(shp, shmflg);
}
+/*
+ * Called with shm_ids.mutex and ipcp locked.
+ */
static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
struct ipc_params *params)
{
@@ -558,6 +577,9 @@ static inline unsigned long copy_shminfo_to_user(void __user *buf, struct shminf
}
}
+/*
+ * Called with shm_ids.mutex held
+ */
static void shm_get_stat(struct ipc_namespace *ns, unsigned long *rss,
unsigned long *swp)
{
@@ -573,18 +595,6 @@ static void shm_get_stat(struct ipc_namespace *ns, unsigned long *rss,
struct shmid_kernel *shp;
struct inode *inode;
- /*
- * idr_find() is called via shm_get(), so with shm_ids.mutex
- * locked. Since ipc_addid() is also called with
- * shm_ids.mutex down, there is no need to add read barriers
- * here to gurantee the writes in ipc_addid() are seen in
- * order here (for Alpha).
- * However idr_find() itself does not necessary require
- * ipc_ids.mutex down. So if idr_find() is used by other
- * places without ipc_ids.mutex down, then it needs read
- * read memory barriers as ipc_lock() does.
- */
-
shp = idr_find(&shm_ids(ns).ipcs_idr, next_id);
if (shp == NULL)
continue;
@@ -638,8 +648,11 @@ asmlinkage long sys_shmctl (int shmid, int cmd, struct shmid_ds __user *buf)
shminfo.shmmin = SHMMIN;
if(copy_shminfo_to_user (buf, &shminfo, version))
return -EFAULT;
- /* reading a integer is always atomic */
+
+ mutex_lock(&shm_ids(ns).mutex);
err = ipc_get_maxid(&shm_ids(ns));
+ mutex_unlock(&shm_ids(ns).mutex);
+
if(err<0)
err = 0;
goto out;