* [PATCH v2] drm/amdgpu: Fix realloc of ptr
@ 2022-02-27 15:33 ` trix
0 siblings, 0 replies; 7+ messages in thread
From: trix @ 2022-02-27 15:33 UTC (permalink / raw)
To: alexander.deucher, christian.koenig, Xinhui.Pan, airlied, daniel,
nathan, ndesaulniers, lijo.lazar, nirmoy.das, kevin1.wang,
tom.stdenis, evan.quan, Amaranath.Somalapuram
Cc: amd-gfx, dri-devel, linux-kernel, llvm, Tom Rix
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 uses 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>
---
v2:
use 'new' to hold/check the ralloc return
fix commit log mistake on ralloc freeing to using input ptr
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
index 9eb9b440bd438..2f4f8c5618d81 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 *new, *tmp = NULL;
int ret, i = 0, len = 0;
do {
@@ -1687,7 +1687,12 @@ static ssize_t amdgpu_reset_dump_register_list_write(struct file *f,
goto error_free;
}
- tmp = krealloc_array(tmp, i + 1, sizeof(uint32_t), GFP_KERNEL);
+ new = krealloc_array(tmp, i + 1, sizeof(uint32_t), GFP_KERNEL);
+ if (!new) {
+ ret = -ENOMEM;
+ goto error_free;
+ }
+ tmp = new;
if (sscanf(reg_offset, "%X %n", &tmp[i], &ret) != 1) {
ret = -EINVAL;
goto error_free;
--
2.26.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2] drm/amdgpu: Fix realloc of ptr
@ 2022-02-27 15:33 ` trix
0 siblings, 0 replies; 7+ messages in thread
From: trix @ 2022-02-27 15:33 UTC (permalink / raw)
To: alexander.deucher, christian.koenig, Xinhui.Pan, airlied, daniel,
nathan, ndesaulniers, lijo.lazar, nirmoy.das, kevin1.wang,
tom.stdenis, evan.quan, Amaranath.Somalapuram
Cc: Tom Rix, llvm, dri-devel, amd-gfx, linux-kernel
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 uses 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>
---
v2:
use 'new' to hold/check the ralloc return
fix commit log mistake on ralloc freeing to using input ptr
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
index 9eb9b440bd438..2f4f8c5618d81 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 *new, *tmp = NULL;
int ret, i = 0, len = 0;
do {
@@ -1687,7 +1687,12 @@ static ssize_t amdgpu_reset_dump_register_list_write(struct file *f,
goto error_free;
}
- tmp = krealloc_array(tmp, i + 1, sizeof(uint32_t), GFP_KERNEL);
+ new = krealloc_array(tmp, i + 1, sizeof(uint32_t), GFP_KERNEL);
+ if (!new) {
+ ret = -ENOMEM;
+ goto error_free;
+ }
+ tmp = new;
if (sscanf(reg_offset, "%X %n", &tmp[i], &ret) != 1) {
ret = -EINVAL;
goto error_free;
--
2.26.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2] drm/amdgpu: Fix realloc of ptr
2022-02-27 15:33 ` trix
@ 2022-02-28 10:55 ` Christian König
-1 siblings, 0 replies; 7+ messages in thread
From: Christian König @ 2022-02-28 10:55 UTC (permalink / raw)
To: trix, alexander.deucher, Xinhui.Pan, airlied, daniel, nathan,
ndesaulniers, lijo.lazar, nirmoy.das, kevin1.wang, tom.stdenis,
evan.quan, Amaranath.Somalapuram
Cc: llvm, dri-devel, amd-gfx, linux-kernel
Am 27.02.22 um 16:33 schrieb trix@redhat.com:
> 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 uses 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>
Yeah, stuff I missed because of the long review. I was already wondering
what semantics krealloc_array is following for freeing up the pointer on
error.
Reviewed-by: Christian König <christian.koenig@amd.com>
Thanks,
Christian.
> ---
> v2:
> use 'new' to hold/check the ralloc return
> fix commit log mistake on ralloc freeing to using input ptr
>
> drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> index 9eb9b440bd438..2f4f8c5618d81 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 *new, *tmp = NULL;
> int ret, i = 0, len = 0;
>
> do {
> @@ -1687,7 +1687,12 @@ static ssize_t amdgpu_reset_dump_register_list_write(struct file *f,
> goto error_free;
> }
>
> - tmp = krealloc_array(tmp, i + 1, sizeof(uint32_t), GFP_KERNEL);
> + new = krealloc_array(tmp, i + 1, sizeof(uint32_t), GFP_KERNEL);
> + if (!new) {
> + ret = -ENOMEM;
> + goto error_free;
> + }
> + tmp = new;
> if (sscanf(reg_offset, "%X %n", &tmp[i], &ret) != 1) {
> ret = -EINVAL;
> goto error_free;
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] drm/amdgpu: Fix realloc of ptr
@ 2022-02-28 10:55 ` Christian König
0 siblings, 0 replies; 7+ messages in thread
From: Christian König @ 2022-02-28 10:55 UTC (permalink / raw)
To: trix, alexander.deucher, Xinhui.Pan, airlied, daniel, nathan,
ndesaulniers, lijo.lazar, nirmoy.das, kevin1.wang, tom.stdenis,
evan.quan, Amaranath.Somalapuram
Cc: amd-gfx, dri-devel, linux-kernel, llvm
Am 27.02.22 um 16:33 schrieb trix@redhat.com:
> 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 uses 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>
Yeah, stuff I missed because of the long review. I was already wondering
what semantics krealloc_array is following for freeing up the pointer on
error.
Reviewed-by: Christian König <christian.koenig@amd.com>
Thanks,
Christian.
> ---
> v2:
> use 'new' to hold/check the ralloc return
> fix commit log mistake on ralloc freeing to using input ptr
>
> drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> index 9eb9b440bd438..2f4f8c5618d81 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 *new, *tmp = NULL;
> int ret, i = 0, len = 0;
>
> do {
> @@ -1687,7 +1687,12 @@ static ssize_t amdgpu_reset_dump_register_list_write(struct file *f,
> goto error_free;
> }
>
> - tmp = krealloc_array(tmp, i + 1, sizeof(uint32_t), GFP_KERNEL);
> + new = krealloc_array(tmp, i + 1, sizeof(uint32_t), GFP_KERNEL);
> + if (!new) {
> + ret = -ENOMEM;
> + goto error_free;
> + }
> + tmp = new;
> if (sscanf(reg_offset, "%X %n", &tmp[i], &ret) != 1) {
> ret = -EINVAL;
> goto error_free;
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] drm/amdgpu: Fix realloc of ptr
2022-02-28 10:55 ` Christian König
(?)
@ 2022-02-28 22:30 ` Alex Deucher
-1 siblings, 0 replies; 7+ messages in thread
From: Alex Deucher @ 2022-02-28 22:30 UTC (permalink / raw)
To: Christian König
Cc: Tom Rix, Deucher, Alexander, xinhui pan, Dave Airlie,
Daniel Vetter, Nathan Chancellor, Nick Desaulniers, Lazar, Lijo,
Nirmoy Das, Kevin Wang, Tom St Denis, Quan, Evan,
Somalapuram Amaranath, llvm, Maling list - DRI developers,
amd-gfx list, LKML
Applied. Thanks!
Alex
On Mon, Feb 28, 2022 at 5:55 AM Christian König
<christian.koenig@amd.com> wrote:
>
> Am 27.02.22 um 16:33 schrieb trix@redhat.com:
> > 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 uses 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>
>
> Yeah, stuff I missed because of the long review. I was already wondering
> what semantics krealloc_array is following for freeing up the pointer on
> error.
>
> Reviewed-by: Christian König <christian.koenig@amd.com>
>
> Thanks,
> Christian.
>
> > ---
> > v2:
> > use 'new' to hold/check the ralloc return
> > fix commit log mistake on ralloc freeing to using input ptr
> >
> > drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 9 +++++++--
> > 1 file changed, 7 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> > index 9eb9b440bd438..2f4f8c5618d81 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 *new, *tmp = NULL;
> > int ret, i = 0, len = 0;
> >
> > do {
> > @@ -1687,7 +1687,12 @@ static ssize_t amdgpu_reset_dump_register_list_write(struct file *f,
> > goto error_free;
> > }
> >
> > - tmp = krealloc_array(tmp, i + 1, sizeof(uint32_t), GFP_KERNEL);
> > + new = krealloc_array(tmp, i + 1, sizeof(uint32_t), GFP_KERNEL);
> > + if (!new) {
> > + ret = -ENOMEM;
> > + goto error_free;
> > + }
> > + tmp = new;
> > if (sscanf(reg_offset, "%X %n", &tmp[i], &ret) != 1) {
> > ret = -EINVAL;
> > goto error_free;
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] drm/amdgpu: Fix realloc of ptr
@ 2022-02-28 22:30 ` Alex Deucher
0 siblings, 0 replies; 7+ messages in thread
From: Alex Deucher @ 2022-02-28 22:30 UTC (permalink / raw)
To: Christian König
Cc: Tom St Denis, llvm, Lazar, Lijo, Kevin Wang,
Somalapuram Amaranath, Dave Airlie, Tom Rix, xinhui pan,
Nick Desaulniers, LKML, Maling list - DRI developers,
Nathan Chancellor, Nirmoy Das, amd-gfx list, Deucher, Alexander,
Quan, Evan
Applied. Thanks!
Alex
On Mon, Feb 28, 2022 at 5:55 AM Christian König
<christian.koenig@amd.com> wrote:
>
> Am 27.02.22 um 16:33 schrieb trix@redhat.com:
> > 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 uses 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>
>
> Yeah, stuff I missed because of the long review. I was already wondering
> what semantics krealloc_array is following for freeing up the pointer on
> error.
>
> Reviewed-by: Christian König <christian.koenig@amd.com>
>
> Thanks,
> Christian.
>
> > ---
> > v2:
> > use 'new' to hold/check the ralloc return
> > fix commit log mistake on ralloc freeing to using input ptr
> >
> > drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 9 +++++++--
> > 1 file changed, 7 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> > index 9eb9b440bd438..2f4f8c5618d81 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 *new, *tmp = NULL;
> > int ret, i = 0, len = 0;
> >
> > do {
> > @@ -1687,7 +1687,12 @@ static ssize_t amdgpu_reset_dump_register_list_write(struct file *f,
> > goto error_free;
> > }
> >
> > - tmp = krealloc_array(tmp, i + 1, sizeof(uint32_t), GFP_KERNEL);
> > + new = krealloc_array(tmp, i + 1, sizeof(uint32_t), GFP_KERNEL);
> > + if (!new) {
> > + ret = -ENOMEM;
> > + goto error_free;
> > + }
> > + tmp = new;
> > if (sscanf(reg_offset, "%X %n", &tmp[i], &ret) != 1) {
> > ret = -EINVAL;
> > goto error_free;
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] drm/amdgpu: Fix realloc of ptr
@ 2022-02-28 22:30 ` Alex Deucher
0 siblings, 0 replies; 7+ messages in thread
From: Alex Deucher @ 2022-02-28 22:30 UTC (permalink / raw)
To: Christian König
Cc: Tom St Denis, llvm, Lazar, Lijo, Kevin Wang,
Somalapuram Amaranath, Dave Airlie, Tom Rix, xinhui pan,
Nick Desaulniers, LKML, Maling list - DRI developers,
Nathan Chancellor, Nirmoy Das, amd-gfx list, Daniel Vetter,
Deucher, Alexander, Quan, Evan
Applied. Thanks!
Alex
On Mon, Feb 28, 2022 at 5:55 AM Christian König
<christian.koenig@amd.com> wrote:
>
> Am 27.02.22 um 16:33 schrieb trix@redhat.com:
> > 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 uses 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>
>
> Yeah, stuff I missed because of the long review. I was already wondering
> what semantics krealloc_array is following for freeing up the pointer on
> error.
>
> Reviewed-by: Christian König <christian.koenig@amd.com>
>
> Thanks,
> Christian.
>
> > ---
> > v2:
> > use 'new' to hold/check the ralloc return
> > fix commit log mistake on ralloc freeing to using input ptr
> >
> > drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 9 +++++++--
> > 1 file changed, 7 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> > index 9eb9b440bd438..2f4f8c5618d81 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 *new, *tmp = NULL;
> > int ret, i = 0, len = 0;
> >
> > do {
> > @@ -1687,7 +1687,12 @@ static ssize_t amdgpu_reset_dump_register_list_write(struct file *f,
> > goto error_free;
> > }
> >
> > - tmp = krealloc_array(tmp, i + 1, sizeof(uint32_t), GFP_KERNEL);
> > + new = krealloc_array(tmp, i + 1, sizeof(uint32_t), GFP_KERNEL);
> > + if (!new) {
> > + ret = -ENOMEM;
> > + goto error_free;
> > + }
> > + tmp = new;
> > if (sscanf(reg_offset, "%X %n", &tmp[i], &ret) != 1) {
> > ret = -EINVAL;
> > goto error_free;
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-02-28 22:30 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-27 15:33 [PATCH v2] drm/amdgpu: Fix realloc of ptr trix
2022-02-27 15:33 ` trix
2022-02-28 10:55 ` Christian König
2022-02-28 10:55 ` Christian König
2022-02-28 22:30 ` Alex Deucher
2022-02-28 22:30 ` Alex Deucher
2022-02-28 22:30 ` Alex Deucher
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.