Skip to content

Commit

Permalink
IPC: use ipc_buildid() directly from ipc_addid()
Browse files Browse the repository at this point in the history
By continuing to consolidate a little the IPC code, each id can be built
directly in ipc_addid() instead of having it built from each callers of
ipc_addid()

And I also remove shm_addid() in order to have, as much as possible, the
same code for shm/sem/msg.

[[email protected]: coding-style fixes]
Signed-off-by: Pierre Peiffer <[email protected]>
Cc: Nadia Derbey <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Pierre Peiffer authored and torvalds committed Apr 29, 2008
1 parent 02d15c4 commit 48dea40
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 13 deletions.
2 changes: 0 additions & 2 deletions ipc/msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ struct msg_sender {
#define msg_ids(ns) ((ns)->ids[IPC_MSG_IDS])

#define msg_unlock(msq) ipc_unlock(&(msq)->q_perm)
#define msg_buildid(id, seq) ipc_buildid(id, seq)

static void freeque(struct ipc_namespace *, struct kern_ipc_perm *);
static int newque(struct ipc_namespace *, struct ipc_params *);
Expand Down Expand Up @@ -186,7 +185,6 @@ static int newque(struct ipc_namespace *ns, struct ipc_params *params)
return id;
}

msq->q_perm.id = msg_buildid(id, msq->q_perm.seq);
msq->q_stime = msq->q_rtime = 0;
msq->q_ctime = get_seconds();
msq->q_cbytes = msq->q_qnum = 0;
Expand Down
2 changes: 0 additions & 2 deletions ipc/sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@

#define sem_unlock(sma) ipc_unlock(&(sma)->sem_perm)
#define sem_checkid(sma, semid) ipc_checkid(&sma->sem_perm, semid)
#define sem_buildid(id, seq) ipc_buildid(id, seq)

static int newary(struct ipc_namespace *, struct ipc_params *);
static void freeary(struct ipc_namespace *, struct kern_ipc_perm *);
Expand Down Expand Up @@ -268,7 +267,6 @@ static int newary(struct ipc_namespace *ns, struct ipc_params *params)
}
ns->used_sems += nsems;

sma->sem_perm.id = sem_buildid(id, sma->sem_perm.seq);
sma->sem_base = (struct sem *) &sma[1];
/* sma->sem_pending = NULL; */
sma->sem_pending_last = &sma->sem_pending;
Expand Down
10 changes: 1 addition & 9 deletions ipc/shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ static struct vm_operations_struct shm_vm_ops;

#define shm_unlock(shp) \
ipc_unlock(&(shp)->shm_perm)
#define shm_buildid(id, seq) ipc_buildid(id, seq)

static int newseg(struct ipc_namespace *, struct ipc_params *);
static void shm_open(struct vm_area_struct *vma);
Expand Down Expand Up @@ -169,12 +168,6 @@ static inline void shm_rmid(struct ipc_namespace *ns, struct shmid_kernel *s)
ipc_rmid(&shm_ids(ns), &s->shm_perm);
}

static inline int shm_addid(struct ipc_namespace *ns, struct shmid_kernel *shp)
{
return ipc_addid(&shm_ids(ns), &shp->shm_perm, ns->shm_ctlmni);
}



/* This is called by fork, once for every shm attach. */
static void shm_open(struct vm_area_struct *vma)
Expand Down Expand Up @@ -416,7 +409,7 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
if (IS_ERR(file))
goto no_file;

id = shm_addid(ns, shp);
id = ipc_addid(&shm_ids(ns), &shp->shm_perm, ns->shm_ctlmni);
if (id < 0) {
error = id;
goto no_id;
Expand All @@ -428,7 +421,6 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
shp->shm_ctim = get_seconds();
shp->shm_segsz = size;
shp->shm_nattch = 0;
shp->shm_perm.id = shm_buildid(id, shp->shm_perm.seq);
shp->shm_file = file;
/*
* shmid gets reported as "inode#" in /proc/pid/maps.
Expand Down
1 change: 1 addition & 0 deletions ipc/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size)
if(ids->seq > ids->seq_max)
ids->seq = 0;

new->id = ipc_buildid(id, new->seq);
spin_lock_init(&new->lock);
new->deleted = 0;
rcu_read_lock();
Expand Down

0 comments on commit 48dea40

Please sign in to comment.