From 8b7cfed90748d7bf5d35f03d83e7a105c4a26809 Mon Sep 17 00:00:00 2001 From: Djalal Harouni Date: Wed, 30 Jul 2014 21:11:52 +0100 Subject: [PATCH] domain: add kdbus_domain_user_assign_id() to assign IDs to domain users Signed-off-by: Djalal Harouni --- domain.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/domain.c b/domain.c index c4912fa..af9d986 100644 --- a/domain.c +++ b/domain.c @@ -418,6 +418,39 @@ int kdbus_domain_make_user(struct kdbus_cmd_make *cmd, char **name) return 0; } +/** + * kdbus_domain_user_assign_id() - allocate ID and assign in it to the + * domain user + * @domain: The domain of the user + * @user The kdbus_domain_user object of the user + * + * Returns 0 if ID in [0, INT_MAX] is successfully assigned to the + * domain user. Negative errno on failure. + * + * The user index is used in arrays for accounting user quota in + * receiver queues. + * + * Caller must have the domain lock held and must ensure that the + * domain was not disconnected. + */ +static int kdbus_domain_user_assign_id(struct kdbus_domain *domain, + struct kdbus_domain_user *user) +{ + int ret; + + /* + * Allocate the smallest possible index for this user; used + * in arrays for accounting user quota in receiver queues. + */ + ret = idr_alloc(&domain->user_idr, user, 0, 0, GFP_KERNEL); + if (ret < 0) + return ret; + + user->idr = ret; + + return 0; +} + /** * kdbus_domain_user_find_or_new() - get a kdbus_domain_user object in a domain * @domain: The domain -- 2.34.1