From: trix@redhat.com To: alexander.deucher@amd.com, christian.koenig@amd.com, Xinhui.Pan@amd.com, airlied@linux.ie, daniel@ffwll.ch, nathan@kernel.org, ndesaulniers@google.com, nirmoy.das@amd.com, lijo.lazar@amd.com, tom.stdenis@amd.com, evan.quan@amd.com, kevin1.wang@amd.com, Amaranath.Somalapuram@amd.com Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Tom Rix <trix@redhat.com> Subject: [PATCH] drm/amdgpu: Fix realloc of ptr Date: Sat, 26 Feb 2022 07:58:51 -0800 [thread overview] Message-ID: <20220226155851.4176109-1-trix@redhat.com> (raw) From: Tom Rix <trix@redhat.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@redhat.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
WARNING: multiple messages have this Message-ID (diff)
From: trix@redhat.com To: alexander.deucher@amd.com, christian.koenig@amd.com, Xinhui.Pan@amd.com, airlied@linux.ie, daniel@ffwll.ch, nathan@kernel.org, ndesaulniers@google.com, nirmoy.das@amd.com, lijo.lazar@amd.com, tom.stdenis@amd.com, evan.quan@amd.com, kevin1.wang@amd.com, Amaranath.Somalapuram@amd.com Cc: Tom Rix <trix@redhat.com>, llvm@lists.linux.dev, dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH] drm/amdgpu: Fix realloc of ptr Date: Sat, 26 Feb 2022 07:58:51 -0800 [thread overview] Message-ID: <20220226155851.4176109-1-trix@redhat.com> (raw) From: Tom Rix <trix@redhat.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@redhat.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
next reply other threads:[~2022-02-26 15:59 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-02-26 15:58 trix [this message] 2022-02-26 15:58 ` [PATCH] drm/amdgpu: Fix realloc of ptr trix 2022-02-26 22:21 ` David Laight 2022-02-26 22:21 ` David Laight 2022-02-27 14:36 ` Tom Rix 2022-02-27 14:36 ` Tom Rix
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220226155851.4176109-1-trix@redhat.com \ --to=trix@redhat.com \ --cc=Amaranath.Somalapuram@amd.com \ --cc=Xinhui.Pan@amd.com \ --cc=airlied@linux.ie \ --cc=alexander.deucher@amd.com \ --cc=amd-gfx@lists.freedesktop.org \ --cc=christian.koenig@amd.com \ --cc=daniel@ffwll.ch \ --cc=dri-devel@lists.freedesktop.org \ --cc=evan.quan@amd.com \ --cc=kevin1.wang@amd.com \ --cc=lijo.lazar@amd.com \ --cc=linux-kernel@vger.kernel.org \ --cc=llvm@lists.linux.dev \ --cc=nathan@kernel.org \ --cc=ndesaulniers@google.com \ --cc=nirmoy.das@amd.com \ --cc=tom.stdenis@amd.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.