mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-22 17:36:20 +03:00
gpu: nvgpu: Use stack buffer for DMA flags string
Instead of using kmalloc() to get a buffer for storing the computed flags string during DMA debugging use a stack buffer. This removes the need for a kmalloc() call. The problem with kmalloc() is that if a dma_alloc() fails due to being out of memory the kmalloc may likely fail, too! Also simplify the logic now that there's no need to do any error checking for a kmalloc() call. Change-Id: I45c1fd16658212188a1206a2edf17b28f3c06c9e Signed-off-by: Alex Waterman <alexw@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1976440 Reviewed-by: Automatic_Commit_Validation_User GVS: Gerrit_Virtual_Submit Reviewed-by: Vinod Gopalakrishnakurup <vinodg@nvidia.com> Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
committed by
mobile promotions
parent
013ca60edd
commit
3282d0c50a
@@ -42,19 +42,14 @@
|
|||||||
sizeof("NO_KERNEL_MAPPING FORCE_CONTIGUOUS PHYSICALLY_ADDRESSED")
|
sizeof("NO_KERNEL_MAPPING FORCE_CONTIGUOUS PHYSICALLY_ADDRESSED")
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The returned string is kmalloc()ed here but must be freed by the caller.
|
* This function can't fail. It will always at minimum memset() the buf which
|
||||||
|
* is assumed to be able to hold at least %NVGPU_DMA_STR_SIZE bytes.
|
||||||
*/
|
*/
|
||||||
static char *nvgpu_dma_flags_to_str(struct gk20a *g, unsigned long flags)
|
void nvgpu_dma_flags_to_str(struct gk20a *g, unsigned long flags, char *buf)
|
||||||
{
|
{
|
||||||
char *buf = nvgpu_kzalloc(g, NVGPU_DMA_STR_SIZE);
|
|
||||||
int bytes_available = NVGPU_DMA_STR_SIZE;
|
int bytes_available = NVGPU_DMA_STR_SIZE;
|
||||||
|
|
||||||
/*
|
memset(buf, 0, NVGPU_DMA_STR_SIZE);
|
||||||
* Return the empty buffer if there's no flags. Makes it easier on the
|
|
||||||
* calling code to just print it instead of any if (NULL) type logic.
|
|
||||||
*/
|
|
||||||
if (!flags)
|
|
||||||
return buf;
|
|
||||||
|
|
||||||
#define APPEND_FLAG(flag, str_flag) \
|
#define APPEND_FLAG(flag, str_flag) \
|
||||||
do { \
|
do { \
|
||||||
@@ -68,8 +63,6 @@ static char *nvgpu_dma_flags_to_str(struct gk20a *g, unsigned long flags)
|
|||||||
APPEND_FLAG(NVGPU_DMA_FORCE_CONTIGUOUS, "FORCE_CONTIGUOUS ");
|
APPEND_FLAG(NVGPU_DMA_FORCE_CONTIGUOUS, "FORCE_CONTIGUOUS ");
|
||||||
APPEND_FLAG(NVGPU_DMA_PHYSICALLY_ADDRESSED, "PHYSICALLY_ADDRESSED");
|
APPEND_FLAG(NVGPU_DMA_PHYSICALLY_ADDRESSED, "PHYSICALLY_ADDRESSED");
|
||||||
#undef APPEND_FLAG
|
#undef APPEND_FLAG
|
||||||
|
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,16 +83,15 @@ static void __dma_dbg(struct gk20a *g, size_t size, unsigned long flags,
|
|||||||
const char *type, const char *what,
|
const char *type, const char *what,
|
||||||
const char *func, int line)
|
const char *func, int line)
|
||||||
{
|
{
|
||||||
char *flags_str = NULL;
|
char flags_str[NVGPU_DMA_STR_SIZE];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Don't bother making the flags_str if debugging is
|
* Don't bother making the flags_str if debugging is not enabled.
|
||||||
* not enabled. This saves a malloc and a free.
|
|
||||||
*/
|
*/
|
||||||
if (!nvgpu_log_mask_enabled(g, gpu_dbg_dma))
|
if (!nvgpu_log_mask_enabled(g, gpu_dbg_dma))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
flags_str = nvgpu_dma_flags_to_str(g, flags);
|
nvgpu_dma_flags_to_str(g, flags, flags_str);
|
||||||
|
|
||||||
__nvgpu_log_dbg(g, gpu_dbg_dma,
|
__nvgpu_log_dbg(g, gpu_dbg_dma,
|
||||||
func, line,
|
func, line,
|
||||||
@@ -109,9 +101,6 @@ static void __dma_dbg(struct gk20a *g, size_t size, unsigned long flags,
|
|||||||
size, PAGE_ALIGN(size),
|
size, PAGE_ALIGN(size),
|
||||||
g->dma_memory_used >> 10,
|
g->dma_memory_used >> 10,
|
||||||
flags_str);
|
flags_str);
|
||||||
|
|
||||||
if (flags_str)
|
|
||||||
nvgpu_kfree(g, flags_str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define dma_dbg_alloc(g, size, flags, type) \
|
#define dma_dbg_alloc(g, size, flags, type) \
|
||||||
|
|||||||
Reference in New Issue
Block a user