return ret;
}
-/**
- * kdbus_domain_user_find_or_new() - get a kdbus_domain_user object in a domain
- * @domain: The domain
- * @uid: The uid of the user; INVALID_UID for an anonymous
- * user like a custom endpoint
- *
- * Return: a kdbus_domain_user, either freshly allocated or with the reference
- * counter increased. In case of memory allocation failure, NULL is returned.
- */
-struct kdbus_domain_user
-*kdbus_domain_user_find_or_new(struct kdbus_domain *domain, kuid_t uid)
-{
- struct kdbus_domain_user *u;
- int ret;
-
- /* find uid and reference it */
- if (uid_valid(uid)) {
- mutex_lock(&domain->lock);
- hash_for_each_possible(domain->user_hash, u,
- hentry, __kuid_val(uid)) {
- if (!uid_eq(u->uid, uid))
- continue;
-
- kref_get(&u->kref);
- mutex_unlock(&domain->lock);
- return u;
- }
- mutex_unlock(&domain->lock);
- }
-
- /* allocate a new user */
- u = kzalloc(sizeof(*u), GFP_KERNEL);
- if (!u)
- return NULL;
-
- kref_init(&u->kref);
- u->domain = kdbus_domain_ref(domain);
- u->uid = uid;
- atomic_set(&u->buses, 0);
- atomic_set(&u->connections, 0);
-
- /* link into domain */
- mutex_lock(&domain->lock);
- if (domain->disconnected) {
- mutex_unlock(&domain->lock);
- kfree(u);
- return NULL;
- }
-
- /*
- * Allocate the smallest possible index for this user; used
- * in arrays for accounting user quota in receiver queues.
- */
- ret = idr_alloc(&domain->user_idr, u, 0, 0, GFP_KERNEL);
- if (ret < 0) {
- mutex_unlock(&domain->lock);
- return NULL;
- }
- u->idr = ret;
-
- /* UID hash map */
- hash_add(domain->user_hash, &u->hentry, __kuid_val(u->uid));
- mutex_unlock(&domain->lock);
-
- return u;
-}
-
static void __kdbus_domain_user_free(struct kref *kref)
{
struct kdbus_domain_user *user =