From mboxrd@z Thu Jan 1 00:00:00 1970 From: Konrad Rzeszutek Wilk Subject: [PATCH v2.1 12/15] tmem: cleanup: refactor function tmemc_shared_pool_auth() Date: Wed, 9 Apr 2014 09:26:16 -0400 Message-ID: <1397049979-3479-13-git-send-email-konrad.wilk@oracle.com> References: <1397049979-3479-1-git-send-email-konrad.wilk@oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WXsWN-0000sy-9S for xen-devel@lists.xenproject.org; Wed, 09 Apr 2014 13:26:31 +0000 In-Reply-To: <1397049979-3479-1-git-send-email-konrad.wilk@oracle.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org, jbeulich@suse.com Cc: Bob Liu , Konrad Rzeszutek Wilk List-Id: xen-devel@lists.xenproject.org From: Bob Liu Make function tmemc_shared_pool_auth() more readable. Note that the previous check for free being set the first time '(free == -1)' in the loop is now removed. That is OK because when we set free the first time ('free = i;') we follow it immediately with a break to get out of the loop. Signed-off-by: Bob Liu Signed-off-by: Konrad Rzeszutek Wilk --- xen/common/tmem.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/xen/common/tmem.c b/xen/common/tmem.c index add236e..bad1bb9 100644 --- a/xen/common/tmem.c +++ b/xen/common/tmem.c @@ -2257,27 +2257,39 @@ static int tmemc_shared_pool_auth(domid_t cli_id, uint64_t uuid_lo, client = tmem_client_from_cli_id(cli_id); if ( client == NULL ) return -EINVAL; + for ( i = 0; i < MAX_GLOBAL_SHARED_POOLS; i++) { - if ( (client->shared_auth_uuid[i][0] == uuid_lo) && - (client->shared_auth_uuid[i][1] == uuid_hi) ) + if ( auth == 0 ) { - if ( auth == 0 ) - client->shared_auth_uuid[i][0] = - client->shared_auth_uuid[i][1] = -1L; - return 1; + if ( (client->shared_auth_uuid[i][0] == uuid_lo) && + (client->shared_auth_uuid[i][1] == uuid_hi) ) + { + client->shared_auth_uuid[i][0] = -1L; + client->shared_auth_uuid[i][1] = -1L; + return 1; + } } - if ( (auth == 1) && (client->shared_auth_uuid[i][0] == -1L) && - (client->shared_auth_uuid[i][1] == -1L) && (free == -1) ) - free = i; + else + { + if ( (client->shared_auth_uuid[i][0] == -1L) && + (client->shared_auth_uuid[i][1] == -1L) ) + { + free = i; + break; + } + } } if ( auth == 0 ) return 0; - if ( auth == 1 && free == -1 ) + else if ( free == -1) return -ENOMEM; - client->shared_auth_uuid[free][0] = uuid_lo; - client->shared_auth_uuid[free][1] = uuid_hi; - return 1; + else + { + client->shared_auth_uuid[free][0] = uuid_lo; + client->shared_auth_uuid[free][1] = uuid_hi; + return 1; + } } static int tmemc_save_subop(int cli_id, uint32_t pool_id, -- 1.8.5.3