public inbox for linux-next@vger.kernel.org 
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel•org>
To: Sedat Dilek <sedat.dilek@gmail•com>
Cc: Stephen Rothwell <sfr@canb•auug.org.au>,
	linux-next@vger•kernel.org, linux-kernel@vger•kernel.org,
	Al Viro <viro@zeniv•linux.org.uk>,
	"Eric W. Biederman" <ebiederm@xmission•com>,
	Andrew Morton <akpm@linux-foundation•org>
Subject: [PATCH v2] ipc: convert to idr_alloc()
Date: Thu, 7 Feb 2013 08:14:04 -0800	[thread overview]
Message-ID: <20130207161404.GK2875@htj.dyndns.org> (raw)
In-Reply-To: <CA+icZUU23tENcnh=jH9FXk82X=8MUAJAYeZpfDOhnt3MWoLzhQ@mail.gmail.com>

Convert to the much saner new idr interface.

The new interface doesn't directly translate to the way idr_pre_get()
was used around ipc_addid() as preloading disables preemption.  From
my cursory reading, it seems like we should be able to do all
allocation from ipc_addid(), so I moved it there.  Can you please
check whether this would be okay?  If this is wrong and ipc_addid()
should be allowed to be called from non-sleepable context, I'd suggest
allocating id itself in the outer functions and later install the
pointer using idr_replace().

Only compile tested.

v2: The v1 conversion of ipcget_public() was incorrect.  As
    idr_pre_get() returns 0 for -ENOMEM failure, @err should have been
    initialized to 1 not 0.  As the function doesn't do preloading
    itself anymore, there's no point in the error handling path.
    Simply remove the -ENOMEM path.

Signed-off-by: Tejun Heo <tj@kernel•org>
Reported-by: Sedat Dilek <sedat.dilek@gmail•com>
Cc: Stanislav Kinsbursky <skinsbursky@parallels•com>
Cc: "Eric W. Biederman" <ebiederm@xmission•com>
Cc: James Morris <jmorris@namei•org>
---
Yeah, I messed up the ipcget_public() conversion.  Can you please test
this one?

Thanks.

 ipc/util.c |   30 +++++++++---------------------
 1 file changed, 9 insertions(+), 21 deletions(-)

--- a/ipc/util.c
+++ b/ipc/util.c
@@ -252,7 +252,7 @@ int ipc_addid(struct ipc_ids* ids, struc
 {
 	kuid_t euid;
 	kgid_t egid;
-	int id, err;
+	int id;
 	int next_id = ids->next_id;
 
 	if (size > IPCMNI)
@@ -261,17 +261,21 @@ int ipc_addid(struct ipc_ids* ids, struc
 	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++;
@@ -307,19 +311,10 @@ static int ipcget_new(struct ipc_namespa
 		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;
 }
 
@@ -376,8 +371,6 @@ static int ipcget_public(struct ipc_name
 	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
@@ -389,8 +382,6 @@ retry:
 		/* key not used */
 		if (!(flg & IPC_CREAT))
 			err = -ENOENT;
-		else if (!err)
-			err = -ENOMEM;
 		else
 			err = ops->getnew(ns, params);
 	} else {
@@ -413,9 +404,6 @@ retry:
 	}
 	up_write(&ids->rw_mutex);
 
-	if (err == -EAGAIN)
-		goto retry;
-
 	return err;
 }
 

  reply	other threads:[~2013-02-07 16:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-07  9:38 linux-next: Tree for Feb 7 (fakeroot BROKEN due to SYSV IPC support?) Sedat Dilek
2013-02-07 10:20 ` Sedat Dilek
2013-02-07 10:42   ` Sedat Dilek
2013-02-07 11:14     ` Eric W. Biederman
2013-02-07 11:52       ` Sedat Dilek
2013-02-07 13:39         ` Sedat Dilek
2013-02-07 14:40           ` Sedat Dilek
2013-02-07 16:14             ` Tejun Heo [this message]
2013-02-07 19:15               ` [PATCH v2] ipc: convert to idr_alloc() Sedat Dilek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130207161404.GK2875@htj.dyndns.org \
    --to=tj@kernel$(echo .)org \
    --cc=akpm@linux-foundation$(echo .)org \
    --cc=ebiederm@xmission$(echo .)com \
    --cc=linux-kernel@vger$(echo .)kernel.org \
    --cc=linux-next@vger$(echo .)kernel.org \
    --cc=sedat.dilek@gmail$(echo .)com \
    --cc=sfr@canb$(echo .)auug.org.au \
    --cc=viro@zeniv$(echo .)linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox