From: Dan Carpenter <dan.carpenter@oracle.com>
To: christian.koenig@amd.com
Cc: David Airlie <airlied@linux.ie>, Kevin Wang <kevin1.wang@amd.com>,
kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org,
amd-gfx@lists.freedesktop.org, Rui Huang <ray.huang@amd.com>,
dri-devel@lists.freedesktop.org, Daniel Vetter <daniel@ffwll.ch>,
Alex Deucher <alexander.deucher@amd.com>,
Yintian Tao <yttao@amd.com>, Evan Quan <evan.quan@amd.com>,
Kenneth Feng <kenneth.feng@amd.com>,
Hawking Zhang <Hawking.Zhang@amd.com>
Subject: Re: [PATCH] drm/amdgpu: off by on in amdgpu_device_attr_create_groups() error handling
Date: Wed, 20 May 2020 15:52:09 +0300 [thread overview]
Message-ID: <20200520125209.GP3041@kadam> (raw)
In-Reply-To: <62d9d539-8401-233a-3f20-984042489987@gmail.com>
On Wed, May 20, 2020 at 02:05:19PM +0200, Christian König wrote:
> Am 20.05.20 um 14:00 schrieb Dan Carpenter:
> > This loop in the error handling code should start a "i - 1" and end at
> > "i == 0". Currently it starts a "i" and ends at "i == 1". The result
> > is that it removes one attribute that wasn't created yet, and leaks the
> > zeroeth attribute.
> >
> > Fixes: 4e01847c38f7 ("drm/amdgpu: optimize amdgpu device attribute code")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > ---
> > drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 5 ++---
> > 1 file changed, 2 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> > index b75362bf0742..ee4a8e44fbeb 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> > @@ -1931,7 +1931,7 @@ static int amdgpu_device_attr_create_groups(struct amdgpu_device *adev,
> > uint32_t mask)
> > {
> > int ret = 0;
> > - uint32_t i = 0;
> > + int i;
> > for (i = 0; i < counts; i++) {
> > ret = amdgpu_device_attr_create(adev, &attrs[i], mask);
> > @@ -1942,9 +1942,8 @@ static int amdgpu_device_attr_create_groups(struct amdgpu_device *adev,
> > return 0;
> > failed:
> > - for (; i > 0; i--) {
> > + while (--i >= 0)
>
> As far as I know the common idiom for this is while (i--) which even works
> without changing the type of i to signed.
It's about 50/50, one way or the other. To me --i >= 0 seems far more
readable.
I've been trying to figure out which tool tells people to make iterators
unsigned so I can help them avoid it. :/ I understand how in theory
iterators could go above INT_MAX but if we're going above INT_MAX then
probably we should use a 64 bit type. There are very few times where 2
billion iterations is not enough but in those situations probably 4
billion is not enough either. So unsigned int iterators never or seldom
solve real life bugs but they regularly cause them.
regards,
dan carpenter
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: christian.koenig@amd.com
Cc: David Airlie <airlied@linux.ie>, Kevin Wang <kevin1.wang@amd.com>,
kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org,
amd-gfx@lists.freedesktop.org, Rui Huang <ray.huang@amd.com>,
dri-devel@lists.freedesktop.org, Daniel Vetter <daniel@ffwll.ch>,
Alex Deucher <alexander.deucher@amd.com>,
Yintian Tao <yttao@amd.com>, Evan Quan <evan.quan@amd.com>,
Kenneth Feng <kenneth.feng@amd.com>,
Hawking Zhang <Hawking.Zhang@amd.com>
Subject: Re: [PATCH] drm/amdgpu: off by on in amdgpu_device_attr_create_groups() error handling
Date: Wed, 20 May 2020 12:52:09 +0000 [thread overview]
Message-ID: <20200520125209.GP3041@kadam> (raw)
In-Reply-To: <62d9d539-8401-233a-3f20-984042489987@gmail.com>
On Wed, May 20, 2020 at 02:05:19PM +0200, Christian König wrote:
> Am 20.05.20 um 14:00 schrieb Dan Carpenter:
> > This loop in the error handling code should start a "i - 1" and end at
> > "i = 0". Currently it starts a "i" and ends at "i = 1". The result
> > is that it removes one attribute that wasn't created yet, and leaks the
> > zeroeth attribute.
> >
> > Fixes: 4e01847c38f7 ("drm/amdgpu: optimize amdgpu device attribute code")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > ---
> > drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 5 ++---
> > 1 file changed, 2 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> > index b75362bf0742..ee4a8e44fbeb 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> > @@ -1931,7 +1931,7 @@ static int amdgpu_device_attr_create_groups(struct amdgpu_device *adev,
> > uint32_t mask)
> > {
> > int ret = 0;
> > - uint32_t i = 0;
> > + int i;
> > for (i = 0; i < counts; i++) {
> > ret = amdgpu_device_attr_create(adev, &attrs[i], mask);
> > @@ -1942,9 +1942,8 @@ static int amdgpu_device_attr_create_groups(struct amdgpu_device *adev,
> > return 0;
> > failed:
> > - for (; i > 0; i--) {
> > + while (--i >= 0)
>
> As far as I know the common idiom for this is while (i--) which even works
> without changing the type of i to signed.
It's about 50/50, one way or the other. To me --i >= 0 seems far more
readable.
I've been trying to figure out which tool tells people to make iterators
unsigned so I can help them avoid it. :/ I understand how in theory
iterators could go above INT_MAX but if we're going above INT_MAX then
probably we should use a 64 bit type. There are very few times where 2
billion iterations is not enough but in those situations probably 4
billion is not enough either. So unsigned int iterators never or seldom
solve real life bugs but they regularly cause them.
regards,
dan carpenter
WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: christian.koenig@amd.com
Cc: David Airlie <airlied@linux.ie>, Kevin Wang <kevin1.wang@amd.com>,
kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org,
amd-gfx@lists.freedesktop.org, Rui Huang <ray.huang@amd.com>,
dri-devel@lists.freedesktop.org,
Alex Deucher <alexander.deucher@amd.com>,
Yintian Tao <yttao@amd.com>, Evan Quan <evan.quan@amd.com>,
Kenneth Feng <kenneth.feng@amd.com>,
Hawking Zhang <Hawking.Zhang@amd.com>
Subject: Re: [PATCH] drm/amdgpu: off by on in amdgpu_device_attr_create_groups() error handling
Date: Wed, 20 May 2020 15:52:09 +0300 [thread overview]
Message-ID: <20200520125209.GP3041@kadam> (raw)
In-Reply-To: <62d9d539-8401-233a-3f20-984042489987@gmail.com>
On Wed, May 20, 2020 at 02:05:19PM +0200, Christian König wrote:
> Am 20.05.20 um 14:00 schrieb Dan Carpenter:
> > This loop in the error handling code should start a "i - 1" and end at
> > "i == 0". Currently it starts a "i" and ends at "i == 1". The result
> > is that it removes one attribute that wasn't created yet, and leaks the
> > zeroeth attribute.
> >
> > Fixes: 4e01847c38f7 ("drm/amdgpu: optimize amdgpu device attribute code")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > ---
> > drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 5 ++---
> > 1 file changed, 2 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> > index b75362bf0742..ee4a8e44fbeb 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> > @@ -1931,7 +1931,7 @@ static int amdgpu_device_attr_create_groups(struct amdgpu_device *adev,
> > uint32_t mask)
> > {
> > int ret = 0;
> > - uint32_t i = 0;
> > + int i;
> > for (i = 0; i < counts; i++) {
> > ret = amdgpu_device_attr_create(adev, &attrs[i], mask);
> > @@ -1942,9 +1942,8 @@ static int amdgpu_device_attr_create_groups(struct amdgpu_device *adev,
> > return 0;
> > failed:
> > - for (; i > 0; i--) {
> > + while (--i >= 0)
>
> As far as I know the common idiom for this is while (i--) which even works
> without changing the type of i to signed.
It's about 50/50, one way or the other. To me --i >= 0 seems far more
readable.
I've been trying to figure out which tool tells people to make iterators
unsigned so I can help them avoid it. :/ I understand how in theory
iterators could go above INT_MAX but if we're going above INT_MAX then
probably we should use a 64 bit type. There are very few times where 2
billion iterations is not enough but in those situations probably 4
billion is not enough either. So unsigned int iterators never or seldom
solve real life bugs but they regularly cause them.
regards,
dan carpenter
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: christian.koenig@amd.com
Cc: Alex Deucher <alexander.deucher@amd.com>,
Kevin Wang <kevin1.wang@amd.com>, David Airlie <airlied@linux.ie>,
kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org,
amd-gfx@lists.freedesktop.org,
Hawking Zhang <Hawking.Zhang@amd.com>,
Rui Huang <ray.huang@amd.com>,
dri-devel@lists.freedesktop.org, Daniel Vetter <daniel@ffwll.ch>,
Evan Quan <evan.quan@amd.com>,
Kenneth Feng <kenneth.feng@amd.com>, Yintian Tao <yttao@amd.com>
Subject: Re: [PATCH] drm/amdgpu: off by on in amdgpu_device_attr_create_groups() error handling
Date: Wed, 20 May 2020 15:52:09 +0300 [thread overview]
Message-ID: <20200520125209.GP3041@kadam> (raw)
In-Reply-To: <62d9d539-8401-233a-3f20-984042489987@gmail.com>
On Wed, May 20, 2020 at 02:05:19PM +0200, Christian König wrote:
> Am 20.05.20 um 14:00 schrieb Dan Carpenter:
> > This loop in the error handling code should start a "i - 1" and end at
> > "i == 0". Currently it starts a "i" and ends at "i == 1". The result
> > is that it removes one attribute that wasn't created yet, and leaks the
> > zeroeth attribute.
> >
> > Fixes: 4e01847c38f7 ("drm/amdgpu: optimize amdgpu device attribute code")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > ---
> > drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 5 ++---
> > 1 file changed, 2 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> > index b75362bf0742..ee4a8e44fbeb 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> > @@ -1931,7 +1931,7 @@ static int amdgpu_device_attr_create_groups(struct amdgpu_device *adev,
> > uint32_t mask)
> > {
> > int ret = 0;
> > - uint32_t i = 0;
> > + int i;
> > for (i = 0; i < counts; i++) {
> > ret = amdgpu_device_attr_create(adev, &attrs[i], mask);
> > @@ -1942,9 +1942,8 @@ static int amdgpu_device_attr_create_groups(struct amdgpu_device *adev,
> > return 0;
> > failed:
> > - for (; i > 0; i--) {
> > + while (--i >= 0)
>
> As far as I know the common idiom for this is while (i--) which even works
> without changing the type of i to signed.
It's about 50/50, one way or the other. To me --i >= 0 seems far more
readable.
I've been trying to figure out which tool tells people to make iterators
unsigned so I can help them avoid it. :/ I understand how in theory
iterators could go above INT_MAX but if we're going above INT_MAX then
probably we should use a 64 bit type. There are very few times where 2
billion iterations is not enough but in those situations probably 4
billion is not enough either. So unsigned int iterators never or seldom
solve real life bugs but they regularly cause them.
regards,
dan carpenter
next prev parent reply other threads:[~2020-05-20 12:54 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-20 12:00 [PATCH] drm/amdgpu: off by on in amdgpu_device_attr_create_groups() error handling Dan Carpenter
2020-05-20 12:00 ` Dan Carpenter
2020-05-20 12:00 ` Dan Carpenter
2020-05-20 12:00 ` Dan Carpenter
2020-05-20 12:05 ` Christian König
2020-05-20 12:05 ` Christian König
2020-05-20 12:05 ` Christian König
2020-05-20 12:05 ` Christian König
2020-05-20 12:52 ` Dan Carpenter [this message]
2020-05-20 12:52 ` Dan Carpenter
2020-05-20 12:52 ` Dan Carpenter
2020-05-20 12:52 ` Dan Carpenter
2020-05-20 13:08 ` [PATCH v2] " Dan Carpenter
2020-05-20 13:08 ` Dan Carpenter
2020-05-20 13:08 ` Dan Carpenter
2020-05-20 13:08 ` Dan Carpenter
2020-05-20 13:38 ` Wang, Kevin(Yang)
2020-05-20 13:38 ` Wang, Kevin(Yang)
2020-05-20 15:23 ` Ruhl, Michael J
2020-05-20 15:23 ` Ruhl, Michael J
2020-05-20 15:23 ` Ruhl, Michael J
2020-05-20 15:23 ` Ruhl, Michael J
2020-05-20 15:25 ` [PATCH v3] drm/amdgpu: off by one " Dan Carpenter
2020-05-20 15:25 ` Dan Carpenter
2020-05-20 15:25 ` Dan Carpenter
2020-05-20 15:25 ` Dan Carpenter
2020-05-20 15:31 ` Ruhl, Michael J
2020-05-20 15:31 ` Ruhl, Michael J
2020-05-20 15:31 ` Ruhl, Michael J
2020-05-20 15:31 ` Ruhl, Michael J
2020-05-20 15:32 ` Christian König
2020-05-20 15:32 ` Christian König
2020-05-20 15:32 ` Christian König
2020-05-20 15:32 ` Christian König
2020-05-20 18:39 ` Alex Deucher
2020-05-20 18:39 ` Alex Deucher
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=20200520125209.GP3041@kadam \
--to=dan.carpenter@oracle.com \
--cc=Hawking.Zhang@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=kenneth.feng@amd.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=kevin1.wang@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ray.huang@amd.com \
--cc=yttao@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: link
Be 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.