gpu: nvgpu: posix: print WARN*() location

WARN() and WARN_ON() are most useful when the log explains where they
happened. The posix implementation of these prints neither that nor the
warning message (if any). Extend the macros to include function name and
line number, and print those plus the format string.

Actually formatting the format string is problematic wrt. MISRA rules,
so the arguments are not formatted.

The implementation of BUG() already prints the function name and line
number.

Change-Id: Ie246a915f5e8420e1c606bb1555a7f9b498725fd
Signed-off-by: Konsta Hölttä <kholtta@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2634105
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
Reviewed-by: svc-mobile-cert <svc-mobile-cert@nvidia.com>
Reviewed-by: svcacv <svcacv@nvidia.com>
Reviewed-by: Alex Waterman <alexw@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
GVS: Gerrit_Virtual_Submit
This commit is contained in:
Konsta Hölttä
2021-11-30 10:52:41 +02:00
committed by mobile promotions
parent 4c2e2bb0b9
commit ae166bba8a
3 changed files with 14 additions and 7 deletions

View File

@@ -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);

View File

@@ -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();

View File

@@ -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");
}