[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <14bfc3816927222e1e50dfeb8b1df91f7267bd49.1444302968.git.sergei@s15v.net>
Date: Thu, 8 Oct 2015 14:32:08 +0300
From: Sergei Zviagintsev <sergei@...v.net>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Daniel Mack <daniel@...que.org>,
David Herrmann <dh.herrmann@...glemail.com>,
Djalal Harouni <tixxdz@...ndz.org>
Cc: linux-kernel@...r.kernel.org, Sergei Zviagintsev <sergei@...v.net>
Subject: [PATCH 39/44] kdbus: Cleanup kdbus_user_lookup()
- Do not initialize `u' with NULL as value is assigned to it at the
first use.
- Simplify if-statement. If `old' is non-NULL, it means that provided
@uid is valid, so there is no need to check both.
- Use `uid' and `domain' instead of `u->uid' and `u->domain' in error
path, which is equivalent but more concise and readable (as we used
same vars in the code above).
Signed-off-by: Sergei Zviagintsev <sergei@...v.net>
---
ipc/kdbus/domain.c | 26 ++++++++++++--------------
1 file changed, 12 insertions(+), 14 deletions(-)
diff --git a/ipc/kdbus/domain.c b/ipc/kdbus/domain.c
index 31cd09fb572f..1da893089889 100644
--- a/ipc/kdbus/domain.c
+++ b/ipc/kdbus/domain.c
@@ -188,7 +188,7 @@ int kdbus_domain_populate(struct kdbus_domain *domain, unsigned int access)
*/
struct kdbus_user *kdbus_user_lookup(struct kdbus_domain *domain, kuid_t uid)
{
- struct kdbus_user *u = NULL, *old = NULL;
+ struct kdbus_user *u, *old = NULL;
int ret;
mutex_lock(&domain->lock);
@@ -217,16 +217,14 @@ struct kdbus_user *kdbus_user_lookup(struct kdbus_domain *domain, kuid_t uid)
atomic_set(&u->buses, 0);
atomic_set(&u->connections, 0);
- if (uid_valid(uid)) {
- if (old) {
- idr_replace(&domain->user_idr, u, __kuid_val(uid));
- old->uid = INVALID_UID; /* mark old as removed */
- } else {
- ret = idr_alloc(&domain->user_idr, u, __kuid_val(uid),
- __kuid_val(uid) + 1, GFP_KERNEL);
- if (ret < 0)
- goto exit_free;
- }
+ if (old) {
+ idr_replace(&domain->user_idr, u, __kuid_val(uid));
+ old->uid = INVALID_UID; /* mark old as removed */
+ } else if (uid_valid(uid)) {
+ ret = idr_alloc(&domain->user_idr, u, __kuid_val(uid),
+ __kuid_val(uid) + 1, GFP_KERNEL);
+ if (ret < 0)
+ goto exit_free;
}
/*
@@ -242,10 +240,10 @@ struct kdbus_user *kdbus_user_lookup(struct kdbus_domain *domain, kuid_t uid)
return u;
exit_idr:
- if (uid_valid(u->uid))
- idr_remove(&domain->user_idr, __kuid_val(u->uid));
+ if (uid_valid(uid))
+ idr_remove(&domain->user_idr, __kuid_val(uid));
exit_free:
- kdbus_domain_unref(u->domain);
+ kdbus_domain_unref(domain);
kfree(u);
exit_unlock:
mutex_unlock(&domain->lock);
--
1.8.3.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists