[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220226155851.4176109-1-trix@redhat.com>
Date: Sat, 26 Feb 2022 07:58:51 -0800
From: trix@...hat.com
To: alexander.deucher@....com, christian.koenig@....com,
Xinhui.Pan@....com, airlied@...ux.ie, daniel@...ll.ch,
nathan@...nel.org, ndesaulniers@...gle.com, nirmoy.das@....com,
lijo.lazar@....com, tom.stdenis@....com, evan.quan@....com,
kevin1.wang@....com, Amaranath.Somalapuram@....com
Cc: amd-gfx@...ts.freedesktop.org, dri-devel@...ts.freedesktop.org,
linux-kernel@...r.kernel.org, llvm@...ts.linux.dev,
Tom Rix <trix@...hat.com>
Subject: [PATCH] drm/amdgpu: Fix realloc of ptr
From: Tom Rix <trix@...hat.com>
Clang static analysis reports this error
amdgpu_debugfs.c:1690:9: warning: 1st function call
argument is an uninitialized value
tmp = krealloc_array(tmp, i + 1,
^~~~~~~~~~~~~~~~~~~~~~~~~~~
realloc will free tmp, so tmp can not be garbage.
And the return needs to be checked.
Fixes: 5ce5a584cb82 ("drm/amdgpu: add debugfs for reset registers list")
Signed-off-by: Tom Rix <trix@...hat.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
index 9eb9b440bd438..159b97c0b4ebc 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
@@ -1676,7 +1676,7 @@ static ssize_t amdgpu_reset_dump_register_list_write(struct file *f,
{
struct amdgpu_device *adev = (struct amdgpu_device *)file_inode(f)->i_private;
char reg_offset[11];
- uint32_t *tmp;
+ uint32_t *tmp = NULL;
int ret, i = 0, len = 0;
do {
@@ -1688,6 +1688,10 @@ static ssize_t amdgpu_reset_dump_register_list_write(struct file *f,
}
tmp = krealloc_array(tmp, i + 1, sizeof(uint32_t), GFP_KERNEL);
+ if (!tmp) {
+ ret = -ENOMEM;
+ goto error_free;
+ }
if (sscanf(reg_offset, "%X %n", &tmp[i], &ret) != 1) {
ret = -EINVAL;
goto error_free;
--
2.26.3
Powered by blists - more mailing lists