From a42af2d0ade252828345fa97ca86182e279e3203 Mon Sep 17 00:00:00 2001 From: Mahesh Kumar Date: Tue, 23 Aug 2022 12:54:24 +0530 Subject: [PATCH] platform: dce: Coverity Fix Fix Coverity issue CID 10138164 Create new macro to avoid non-reachable code. Bug 3461002 Signed-off-by: Mahesh Kumar Change-Id: Ie5ff50678e30ae0ddd712ceda212f4b572ce624e Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2765168 Reviewed-by: svcacv Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-cert Reviewed-by: Arun Swain GVS: Gerrit_Virtual_Submit --- drivers/platform/tegra/dce/dce-client-ipc.c | 3 +- drivers/platform/tegra/dce/dce-worker.c | 3 +- drivers/platform/tegra/dce/include/dce-cond.h | 39 +++++++++++++++++-- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/drivers/platform/tegra/dce/dce-client-ipc.c b/drivers/platform/tegra/dce/dce-client-ipc.c index 2d889b2c..c40d198a 100644 --- a/drivers/platform/tegra/dce/dce-client-ipc.c +++ b/drivers/platform/tegra/dce/dce-client-ipc.c @@ -279,8 +279,7 @@ int dce_client_ipc_wait(struct tegra_dce *d, u32 int_type) retry_wait: DCE_COND_WAIT_INTERRUPTIBLE(&cl->recv_wait, - atomic_read(&cl->complete) == 1, - 0); + atomic_read(&cl->complete) == 1); if (atomic_read(&cl->complete) != 1) goto retry_wait; diff --git a/drivers/platform/tegra/dce/dce-worker.c b/drivers/platform/tegra/dce/dce-worker.c index 6abb775f..ace3198e 100644 --- a/drivers/platform/tegra/dce/dce-worker.c +++ b/drivers/platform/tegra/dce/dce-worker.c @@ -39,8 +39,7 @@ int dce_wait_interruptible(struct tegra_dce *d, u32 msg_id) atomic_set(&wait->complete, 0); DCE_COND_WAIT_INTERRUPTIBLE(&wait->cond_wait, - atomic_read(&wait->complete) == 1, - 0); + atomic_read(&wait->complete) == 1); if (atomic_read(&wait->complete) != 1) return -EINTR; diff --git a/drivers/platform/tegra/dce/include/dce-cond.h b/drivers/platform/tegra/dce/include/dce-cond.h index 0f5886b3..d4a1daf5 100644 --- a/drivers/platform/tegra/dce/include/dce-cond.h +++ b/drivers/platform/tegra/dce/include/dce-cond.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2019-2022, NVIDIA CORPORATION. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -27,6 +27,37 @@ struct dce_cond { * * @c - The condition variable to sleep on * @condition - The condition that needs to be true + * + * Wait for a condition to become true. + */ +#define DCE_COND_WAIT(c, condition) \ +({\ + int ret = 0; \ + wait_event((c)->wq, condition); \ + ret;\ +}) + +/** + * DCE_COND_WAIT_INTERRUPTIBLE - Wait for a condition to be true + * + * @c - The condition variable to sleep on + * @condition - The condition that needs to be true + * + * Wait for a condition to become true. Returns -ERESTARTSYS + * on signal. + */ +#define DCE_COND_WAIT_INTERRUPTIBLE(c, condition) \ +({ \ + int ret = 0; \ + ret = wait_event_interruptible((c)->wq, condition); \ + ret; \ +}) + +/** + * DCE_COND_WAIT_TIMEOUT - Wait for a condition to be true + * + * @c - The condition variable to sleep on + * @condition - The condition that needs to be true * @timeout_ms - Timeout in milliseconds, or 0 for infinite wait. * This parameter must be a u32. Since this is a macro, this is * enforced by assigning a typecast NULL pointer to a u32 tmp @@ -36,7 +67,7 @@ struct dce_cond { * Wait for a condition to become true. Returns -ETIMEOUT if * the wait timed out with condition false. */ -#define DCE_COND_WAIT(c, condition, timeout_ms) \ +#define DCE_COND_WAIT_TIMEOUT(c, condition, timeout_ms) \ ({\ int ret = 0; \ /* This is the assignment to enforce a u32 for timeout_ms */ \ @@ -54,7 +85,7 @@ struct dce_cond { }) /** - * DCE_COND_WAIT_INTERRUPTIBLE - Wait for a condition to be true + * DCE_COND_WAIT_INTERRUPTIBLE_TIMEOUT - Wait for a condition to be true * * @c - The condition variable to sleep on * @condition - The condition that needs to be true @@ -68,7 +99,7 @@ struct dce_cond { * the wait timed out with condition false or -ERESTARTSYS on * signal. */ -#define DCE_COND_WAIT_INTERRUPTIBLE(c, condition, timeout_ms) \ +#define DCE_COND_WAIT_INTERRUPTIBLE_TIMEOUT(c, condition, timeout_ms) \ ({ \ int ret = 0; \ /* This is the assignment to enforce a u32 for timeout_ms */ \