From patchwork Thu Jan 22 15:44:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 43522 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8D08E240DB for ; Thu, 22 Jan 2015 15:45:13 +0000 (UTC) Received: by mail-la0-f72.google.com with SMTP id gq15sf1490327lab.3 for ; Thu, 22 Jan 2015 07:45:12 -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=kXcQKhSu0/63xFWOCifftmJDQnCC+IZJDdxxtEOiqeMxRiaBIdXwicXgHYlbBaVEgt REkyvP3ff3fzUcmys4O6dBKilXWgZ0tiRW5/Gkf6kpBwcJ6fhYFe5GnRaSkBPYulz9Y0 EIEIb+UzwSdcsK/NiXRjyF+CwdS2SpcsQXlI85EWqA4KZ6ZMF1/LEs1RPXSpZpy1Fy+B jArIH1ma9bk+RaG0rB/CTroiRRB2uXFXm3HTzTZsY6UFSUP7+9VPGtCE/0tCglGVx0nz erNpVDtB+UkWJ2vzvnJVhZkKr9wnVfarVsENwF8MCfAPcTzPe9us5cvOBoxReHoWB2g/ Otgg== X-Gm-Message-State: ALoCoQm8mui0sVqGSMk8pti8KQ8VEc9BU1sGQ9ZHVnETBpySsX26FmQxDRZv2a58xXsMiySUchWc X-Received: by 10.152.36.168 with SMTP id r8mr341775laj.2.1421941512581; Thu, 22 Jan 2015 07:45:12 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.10.67 with SMTP id g3ls183375lab.25.gmail; Thu, 22 Jan 2015 07:45:12 -0800 (PST) X-Received: by 10.112.8.41 with SMTP id o9mr2424195lba.40.1421941512419; Thu, 22 Jan 2015 07:45:12 -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 pl3si15811699lac.8.2015.01.22.07.45.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Jan 2015 07:45:12 -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 l4so2205265lbv.13 for ; Thu, 22 Jan 2015 07:45:12 -0800 (PST) X-Received: by 10.112.180.135 with SMTP id do7mr2348488lbc.23.1421941512313; Thu, 22 Jan 2015 07:45:12 -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 c8csp303973lbb; Thu, 22 Jan 2015 07:45:11 -0800 (PST) X-Received: by 10.140.84.9 with SMTP id k9mr3417729qgd.45.1421941510891; Thu, 22 Jan 2015 07:45:10 -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 h45si4956162qgd.59.2015.01.22.07.45.09 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 22 Jan 2015 07:45:10 -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 1YEJwS-0007e7-45; Thu, 22 Jan 2015 15:45:08 +0000 Received: from mail-la0-f48.google.com ([209.85.215.48]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YEJwJ-0007ca-9A for lng-odp@lists.linaro.org; Thu, 22 Jan 2015 15:44:59 +0000 Received: by mail-la0-f48.google.com with SMTP id pv20so2326921lab.7 for ; Thu, 22 Jan 2015 07:44:53 -0800 (PST) X-Received: by 10.152.28.194 with SMTP id d2mr2331296lah.85.1421941493346; Thu, 22 Jan 2015 07:44:53 -0800 (PST) Received: from localhost.localdomain (broadband-46-188-125-104.2com.net. [46.188.125.104]) by mx.google.com with ESMTPSA id is5sm6405308lac.41.2015.01.22.07.44.52 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 22 Jan 2015 07:44:52 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Thu, 22 Jan 2015 18:44:44 +0300 Message-Id: <1421941485-13742-2-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 In-Reply-To: <1421941485-13742-1-git-send-email-maxim.uvarov@linaro.org> References: <1421941485-13742-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv2 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;