From patchwork Thu Jan 22 14:25:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petri Savolainen X-Patchwork-Id: 43519 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f71.google.com (mail-ee0-f71.google.com [74.125.83.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0AEAF240DB for ; Thu, 22 Jan 2015 14:26:15 +0000 (UTC) Received: by mail-ee0-f71.google.com with SMTP id d49sf1836807eek.2 for ; Thu, 22 Jan 2015 06:26:13 -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=4FjMe9LI9gduwghDDueELmbasReOORdofjnspueiMhE=; b=GQ5tF4Vfhtg5cNOsIluDGGZiCF7F9YxlJnvhFwjr1giXDrgSNnkAEOHs/Pprxj2hoX FWtuYCohcBOibnOZkrlRNsS2zwkvKmVWPCdf5YjpcGWOmv+slaERTcnMshFuIO0PpHGX q8C6XAr1LcoJiMqwYyQN/VRXd44SSaHM4rxbCQcF9vHMlhhW45/hTKmpatPYlvSDHgsx St99v2ewySjkKC0SsKOZQIgcUHLFSug6+nUrMJmQ0/I3hI4RlIV0YoYWsUHhPSwKqGLv hnmo+bEx5Ni95P+YZYfu1HQuXdzgOwKS4iLjy8AGufv2bZtIUIASKcRazeeORfh8sFBW F9uA== X-Gm-Message-State: ALoCoQlzrsPY4Isw4Ynwr4AhuVCZkUtOdQxP8re2jT812z3VNSkV8qeufwSbUD/+4cM/wVcyjQSE X-Received: by 10.112.160.41 with SMTP id xh9mr278724lbb.12.1421936773813; Thu, 22 Jan 2015 06:26:13 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.161.198 with SMTP id xu6ls159508lab.86.gmail; Thu, 22 Jan 2015 06:26:13 -0800 (PST) X-Received: by 10.152.163.100 with SMTP id yh4mr1810856lab.98.1421936773671; Thu, 22 Jan 2015 06:26:13 -0800 (PST) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com. [209.85.217.176]) by mx.google.com with ESMTPS id kg2si20914432lbc.4.2015.01.22.06.26.13 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Jan 2015 06:26:13 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) client-ip=209.85.217.176; Received: by mail-lb0-f176.google.com with SMTP id z12so1799390lbi.7 for ; Thu, 22 Jan 2015 06:26:13 -0800 (PST) X-Received: by 10.112.26.135 with SMTP id l7mr1875759lbg.56.1421936773572; Thu, 22 Jan 2015 06:26:13 -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 c8csp279480lbb; Thu, 22 Jan 2015 06:26:12 -0800 (PST) X-Received: by 10.140.94.195 with SMTP id g61mr2823455qge.80.1421936772051; Thu, 22 Jan 2015 06:26:12 -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 ee7si9056231qcb.31.2015.01.22.06.26.10 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 22 Jan 2015 06:26:12 -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 1YEIhy-0003jY-Ip; Thu, 22 Jan 2015 14:26:06 +0000 Received: from mail-qa0-f54.google.com ([209.85.216.54]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YEIhq-0003eO-E0 for lng-odp@lists.linaro.org; Thu, 22 Jan 2015 14:25:58 +0000 Received: by mail-qa0-f54.google.com with SMTP id w8so1299799qac.13 for ; Thu, 22 Jan 2015 06:25:53 -0800 (PST) X-Received: by 10.229.240.130 with SMTP id la2mr3037331qcb.9.1421936753227; Thu, 22 Jan 2015 06:25:53 -0800 (PST) Received: from mcpro03.emea.nsn-net.net (ec2-23-23-178-99.compute-1.amazonaws.com. [23.23.178.99]) by mx.google.com with ESMTPSA id s9sm6460892qam.43.2015.01.22.06.25.51 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 22 Jan 2015 06:25:52 -0800 (PST) From: Petri Savolainen To: lng-odp@lists.linaro.org Date: Thu, 22 Jan 2015 16:25:10 +0200 Message-Id: <1421936710-21648-2-git-send-email-petri.savolainen@linaro.org> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1421936710-21648-1-git-send-email-petri.savolainen@linaro.org> References: <1421936710-21648-1-git-send-email-petri.savolainen@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH 2/2] 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: petri.savolainen@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.176 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 Added error checks to odp_shm_free and cleaned up the code. Signed-off-by: Petri Savolainen --- 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;