diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/bug.h b/drivers/gpu/nvgpu/include/nvgpu/posix/bug.h index eba30e2b9..c15b1ea65 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/posix/bug.h +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/bug.h @@ -30,10 +30,10 @@ /** Define for issuing warning on condition with message. */ #define WARN(cond, msg, arg...) \ - ((void) nvgpu_posix_warn(cond, msg, ##arg)) + ((void) nvgpu_posix_warn(__func__, __LINE__, cond, msg, ##arg)) /** Define for issuing warning on condition. */ #define WARN_ON(cond) \ - ((void) nvgpu_posix_warn(cond, "")) + ((void) nvgpu_posix_warn(__func__, __LINE__, cond, "")) #ifdef CONFIG_NVGPU_NON_FUSA /** Define for issuing warning once on condition with message. */ @@ -78,13 +78,15 @@ void nvgpu_posix_bug(const char *msg, int line_no) __attribute__ ((noreturn)); * #nvgpu_warn() and dump the stack using function #dump_stack(). Function does * not perform any validation of the parameters. * + * @param func [in] Name of the calling function. + * @param line_no [in] Line number in the file where called. * @param cond [in] Condition to check to issue warning. * @param fmt [in] Format of variable argument list. * @param ... [in] Variable length arguments. * * @return Value of \a cond is returned. */ -bool nvgpu_posix_warn(bool cond, const char *fmt, ...); +bool nvgpu_posix_warn(const char *func, int line_no, bool cond, const char *fmt, ...); #ifdef __NVGPU_UNIT_TEST__ void nvgpu_bug_cb_longjmp(void *arg); diff --git a/drivers/gpu/nvgpu/os/posix/bug.c b/drivers/gpu/nvgpu/os/posix/bug.c index b716b253b..a01e45877 100644 --- a/drivers/gpu/nvgpu/os/posix/bug.c +++ b/drivers/gpu/nvgpu/os/posix/bug.c @@ -207,13 +207,18 @@ done: pthread_exit(NULL); } -bool nvgpu_posix_warn(bool cond, const char *fmt, ...) +bool nvgpu_posix_warn(const char *func, int line_no, bool cond, const char *fmt, ...) { if (!cond) { goto done; } - nvgpu_warn(NULL, "WARNING detected!"); + /* + * MISRA-C rule 17.1 forbids stdarg.h (va_list etc) and this is shared + * with the safety build. Rule 21.6 forbids stdio.h so the warning + * cannot be formatted to a local buffer either. + */ + nvgpu_warn(NULL, "%s:%d WARNING detected %s", func, line_no, fmt); dump_stack(); diff --git a/userspace/units/posix/bug/posix-bug.c b/userspace/units/posix/bug/posix-bug.c index 8ab99e00c..1298f4e9b 100644 --- a/userspace/units/posix/bug/posix-bug.c +++ b/userspace/units/posix/bug/posix-bug.c @@ -164,12 +164,12 @@ int test_warn_msg(struct unit_module *m, { bool ret; - ret = nvgpu_posix_warn(0, ""); + ret = nvgpu_posix_warn(__func__, __LINE__, 0, ""); if (ret != 0) { unit_return_fail(m, "nvgpu_posix_warn failed for cond 0\n"); } - ret = nvgpu_posix_warn(1, ""); + ret = nvgpu_posix_warn(__func__, __LINE__, 1, ""); if (ret != 1) { unit_return_fail(m, "nvgpu_posix_warn failed for cond 1\n"); }