mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-22 17:36:20 +03:00
MISRA Rule 7.4 doesn't allow string literal to initialize char * object. This patch modifies log_message definition to resolve MISRA errors. Jira NVGPU-4075 Change-Id: Iea1c08e76b5af691ff98c24657d6295d17a5b757 Signed-off-by: Vedashree Vidwans <vvidwans@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/2224232 Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com> Reviewed-by: svc-mobile-misra <svc-mobile-misra@nvidia.com> Reviewed-by: svc-mobile-cert <svc-mobile-cert@nvidia.com> GVS: Gerrit_Virtual_Submit Reviewed-by: Alex Waterman <alexw@nvidia.com> Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
85 lines
2.2 KiB
C
85 lines
2.2 KiB
C
/*
|
|
* Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
|
|
*
|
|
* NVIDIA Corporation and its licensors retain all intellectual property and
|
|
* proprietary rights in and to this software and related documentation. Any
|
|
* use, reproduction, disclosure or distribution of this software and related
|
|
* documentation without an express license agreement from NVIDIA Corporation
|
|
* is strictly prohibited.
|
|
*/
|
|
|
|
#include <nvgpu/os_sched.h>
|
|
|
|
#include <unistd.h>
|
|
#include <pthread.h>
|
|
|
|
#define CURRENT_NAME_LEN 30
|
|
|
|
int nvgpu_current_pid(struct gk20a *g)
|
|
{
|
|
/*
|
|
* In the kernel this gets us the PID of the calling process for IOCTLs.
|
|
* But since we are in userspace this doesn't quite mean the same thing.
|
|
* This simply returns the PID of the currently running process.
|
|
*/
|
|
return (int)getpid();
|
|
}
|
|
|
|
int nvgpu_current_tid(struct gk20a *g)
|
|
{
|
|
/*
|
|
* In POSIX thread ID is not the same as a process ID. In Linux threads
|
|
* and processes are represented by the same thing, but userspace can't
|
|
* really rely on that.
|
|
*
|
|
* We can, however, get a pthread_t for a given thread. But this
|
|
* pthread_t need not have any relation to the underlying system's
|
|
* representation of "threads".
|
|
*/
|
|
return (int)pthread_self();
|
|
}
|
|
|
|
void nvgpu_print_current_impl(struct gk20a *g, const char *func_name, int line,
|
|
void *ctx, enum nvgpu_log_type type)
|
|
{
|
|
const char *log_message = "(unknown process)";
|
|
|
|
#if defined(__NVGPU_POSIX__)
|
|
#ifdef _GNU_SOURCE
|
|
char current_tname[CURRENT_NAME_LEN];
|
|
|
|
/* pthread_getname_np() will return null terminated string on success */
|
|
if (pthread_getname_np(0, current_tname, CURRENT_NAME_LEN) == 0) {
|
|
log_message = current_tname;
|
|
}
|
|
#else
|
|
type = NVGPU_ERROR;
|
|
#endif
|
|
#else
|
|
char current_tname[CURRENT_NAME_LEN];
|
|
|
|
/* pthread_getname_np() will return null terminated string on success */
|
|
if (pthread_getname_np(0, current_tname, CURRENT_NAME_LEN) == 0) {
|
|
log_message = current_tname;
|
|
}
|
|
#endif
|
|
|
|
switch (type) {
|
|
case NVGPU_ERROR:
|
|
nvgpu_err(g, "%s", log_message);
|
|
break;
|
|
case NVGPU_WARNING:
|
|
nvgpu_warn(g, "%s", log_message);
|
|
break;
|
|
case NVGPU_DEBUG:
|
|
nvgpu_log(g, 0U, "%s", log_message);
|
|
break;
|
|
case NVGPU_INFO:
|
|
nvgpu_info(g, "%s", log_message);
|
|
break;
|
|
default:
|
|
nvgpu_err(g, "%s", log_message);
|
|
break;
|
|
}
|
|
}
|