Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 359373
b: refs/heads/master
c: 54924ea
h: refs/heads/master
i:
  359371: 9818a0b
v: v3
  • Loading branch information
Tejun Heo authored and Linus Torvalds committed Feb 28, 2013
1 parent de350dc commit fc5ad23
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 22 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 6b207ba3ebe7428a18878c58130e13a3e3bccef9
refs/heads/master: 54924ea33f3ba702243ba4ab068d7d2852db8098
30 changes: 9 additions & 21 deletions trunk/ipc/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size)
{
kuid_t euid;
kgid_t egid;
int id, err;
int id;
int next_id = ids->next_id;

if (size > IPCMNI)
Expand All @@ -261,17 +261,21 @@ int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size)
if (ids->in_use >= size)
return -ENOSPC;

idr_preload(GFP_KERNEL);

spin_lock_init(&new->lock);
new->deleted = 0;
rcu_read_lock();
spin_lock(&new->lock);

err = idr_get_new_above(&ids->ipcs_idr, new,
(next_id < 0) ? 0 : ipcid_to_idx(next_id), &id);
if (err) {
id = idr_alloc(&ids->ipcs_idr, new,
(next_id < 0) ? 0 : ipcid_to_idx(next_id), 0,
GFP_NOWAIT);
idr_preload_end();
if (id < 0) {
spin_unlock(&new->lock);
rcu_read_unlock();
return err;
return id;
}

ids->in_use++;
Expand Down Expand Up @@ -307,19 +311,10 @@ static int ipcget_new(struct ipc_namespace *ns, struct ipc_ids *ids,
struct ipc_ops *ops, struct ipc_params *params)
{
int err;
retry:
err = idr_pre_get(&ids->ipcs_idr, GFP_KERNEL);

if (!err)
return -ENOMEM;

down_write(&ids->rw_mutex);
err = ops->getnew(ns, params);
up_write(&ids->rw_mutex);

if (err == -EAGAIN)
goto retry;

return err;
}

Expand Down Expand Up @@ -376,8 +371,6 @@ static int ipcget_public(struct ipc_namespace *ns, struct ipc_ids *ids,
struct kern_ipc_perm *ipcp;
int flg = params->flg;
int err;
retry:
err = idr_pre_get(&ids->ipcs_idr, GFP_KERNEL);

/*
* Take the lock as a writer since we are potentially going to add
Expand All @@ -389,8 +382,6 @@ static int ipcget_public(struct ipc_namespace *ns, struct ipc_ids *ids,
/* key not used */
if (!(flg & IPC_CREAT))
err = -ENOENT;
else if (!err)
err = -ENOMEM;
else
err = ops->getnew(ns, params);
} else {
Expand All @@ -413,9 +404,6 @@ static int ipcget_public(struct ipc_namespace *ns, struct ipc_ids *ids,
}
up_write(&ids->rw_mutex);

if (err == -EAGAIN)
goto retry;

return err;
}

Expand Down

0 comments on commit fc5ad23

Please sign in to comment.