From 345eae584df734e076faeb4dcc7235d66ef0a7ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konsta=20H=C3=B6ltt=C3=A4?= Date: Tue, 11 Aug 2020 12:48:19 +0300 Subject: [PATCH] gpu: nvgpu: remove nvgpu_channel_joblist_is_empty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit channel_joblist_peek() returns NULL if the list is empty. nvgpu_channel_joblist_is_empty() has been used only together with that function; remove it and check against NULL to see whether there are jobs in flight. This removes some duplication, simplifies the call sites slightly, and gets rid of a Coverity nag about a possible NULL pointer from peek that really isn't (when the emptiness was already checked). Jira NVGPU-5772 Change-Id: I814e9c510d99b88e59539359992fb44d4e7ce2ea Signed-off-by: Konsta Hölttä Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2397394 Reviewed-by: automaticguardword 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/fifo/channel.c | 16 ++++++++-------- drivers/gpu/nvgpu/common/fifo/job.c | 17 ++++------------- drivers/gpu/nvgpu/include/nvgpu/job.h | 1 - 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/drivers/gpu/nvgpu/common/fifo/channel.c b/drivers/gpu/nvgpu/common/fifo/channel.c index 5947a628d..11958ca97 100644 --- a/drivers/gpu/nvgpu/common/fifo/channel.c +++ b/drivers/gpu/nvgpu/common/fifo/channel.c @@ -688,16 +688,16 @@ void nvgpu_channel_clean_up_jobs(struct nvgpu_channel *c) bool completed; nvgpu_channel_joblist_lock(c); - if (nvgpu_channel_joblist_is_empty(c)) { + job = channel_joblist_peek(c); + nvgpu_channel_joblist_unlock(c); + + if (job == NULL) { /* * No jobs in flight, timeout will remain stopped until * new jobs are submitted. */ - nvgpu_channel_joblist_unlock(c); break; } - job = channel_joblist_peek(c); - nvgpu_channel_joblist_unlock(c); completed = nvgpu_fence_is_expired(&job->post_fence); if (!completed) { @@ -787,13 +787,13 @@ void nvgpu_channel_clean_up_deterministic_job(struct nvgpu_channel *c) nvgpu_mutex_acquire(&c->joblist.cleanup_lock); nvgpu_channel_joblist_lock(c); - if (nvgpu_channel_joblist_is_empty(c)) { - nvgpu_channel_joblist_unlock(c); - goto out_unlock; - } job = channel_joblist_peek(c); nvgpu_channel_joblist_unlock(c); + if (job == NULL) { + goto out_unlock; + } + nvgpu_assert(job->num_mapped_buffers == 0U); if (!nvgpu_fence_is_expired(&job->post_fence)) { diff --git a/drivers/gpu/nvgpu/common/fifo/job.c b/drivers/gpu/nvgpu/common/fifo/job.c index 3b525096a..c4cca88c2 100644 --- a/drivers/gpu/nvgpu/common/fifo/job.c +++ b/drivers/gpu/nvgpu/common/fifo/job.c @@ -78,15 +78,11 @@ void nvgpu_channel_joblist_unlock(struct nvgpu_channel *c) struct nvgpu_channel_job *channel_joblist_peek(struct nvgpu_channel *c) { - struct nvgpu_channel_job *job = NULL; + unsigned int get = c->joblist.pre_alloc.get; + unsigned int put = c->joblist.pre_alloc.put; + bool empty = get == put; - if (!nvgpu_channel_joblist_is_empty(c)) { - unsigned int get = c->joblist.pre_alloc.get; - - job = &c->joblist.pre_alloc.jobs[get]; - } - - return job; + return empty ? NULL : &c->joblist.pre_alloc.jobs[get]; } void channel_joblist_add(struct nvgpu_channel *c, @@ -103,11 +99,6 @@ void channel_joblist_delete(struct nvgpu_channel *c, (c->joblist.pre_alloc.length); } -bool nvgpu_channel_joblist_is_empty(struct nvgpu_channel *c) -{ - return c->joblist.pre_alloc.get == c->joblist.pre_alloc.put; -} - int channel_prealloc_resources(struct nvgpu_channel *c, u32 num_jobs) { int err; diff --git a/drivers/gpu/nvgpu/include/nvgpu/job.h b/drivers/gpu/nvgpu/include/nvgpu/job.h index b9f167d16..5d2664459 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/job.h +++ b/drivers/gpu/nvgpu/include/nvgpu/job.h @@ -52,7 +52,6 @@ void channel_joblist_add(struct nvgpu_channel *c, struct nvgpu_channel_job *job); void channel_joblist_delete(struct nvgpu_channel *c, struct nvgpu_channel_job *job); -bool nvgpu_channel_joblist_is_empty(struct nvgpu_channel *c); int channel_prealloc_resources(struct nvgpu_channel *c, u32 num_jobs); void channel_free_prealloc_resources(struct nvgpu_channel *c);