From patchwork Fri Jan 23 12:34:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 43634 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 839AE240D9 for ; Fri, 23 Jan 2015 12:35:33 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id b13sf4050682wgh.1 for ; Fri, 23 Jan 2015 04:35:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=DPWYbQFD76LdJ1IKeje+aSKxmcYMLKjsdXPTglLcEFI=; b=lP4EabQXS5sdmkPxX04wJsPEbZ65W3j6nE5nUXSnaChpyCKA7RKjxIzNHJgPIKkSGj DcdNZx8wxN0B3a5vWeEYYa1m7Xl0kydZpW1971Yw28tbuiL+P5yB9E75FBIhFvWIYapl 899NNgbYSjfZfhtv0S95SPlAaM0QdJQEce31w4rnTB4iUALDDck1ob68E0qWw495JVKG 7EqBe5jd5GebWw9pCPRWLgcj3Octy1UM0HjYMZtvrOGX1i2DNmGCq8Pi+oGex/TaAmEk /b0aXfEaiV2mtHx9Meb1eajXbc94DCRKEA/ZspMaTOnCYrNfgsBadimfZMnMofkx0Rx/ TidQ== X-Gm-Message-State: ALoCoQnCrxVxG1KBFOJWSomfzf0oHQdRAIHaVxWcQA0yApOsuru8AbSOqFW2flKqdpMxMmHhXrkI X-Received: by 10.112.174.36 with SMTP id bp4mr194946lbc.15.1422016532808; Fri, 23 Jan 2015 04:35:32 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.37.137 with SMTP id y9ls302342laj.59.gmail; Fri, 23 Jan 2015 04:35:32 -0800 (PST) X-Received: by 10.112.12.65 with SMTP id w1mr7078926lbb.68.1422016532584; Fri, 23 Jan 2015 04:35:32 -0800 (PST) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id wg10si1209804lbb.118.2015.01.23.04.35.32 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Jan 2015 04:35:32 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by mail-lb0-f182.google.com with SMTP id l4so6743780lbv.13 for ; Fri, 23 Jan 2015 04:35:32 -0800 (PST) X-Received: by 10.152.45.4 with SMTP id i4mr7157628lam.74.1422016532500; Fri, 23 Jan 2015 04:35:32 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.9.200 with SMTP id c8csp236699lbb; Fri, 23 Jan 2015 04:35:31 -0800 (PST) X-Received: by 10.229.221.196 with SMTP id id4mr13594564qcb.16.1422016531006; Fri, 23 Jan 2015 04:35:31 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id d2si1689367qaf.109.2015.01.23.04.35.29 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 23 Jan 2015 04:35:30 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YEdSR-0006HO-UK; Fri, 23 Jan 2015 12:35:27 +0000 Received: from mail-lb0-f181.google.com ([209.85.217.181]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YEdSE-00068Y-Ug for lng-odp@lists.linaro.org; Fri, 23 Jan 2015 12:35:15 +0000 Received: by mail-lb0-f181.google.com with SMTP id u10so6739214lbd.12 for ; Fri, 23 Jan 2015 04:35:09 -0800 (PST) X-Received: by 10.112.133.4 with SMTP id oy4mr7032859lbb.83.1422016509381; Fri, 23 Jan 2015 04:35:09 -0800 (PST) Received: from localhost.localdomain ([188.92.105.210]) by mx.google.com with ESMTPSA id qg5sm410897lbb.42.2015.01.23.04.35.07 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 23 Jan 2015 04:35:08 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Fri, 23 Jan 2015 15:34:33 +0300 Message-Id: <1422016474-8676-2-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 In-Reply-To: <1422016474-8676-1-git-send-email-maxim.uvarov@linaro.org> References: <1422016474-8676-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv4 2/3] linux-generic: shm: clean up and added debug info X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: maxim.uvarov@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Petri Savolainen Added error checks to odp_shm_free and cleaned up the code. Signed-off-by: Petri Savolainen Signed-off-by: Maxim Uvarov --- platform/linux-generic/odp_shared_memory.c | 49 +++++++++++++++++++----------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/platform/linux-generic/odp_shared_memory.c b/platform/linux-generic/odp_shared_memory.c index 7d54f09..23a9ceb 100644 --- a/platform/linux-generic/odp_shared_memory.c +++ b/platform/linux-generic/odp_shared_memory.c @@ -24,6 +24,7 @@ #include #include +#include #define ODP_SHM_NUM_BLOCKS 32 @@ -33,6 +34,7 @@ typedef struct { char name[ODP_SHM_NAME_LEN]; uint64_t size; uint64_t align; + uint64_t alloc_size; void *addr_orig; void *addr; int huge; @@ -122,35 +124,47 @@ int odp_shm_free(odp_shm_t shm) { uint32_t i; int ret; - odp_shm_block_t *shm_block; - uint64_t alloc_size; + odp_shm_block_t *block; + + if (shm == ODP_SHM_INVALID) { + ODP_DBG("odp_shm_free: Invalid handle\n"); + return -1; + } i = from_handle(shm); - if (NULL == odp_shm_tbl->block[i].addr) { - ODP_DBG("odp_shm_free: Free block\n"); - return 0; + + if (i >= ODP_SHM_NUM_BLOCKS) { + ODP_DBG("odp_shm_free: Bad handle\n"); + return -1; } odp_spinlock_lock(&odp_shm_tbl->lock); - shm_block = &odp_shm_tbl->block[i]; - alloc_size = shm_block->size + shm_block->align; - ret = munmap(shm_block->addr_orig, alloc_size); + block = &odp_shm_tbl->block[i]; + + if (block->addr == NULL) { + ODP_DBG("odp_shm_free: Free block\n"); + odp_spinlock_unlock(&odp_shm_tbl->lock); + return 0; + } + + ret = munmap(block->addr_orig, block->alloc_size); if (0 != ret) { - ODP_DBG("odp_shm_free: munmap failed\n"); + ODP_DBG("odp_shm_free: munmap failed: %s, id %u, addr %p\n", + strerror(errno), i, block->addr_orig); odp_spinlock_unlock(&odp_shm_tbl->lock); return -1; } - if (shm_block->flags & ODP_SHM_PROC) { - ret = shm_unlink(shm_block->name); + if (block->flags & ODP_SHM_PROC) { + ret = shm_unlink(block->name); if (0 != ret) { ODP_DBG("odp_shm_free: shm_unlink failed\n"); odp_spinlock_unlock(&odp_shm_tbl->lock); return -1; } } - memset(&odp_shm_tbl->block[i], 0, sizeof(odp_shm_block_t)); + memset(block, 0, sizeof(odp_shm_block_t)); odp_spinlock_unlock(&odp_shm_tbl->lock); return 0; } @@ -251,11 +265,12 @@ odp_shm_t odp_shm_reserve(const char *name, uint64_t size, uint64_t align, strncpy(block->name, name, ODP_SHM_NAME_LEN - 1); block->name[ODP_SHM_NAME_LEN - 1] = 0; - block->size = size; - block->align = align; - block->flags = flags; - block->fd = fd; - block->addr = addr; + block->size = size; + block->align = align; + block->alloc_size = alloc_size; + block->flags = flags; + block->fd = fd; + block->addr = addr; odp_spinlock_unlock(&odp_shm_tbl->lock); return block->hdl;