[PATCH 39/44] kdbus: Cleanup kdbus_user_lookup()

From: Sergei Zviagintsev
Date: Thu Oct 08 2015 - 07:34:42 EST


- 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@xxxxxxxx>
---
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@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/