Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1242226

[PATCH 38/44] kdbus: Fix error path in kdbus_user_lookup()

Path csiph.com!eternal-september.org!feeder.eternal-september.org!aioe.org!bofh.it!news.nic.it!robomod
From Sergei Zviagintsev <sergei@s15v.net>
Newsgroups linux.kernel
Subject [PATCH 38/44] kdbus: Fix error path in kdbus_user_lookup()
Date Thu, 08 Oct 2015 13:40:01 +0200
Message-ID <qhhId-2d4-13@gated-at.bofh.it> (permalink)
References <qhhId-2d4-3@gated-at.bofh.it>
X-Original-To Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Daniel Mack <daniel@zonque.org>, David Herrmann <dh.herrmann@googlemail.com>, Djalal Harouni <tixxdz@opendz.org>
Dkim-Signature v=1; a=rsa-sha1; c=relaxed/relaxed; d=s15v.net; h=cc :date:from:in-reply-to:in-reply-to:message-id:references :references:subject:to:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=ERIMj YcH9heax71MzSNw/OgHipA=; b=HDfwPddFe302Bt0IwSwfbIYJnP90vzoPlFRJ4 RYEfsj+9yRSM42TYwOUpBMHBMvoJViibpi+Rwzug5YEWbmJjZGL7MKZ0sGRHYiB2 i8zzujFkiIJ8tSfUBPTEZ0y5Id0JS6L2SVY8Laub47fU/7xsiEGquSDrofspdzYn 0sTB1U=
Dkim-Signature v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:in-reply-to :message-id:references:references:subject:to:x-sasl-enc :x-sasl-enc; s=smtpout; bh=ERIMjYcH9heax71MzSNw/OgHipA=; b=dK+WG jkIkWnM8zf/mU+wQwIVn/owaGceRCb0B3CeYVZkK/SKQ5XRFlGShN1L7oD6KIpI+ bmybrSZKzaZguWc9teQRXtMkijBmdhHPTcuR211DcBaqd7YjVxLxI5EyzV1CVJdr HsczvhNj73YMxKbrmvkwJTExW+Qg/Wbohd03T4=
X-Sasl-Enc IV79uVtEe0uaoW+JYwxgdJgYKUCoOyf6kgvaAAzBxzwp 1444304066
X-Mailer git-send-email 1.8.3.1
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 67
Organization linux.* mail to news gateway
X-Original-Cc linux-kernel@vger.kernel.org, Sergei Zviagintsev <sergei@s15v.net>
X-Original-Date Thu, 8 Oct 2015 14:32:07 +0300
X-Original-Message-ID <1cbeb0e49e6a51048b4f5c71e8d34fc82ce0a7f3.1444302968.git.sergei@s15v.net>
X-Original-References <cover.1444302968.git.sergei@s15v.net>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1242226

Show key headers only | View raw


If idr_alloc() fails, we shouldn't call idr_remove() as latter produces
warning when called on non-allocated ids. Split cleanup code into three
parts for differrent cleanup scenarios before and after idr_alloc().

Signed-off-by: Sergei Zviagintsev <sergei@s15v.net>
---
 ipc/kdbus/domain.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/ipc/kdbus/domain.c b/ipc/kdbus/domain.c
index ac9f760c150d..31cd09fb572f 100644
--- a/ipc/kdbus/domain.c
+++ b/ipc/kdbus/domain.c
@@ -208,7 +208,7 @@ struct kdbus_user *kdbus_user_lookup(struct kdbus_domain *domain, kuid_t uid)
 	u = kzalloc(sizeof(*u), GFP_KERNEL);
 	if (!u) {
 		ret = -ENOMEM;
-		goto exit;
+		goto exit_unlock;
 	}
 
 	kref_init(&u->kref);
@@ -225,7 +225,7 @@ struct kdbus_user *kdbus_user_lookup(struct kdbus_domain *domain, kuid_t uid)
 			ret = idr_alloc(&domain->user_idr, u, __kuid_val(uid),
 					__kuid_val(uid) + 1, GFP_KERNEL);
 			if (ret < 0)
-				goto exit;
+				goto exit_free;
 		}
 	}
 
@@ -235,19 +235,19 @@ struct kdbus_user *kdbus_user_lookup(struct kdbus_domain *domain, kuid_t uid)
 	 */
 	ret = ida_simple_get(&domain->user_ida, 1, 0, GFP_KERNEL);
 	if (ret < 0)
-		goto exit;
+		goto exit_idr;
 
 	u->id = ret;
 	mutex_unlock(&domain->lock);
 	return u;
 
-exit:
-	if (u) {
-		if (uid_valid(u->uid))
-			idr_remove(&domain->user_idr, __kuid_val(u->uid));
-		kdbus_domain_unref(u->domain);
-		kfree(u);
-	}
+exit_idr:
+	if (uid_valid(u->uid))
+		idr_remove(&domain->user_idr, __kuid_val(u->uid));
+exit_free:
+	kdbus_domain_unref(u->domain);
+	kfree(u);
+exit_unlock:
 	mutex_unlock(&domain->lock);
 	return ERR_PTR(ret);
 }
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

[PATCH 38/44] kdbus: Fix error path in kdbus_user_lookup() Sergei Zviagintsev <sergei@s15v.net> - 2015-10-08 13:40 +0200
  Re: [PATCH 38/44] kdbus: Fix error path in kdbus_user_lookup() David Herrmann <dh.herrmann@gmail.com> - 2015-10-08 17:10 +0200
    Re: [PATCH 38/44] kdbus: Fix error path in kdbus_user_lookup() Sergei Zviagintsev <sergei@s15v.net> - 2015-10-09 20:50 +0200

csiph-web