From 6222ebeaeada9fa125d827fdfbf782329fe42865 Mon Sep 17 00:00:00 2001 From: Debarshi Dutta Date: Mon, 26 Apr 2021 06:53:38 +0000 Subject: [PATCH] gpu: nvgpu: address NULL access during boot. The function nvgpu_pci_probe invokes nvgpu_kzalloc(g) with a pointer to struct gk20a before setting the device pointer in struct nvgpu_os_linux. This may result in NULL Pointer access in the function nvgpu_log_name when some logs are enabled during boot. As a solution, the implementation of nvgpu_log_name is updated to first check for a valid pointer to a struct device before calling dev_name Jira NVGPU-6770 Change-Id: I98a9746550e43f3b7a143f5b7c7141ff6c67f758 Signed-off-by: Debarshi Dutta Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2520355 Reviewed-by: svcacv Reviewed-by: Lakshmanan M Reviewed-by: Seshendra Gadagottu Reviewed-by: Vaibhav Kachore Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/os/linux/log.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/nvgpu/os/linux/log.c b/drivers/gpu/nvgpu/os/linux/log.c index efbcba833..8473c6c23 100644 --- a/drivers/gpu/nvgpu/os/linux/log.c +++ b/drivers/gpu/nvgpu/os/linux/log.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2017-2021, NVIDIA CORPORATION. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -47,7 +47,7 @@ static const char *log_types[] = { static inline const char *nvgpu_log_name(struct gk20a *g) { - return dev_name(dev_from_gk20a(g)); + return dev_from_gk20a(g) == NULL ? "" : dev_name(dev_from_gk20a(g)); } #ifdef CONFIG_GK20A_TRACE_PRINTK @@ -124,7 +124,7 @@ void nvgpu_log_dbg_impl(struct gk20a *g, u64 log_mask, (void) vsnprintf(log, LOG_BUFFER_LENGTH, fmt, args); va_end(args); - __nvgpu_really_print_log(g->log_trace, nvgpu_log_name(g), + __nvgpu_really_print_log(g->log_trace, g ? nvgpu_log_name(g) : "", func_name, line, NVGPU_DEBUG, log); }