From a439d3767d14fff26f4435174fd6d1f00b874074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konsta=20H=C3=B6ltt=C3=A4?= Date: Thu, 13 Aug 2020 10:55:42 +0300 Subject: [PATCH] gpu: nvgpu: silence coverity on fence code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - use release instead of free for the fence destroy identifier - nvhost_dev is a struct name, so use nvhost_device - compare nvgpu_nvhost_syncpt_read_ext_check retval properly Also, if the syncpt read fails when checking for fence expiration, behave as if the wait isn't expired. Possibly getting stuck is safer than possibly continuing too early. Jira NVGPU-5617 Change-Id: Ied529e25f8c43f1c78fd9eac73b9cd6c3550ead5 Signed-off-by: Konsta Hölttä Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2398399 Reviewed-by: automaticguardword Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-cert Reviewed-by: Alex Waterman Reviewed-by: mobile promotions GVS: Gerrit_Virtual_Submit Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/fence/fence.c | 6 ++--- drivers/gpu/nvgpu/common/fence/fence_priv.h | 2 +- drivers/gpu/nvgpu/common/fence/fence_sema.c | 4 +-- drivers/gpu/nvgpu/common/fence/fence_syncpt.c | 25 +++++++++++-------- drivers/gpu/nvgpu/include/nvgpu/fence.h | 2 +- .../gpu/nvgpu/include/nvgpu/fence_syncpt.h | 2 +- .../nvgpu/include/nvgpu/os_fence_syncpts.h | 4 +-- drivers/gpu/nvgpu/os/linux/os_fence_syncpt.c | 4 +-- 8 files changed, 27 insertions(+), 22 deletions(-) diff --git a/drivers/gpu/nvgpu/common/fence/fence.c b/drivers/gpu/nvgpu/common/fence/fence.c index d5edf76d5..1b56c4040 100644 --- a/drivers/gpu/nvgpu/common/fence/fence.c +++ b/drivers/gpu/nvgpu/common/fence/fence.c @@ -33,7 +33,7 @@ static struct nvgpu_fence_type *nvgpu_fence_from_ref(struct nvgpu_ref *ref) offsetof(struct nvgpu_fence_type, priv.ref)); } -static void nvgpu_fence_free(struct nvgpu_ref *ref) +static void nvgpu_fence_release(struct nvgpu_ref *ref) { struct nvgpu_fence_type *f = nvgpu_fence_from_ref(ref); struct nvgpu_fence_type_priv *pf = &f->priv; @@ -42,14 +42,14 @@ static void nvgpu_fence_free(struct nvgpu_ref *ref) pf->os_fence.ops->drop_ref(&pf->os_fence); } - pf->ops->free(f); + pf->ops->release(f); } void nvgpu_fence_put(struct nvgpu_fence_type *f) { struct nvgpu_fence_type_priv *pf = &f->priv; - nvgpu_ref_put(&pf->ref, nvgpu_fence_free); + nvgpu_ref_put(&pf->ref, nvgpu_fence_release); } struct nvgpu_fence_type *nvgpu_fence_get(struct nvgpu_fence_type *f) diff --git a/drivers/gpu/nvgpu/common/fence/fence_priv.h b/drivers/gpu/nvgpu/common/fence/fence_priv.h index 14e45d1ed..1a95abc2c 100644 --- a/drivers/gpu/nvgpu/common/fence/fence_priv.h +++ b/drivers/gpu/nvgpu/common/fence/fence_priv.h @@ -29,7 +29,7 @@ struct nvgpu_fence_type; struct nvgpu_fence_ops { int (*wait)(struct nvgpu_fence_type *f, u32 timeout); bool (*is_expired)(struct nvgpu_fence_type *f); - void (*free)(struct nvgpu_fence_type *f); + void (*release)(struct nvgpu_fence_type *f); }; void nvgpu_fence_init(struct nvgpu_fence_type *f, diff --git a/drivers/gpu/nvgpu/common/fence/fence_sema.c b/drivers/gpu/nvgpu/common/fence/fence_sema.c index 30f587919..c68188c8a 100644 --- a/drivers/gpu/nvgpu/common/fence/fence_sema.c +++ b/drivers/gpu/nvgpu/common/fence/fence_sema.c @@ -47,7 +47,7 @@ static bool nvgpu_fence_semaphore_is_expired(struct nvgpu_fence_type *f) return !nvgpu_semaphore_is_acquired(pf->semaphore); } -static void nvgpu_fence_semaphore_free(struct nvgpu_fence_type *f) +static void nvgpu_fence_semaphore_release(struct nvgpu_fence_type *f) { struct nvgpu_fence_type_priv *pf = &f->priv; @@ -59,7 +59,7 @@ static void nvgpu_fence_semaphore_free(struct nvgpu_fence_type *f) static const struct nvgpu_fence_ops nvgpu_fence_semaphore_ops = { .wait = nvgpu_fence_semaphore_wait, .is_expired = nvgpu_fence_semaphore_is_expired, - .free = nvgpu_fence_semaphore_free, + .release = nvgpu_fence_semaphore_release, }; /* This function takes ownership of the semaphore as well as the os_fence */ diff --git a/drivers/gpu/nvgpu/common/fence/fence_syncpt.c b/drivers/gpu/nvgpu/common/fence/fence_syncpt.c index a3da9b310..f57d1e54d 100644 --- a/drivers/gpu/nvgpu/common/fence/fence_syncpt.c +++ b/drivers/gpu/nvgpu/common/fence/fence_syncpt.c @@ -30,7 +30,7 @@ static int nvgpu_fence_syncpt_wait(struct nvgpu_fence_type *f, u32 timeout) struct nvgpu_fence_type_priv *pf = &f->priv; return nvgpu_nvhost_syncpt_wait_timeout_ext( - pf->nvhost_dev, pf->syncpt_id, pf->syncpt_value, + pf->nvhost_device, pf->syncpt_id, pf->syncpt_value, timeout, NVGPU_NVHOST_DEFAULT_WAITER); } @@ -43,42 +43,47 @@ static bool nvgpu_fence_syncpt_is_expired(struct nvgpu_fence_type *f) * syncpt value to be updated. For this case, we force a read * of the value from HW, and then check for expiration. */ - if (!nvgpu_nvhost_syncpt_is_expired_ext(pf->nvhost_dev, pf->syncpt_id, - pf->syncpt_value)) { + if (!nvgpu_nvhost_syncpt_is_expired_ext(pf->nvhost_device, + pf->syncpt_id, pf->syncpt_value)) { + int err; u32 val; - if (!nvgpu_nvhost_syncpt_read_ext_check(pf->nvhost_dev, - pf->syncpt_id, &val)) { + err = nvgpu_nvhost_syncpt_read_ext_check(pf->nvhost_device, + pf->syncpt_id, &val); + WARN(err != 0, "syncpt read failed??"); + if (err == 0) { return nvgpu_nvhost_syncpt_is_expired_ext( - pf->nvhost_dev, + pf->nvhost_device, pf->syncpt_id, pf->syncpt_value); + } else { + return false; } } return true; } -static void nvgpu_fence_syncpt_free(struct nvgpu_fence_type *f) +static void nvgpu_fence_syncpt_release(struct nvgpu_fence_type *f) { } static const struct nvgpu_fence_ops nvgpu_fence_syncpt_ops = { .wait = nvgpu_fence_syncpt_wait, .is_expired = nvgpu_fence_syncpt_is_expired, - .free = nvgpu_fence_syncpt_free, + .release = nvgpu_fence_syncpt_release, }; /* This function takes the ownership of the os_fence */ void nvgpu_fence_from_syncpt( struct nvgpu_fence_type *f, - struct nvgpu_nvhost_dev *nvhost_dev, + struct nvgpu_nvhost_dev *nvhost_device, u32 id, u32 value, struct nvgpu_os_fence os_fence) { struct nvgpu_fence_type_priv *pf = &f->priv; nvgpu_fence_init(f, &nvgpu_fence_syncpt_ops, os_fence); - pf->nvhost_dev = nvhost_dev; + pf->nvhost_device = nvhost_device; pf->syncpt_id = id; pf->syncpt_value = value; } diff --git a/drivers/gpu/nvgpu/include/nvgpu/fence.h b/drivers/gpu/nvgpu/include/nvgpu/fence.h index 440dd4549..5b2fa4714 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/fence.h +++ b/drivers/gpu/nvgpu/include/nvgpu/fence.h @@ -51,7 +51,7 @@ struct nvgpu_fence_type_priv { #ifdef CONFIG_TEGRA_GK20A_NVHOST /* Valid for fences created from syncpoints: */ - struct nvgpu_nvhost_dev *nvhost_dev; + struct nvgpu_nvhost_dev *nvhost_device; u32 syncpt_id; u32 syncpt_value; #endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/fence_syncpt.h b/drivers/gpu/nvgpu/include/nvgpu/fence_syncpt.h index 4c6001aaf..74ccb21f9 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/fence_syncpt.h +++ b/drivers/gpu/nvgpu/include/nvgpu/fence_syncpt.h @@ -32,7 +32,7 @@ struct nvgpu_nvhost_dev; void nvgpu_fence_from_syncpt( struct nvgpu_fence_type *f, - struct nvgpu_nvhost_dev *nvhost_dev, + struct nvgpu_nvhost_dev *nvhost_device, u32 id, u32 value, struct nvgpu_os_fence os_fence); diff --git a/drivers/gpu/nvgpu/include/nvgpu/os_fence_syncpts.h b/drivers/gpu/nvgpu/include/nvgpu/os_fence_syncpts.h index 71213dda6..47bd4c055 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/os_fence_syncpts.h +++ b/drivers/gpu/nvgpu/include/nvgpu/os_fence_syncpts.h @@ -38,7 +38,7 @@ struct nvgpu_os_fence_syncpt { #if defined(CONFIG_TEGRA_GK20A_NVHOST) && !defined(CONFIG_NVGPU_SYNCFD_NONE) int nvgpu_os_fence_syncpt_create(struct nvgpu_os_fence *fence_out, - struct nvgpu_channel *c, struct nvgpu_nvhost_dev *nvhost_dev, + struct nvgpu_channel *c, struct nvgpu_nvhost_dev *nvhost_device, u32 id, u32 thresh); /* @@ -71,7 +71,7 @@ u32 nvgpu_os_fence_syncpt_get_num_syncpoints( static inline int nvgpu_os_fence_syncpt_create( struct nvgpu_os_fence *fence_out, struct nvgpu_channel *c, - struct nvgpu_nvhost_dev *nvhost_dev, + struct nvgpu_nvhost_dev *nvhost_device, u32 id, u32 thresh) { return -ENOSYS; diff --git a/drivers/gpu/nvgpu/os/linux/os_fence_syncpt.c b/drivers/gpu/nvgpu/os/linux/os_fence_syncpt.c index 4338b5bea..10e5544aa 100644 --- a/drivers/gpu/nvgpu/os/linux/os_fence_syncpt.c +++ b/drivers/gpu/nvgpu/os/linux/os_fence_syncpt.c @@ -56,7 +56,7 @@ static const struct nvgpu_os_fence_ops syncpt_ops = { }; int nvgpu_os_fence_syncpt_create(struct nvgpu_os_fence *fence_out, - struct nvgpu_channel *c, struct nvgpu_nvhost_dev *nvhost_dev, + struct nvgpu_channel *c, struct nvgpu_nvhost_dev *nvhost_device, u32 id, u32 thresh) { struct nvhost_ctrl_sync_fence_info pt = { @@ -64,7 +64,7 @@ int nvgpu_os_fence_syncpt_create(struct nvgpu_os_fence *fence_out, .thresh = thresh, }; struct nvhost_fence *fence = nvhost_fence_create( - nvhost_dev->host1x_pdev, &pt, 1, "fence"); + nvhost_device->host1x_pdev, &pt, 1, "fence"); if (IS_ERR(fence)) { nvgpu_err(c->g, "error %d during construction of fence.",