From: Changyeon Lee Date: Thu, 7 Jan 2021 08:22:00 +0000 (+0900) Subject: bo: use magic number for checking valid of bo X-Git-Tag: accepted/tizen/unified/20210115.125753~4 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Flibtbm.git;a=commitdiff_plain;h=10d8defd14fac319f913f9703a0dd6d6401f2f19 bo: use magic number for checking valid of bo Change-Id: I4bb5a73da0c9afc3fb6040e9063f5c1d92d87df2 --- diff --git a/src/tbm_bo.c b/src/tbm_bo.c index 7e190b1..527c30b 100644 --- a/src/tbm_bo.c +++ b/src/tbm_bo.c @@ -34,6 +34,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "tbm_bufmgr_int.h" #include "list.h" +#define TBM_BO_MAGIC 0xBF011234 + /* check condition */ #define TBM_BO_RETURN_IF_FAIL(cond) {\ if (!(cond)) {\ @@ -280,35 +282,28 @@ _tbm_bo_unlock(tbm_bo bo) } static int -_tbm_bo_is_valid(tbm_bo bo) +_tbm_bo_magic_check(tbm_bo bo) { - tbm_bufmgr bufmgr = NULL; - tbm_bo old_data = NULL; - - if (bo == NULL) { - TBM_ERR("error: bo is NULL.\n"); + if (bo->magic != TBM_BO_MAGIC) return 0; - } - bufmgr = tbm_bufmgr_get(); - if (bufmgr == NULL) { - TBM_ERR("error: bufmgr is NULL.\n"); - return 0; - } + return 1; +} - if (LIST_IS_EMPTY(&bufmgr->bo_list)) { - TBM_ERR("error: bo->bo->bufmgr->bo_list is EMPTY.\n"); +static int +_tbm_bo_is_valid(tbm_bo bo) +{ + if (!bo) { + TBM_ERR("error: bo is NULL.\n"); return 0; } - LIST_FOR_EACH_ENTRY(old_data, &bufmgr->bo_list, item_link) { - if (old_data == bo) - return 1; + if (!_tbm_bo_magic_check(bo)) { + TBM_ERR("error: No valid bo(%p).\n", bo); + return 0; } - TBM_ERR("error: No valid bo(%p).\n", bo); - - return 0; + return 1; } tbm_bo @@ -369,6 +364,7 @@ tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags) } bo->bufmgr->bo_cnt++; + bo->magic = TBM_BO_MAGIC; bo->ref_cnt = 1; bo->flags = flags; @@ -774,6 +770,7 @@ tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key) } bo->bufmgr->bo_cnt++; + bo->magic = TBM_BO_MAGIC; bo->ref_cnt = 1; if (bo->bufmgr->backend_module_data) { @@ -903,6 +900,7 @@ tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd) } bo->bufmgr->bo_cnt++; + bo->magic = TBM_BO_MAGIC; bo->ref_cnt = 1; if (bo->bufmgr->backend_module_data) { @@ -1246,6 +1244,7 @@ _tbm_bo_free(tbm_bo bo) bo->priv = NULL; } + bo->magic = 0; bo->bufmgr->bo_cnt--; LIST_DEL(&bo->item_link); diff --git a/src/tbm_bufmgr_int.h b/src/tbm_bufmgr_int.h index da0997d..f4e6e28 100644 --- a/src/tbm_bufmgr_int.h +++ b/src/tbm_bufmgr_int.h @@ -167,6 +167,7 @@ struct list_head { * @brief tbm_bo : buffer object of Tizen Buffer Manager */ struct _tbm_bo { + unsigned int magic; /* tbm bo magic number */ tbm_bufmgr bufmgr; /* tbm buffer manager */ int ref_cnt; /* ref count of bo */ int flags; /* TBM_BO_FLAGS :bo memory type */