From patchwork Thu Jan 22 16:38:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 43538 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f199.google.com (mail-we0-f199.google.com [74.125.82.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EEEAE240DB for ; Thu, 22 Jan 2015 16:39:25 +0000 (UTC) Received: by mail-we0-f199.google.com with SMTP id k11sf1642443wes.2 for ; Thu, 22 Jan 2015 08:39:24 -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=lKC1JpAHGynCY5EWr34AkBRcKTCkeB7Sfb2xLRoVRPpxY0xiIlDRunFbwoB0dacz8/ wDzyknPgHyaiW6urJacQUCqUs/Cj5MuAIvbWRoxBGfp/MLcD8MecYP4D0zqsieo/D22N ixQixwXpBBbxyfOhVttECCxmR4kV8Cd1J2SETBw4gJu4abzAsOOopKxY+YeqvydIKQSV kmfPlJFCQUEi9hojPAz8n9YxhsFYCXIoEgXvCCazIlGtoOt7VVsLR4MQ8iCkvxaMUyWO AA8iGvCnf1oGymxscxPC1lfIR2AVlqDoR3J/yr2mL3xxQmUaAosNKiDIsOQmpL67rIqU GgGg== X-Gm-Message-State: ALoCoQnMMtD0y3Z5eMxX71obOtM6CI4VbdeVgH4QpJrvjjLHE4IXOoV7TE4DIpZvujwILCfdiJAl X-Received: by 10.180.74.140 with SMTP id t12mr531933wiv.2.1421944764731; Thu, 22 Jan 2015 08:39:24 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.11.163 with SMTP id ej3ls180288lad.94.gmail; Thu, 22 Jan 2015 08:39:24 -0800 (PST) X-Received: by 10.152.4.200 with SMTP id m8mr2692930lam.17.1421944764572; Thu, 22 Jan 2015 08:39:24 -0800 (PST) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id oe5si21230408lbb.2.2015.01.22.08.39.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Jan 2015 08:39:24 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by mail-la0-f44.google.com with SMTP id s18so2672679lam.3 for ; Thu, 22 Jan 2015 08:39:24 -0800 (PST) X-Received: by 10.112.64.35 with SMTP id l3mr2725959lbs.82.1421944764428; Thu, 22 Jan 2015 08:39:24 -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 c8csp321468lbb; Thu, 22 Jan 2015 08:39:23 -0800 (PST) X-Received: by 10.236.199.103 with SMTP id w67mr1361155yhn.37.1421944762936; Thu, 22 Jan 2015 08:39:22 -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 jl8si9515809qcb.30.2015.01.22.08.39.21 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 22 Jan 2015 08:39:22 -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 1YEKmu-0001ec-Kz; Thu, 22 Jan 2015 16:39:20 +0000 Received: from mail-la0-f47.google.com ([209.85.215.47]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YEKmi-0001c8-MQ for lng-odp@lists.linaro.org; Thu, 22 Jan 2015 16:39:08 +0000 Received: by mail-la0-f47.google.com with SMTP id hz20so2650343lab.6 for ; Thu, 22 Jan 2015 08:39:03 -0800 (PST) X-Received: by 10.152.3.70 with SMTP id a6mr2697403laa.71.1421944743049; Thu, 22 Jan 2015 08:39:03 -0800 (PST) Received: from localhost.localdomain (broadband-46-188-125-104.2com.net. [46.188.125.104]) by mx.google.com with ESMTPSA id f4sm1136853lam.30.2015.01.22.08.39.01 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 22 Jan 2015 08:39:01 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Thu, 22 Jan 2015 19:38:48 +0300 Message-Id: <1421944729-28510-2-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 In-Reply-To: <1421944729-28510-1-git-send-email-maxim.uvarov@linaro.org> References: <1421944729-28510-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv3 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.215.44 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;