From d4d81a6f8e8fdeab085b526cb761818cdec4faca Mon Sep 17 00:00:00 2001 From: Rajesh Devaraj Date: Mon, 11 May 2020 11:20:58 +0000 Subject: [PATCH] gpu: nvgpu: add support to print caller information This patch updates nvgpu_assert as macro to print the information about the calling function. Specifically, to print the function name and the line number details. This patch introduces misra violations (misra_c_2012_rule_10_1_violation) in nvgpu_assert(). However, leaving misra violations unfixed has low safety impact since misra violations are coming after fatal error is hit where GPU driver is not expected to be serviceable thereafter. Further, this patch provides debug benefit in quickly finding the function that lead to the exit of NvGPU process. Bug 2964898 Change-Id: Iba85f4a9226742a0bb08b045bcbfa26949bbe746 Signed-off-by: Rajesh Devaraj Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2342086 Reviewed-by: automaticguardword Reviewed-by: Ankur Kishore Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/include/nvgpu/bug.h | 25 +++++++++---------------- drivers/gpu/nvgpu/os/posix/bug.c | 2 +- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/nvgpu/include/nvgpu/bug.h b/drivers/gpu/nvgpu/include/nvgpu/bug.h index 61893f144..6e16dedb3 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/bug.h +++ b/drivers/gpu/nvgpu/include/nvgpu/bug.h @@ -47,23 +47,16 @@ #define nvgpu_assert(cond) ((void) WARN_ON(!(cond))) #else /* - * A static inline for POSIX/QNX/etc so that we can hide the branch in BUG_ON() - * from the branch analyzer. This prevents unit testing branch analysis from - * marking this as an untested branch everywhere the nvgpu_assert() macro is - * used. Similarly for MISRA this hides the messy BUG_ON() macro from users of - * this function. This means the MISRA scanner will only trigger 1 issue for - * this instead of 1 for every place it's used. - * - * When this assert fails the function will not return. + * When this assert fails, the function will not return. */ -static inline void nvgpu_assert(bool cond) -{ -NVGPU_COV_WHITELIST_BLOCK_BEGIN(false_positive, 1, NVGPU_MISRA(Rule, 14_4), "Bug 2277532") -NVGPU_COV_WHITELIST_BLOCK_BEGIN(false_positive, 1, NVGPU_MISRA(Rule, 15_6), "Bug 2277532") - BUG_ON(!cond); -NVGPU_COV_WHITELIST_BLOCK_END(NVGPU_MISRA(Rule, 14_4)) -NVGPU_COV_WHITELIST_BLOCK_END(NVGPU_MISRA(Rule, 15_6)) -} +#define nvgpu_assert(cond) \ + ({ \ + NVGPU_COV_WHITELIST_BLOCK_BEGIN(false_positive, 1, NVGPU_MISRA(Rule, 14_4), "Bug 2277532") \ + NVGPU_COV_WHITELIST_BLOCK_BEGIN(false_positive, 1, NVGPU_MISRA(Rule, 15_6), "Bug 2277532") \ + BUG_ON(!(cond)); \ + NVGPU_COV_WHITELIST_BLOCK_END(NVGPU_MISRA(Rule, 14_4)) \ + NVGPU_COV_WHITELIST_BLOCK_END(NVGPU_MISRA(Rule, 15_6)) \ + }) #endif /* diff --git a/drivers/gpu/nvgpu/os/posix/bug.c b/drivers/gpu/nvgpu/os/posix/bug.c index 807ef8ff1..2ed93a297 100644 --- a/drivers/gpu/nvgpu/os/posix/bug.c +++ b/drivers/gpu/nvgpu/os/posix/bug.c @@ -169,7 +169,7 @@ done: #endif while ((err = raise(SIGSEGV)) != 0) { /* - * Make sure the signal is raised. + * Make sure that SIGSEGV signal is raised. */ }