Files
linux-nvgpu/drivers/gpu/nvgpu/os/posix/os_sched.c
Alex Waterman f7860833f1 gpu: ngpu: POSIX log fmt string fix
The os_sched unit was recently unified with QNX and as a result some
new code was added to the POSIX build. This code works fine with the
Tmake compiler, but on x86 local builds of the POSIX code it triggers
a fmt-security warning (which is subsequently treated as an error).
Thus the build breaks.

The fix is to explicitly define a format of "%s" instead of passing
in a format from a locally defined char array.

Also fix the MISRA issues due to lack of curly braces.

Change-Id: Ia5bfda39e486acde22f16e338ef0d390e5b50e3c
Signed-off-by: Alex Waterman <alexw@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/2089081
Reviewed-by: Philip Elcan <pelcan@nvidia.com>
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
Reviewed-by: svc-mobile-misra <svc-mobile-misra@nvidia.com>
Reviewed-by: Nicolas Benech <nbenech@nvidia.com>
Reviewed-by: svc-misra-checker <svc-misra-checker@nvidia.com>
Reviewed-by: Sagar Kadamati <skadamati@nvidia.com>
Reviewed-by: Thomas Fleury <tfleury@nvidia.com>
Tested-by: Thomas Fleury <tfleury@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
2019-04-05 10:54:10 -07:00

60 lines
1.7 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>
#if defined(__NVGPU_POSIX__)
#define __USE_GNU
#else
#define __EXT_QNX
#endif
#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(struct gk20a *g, const char *func_name, int line,
void *ctx, enum nvgpu_log_type type)
{
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) {
__nvgpu_log_msg(g, func_name, line, type, "%s", current_tname);
} else {
__nvgpu_log_msg(g, func_name, line, type, "(unknown process)");
}
}