From: Joe Perches <joe@perches.com>
To: "Heinrich Schuchardt" <xypron.debian@gmx.de>,
"Heinrich Schuchardt" <xypron.glpk@gmx.de>,
"Alex Deucher" <alexander.deucher@amd.com>,
"Christian König" <christian.koenig@amd.com>
Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 1/1] drm/radeon: avoid NULL dereference, si_get_vce_clock_voltage
Date: Sun, 21 Aug 2016 14:31:04 -0700 [thread overview]
Message-ID: <1471815064.3746.29.camel@perches.com> (raw)
In-Reply-To: <6345f323-9fc5-6d26-f646-0a0a5989c34d@gmx.de>
On Sun, 2016-08-21 at 23:20 +0200, Heinrich Schuchardt wrote:
> On 08/21/2016 11:06 PM, Joe Perches wrote:
> > On Sun, 2016-08-21 at 22:52 +0200, Heinrich Schuchardt wrote:
> > >
> > > It does not make sense to check if table is NULL
> > > and afterwards to dereference it without
> > > considering the result.
> > This makes no sense.
> > > The inconsistency was indicated by cppcheck.
> > Perhaps this is a defect in cppcheck?
> > > An actual NULL pointer dereference was not observed.
> > []
> > > diff --git a/drivers/gpu/drm/radeon/si_dpm.c b/drivers/gpu/drm/radeon/si_dpm.c
> > []
> > > @@ -2962,7 +2962,7 @@ static int si_get_vce_clock_voltage(struct radeon_device *rdev,
> > > &rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table;
> > >
> > > if (((evclk == 0) && (ecclk == 0)) ||
> > > - (table && (table->count == 0))) {
> > Here table is only dereferenced if table is non-null
> > >
> > > + table == NULL || table->count == 0) {
> > > *voltage = 0;
> > > return 0;
> > > }
> > Perhaps the unnecessary parentheses can be reduce though.
> >
> > if ((evclk == 0 && ecclk == 0) || (table && table->count == 0)) {
> >
> The possible NULL pointer dereference would occur here:
>
> 2970 for (i = 0; i < table->count; i++) {
This still doesn't make any sense as table is known non-null
at line 2961
struct radeon_vce_clock_voltage_dependency_table *table =
&rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table;
So I now suggest simply removing the test for table.
Perhaps cppcheck can be improved to know about known non-null pointers.
_______________________________________________
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: Joe Perches <joe@perches.com>
To: "Heinrich Schuchardt" <xypron.debian@gmx.de>,
"Heinrich Schuchardt" <xypron.glpk@gmx.de>,
"Alex Deucher" <alexander.deucher@amd.com>,
"Christian König" <christian.koenig@amd.com>
Cc: David Airlie <airlied@linux.ie>,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] drm/radeon: avoid NULL dereference, si_get_vce_clock_voltage
Date: Sun, 21 Aug 2016 14:31:04 -0700 [thread overview]
Message-ID: <1471815064.3746.29.camel@perches.com> (raw)
In-Reply-To: <6345f323-9fc5-6d26-f646-0a0a5989c34d@gmx.de>
On Sun, 2016-08-21 at 23:20 +0200, Heinrich Schuchardt wrote:
> On 08/21/2016 11:06 PM, Joe Perches wrote:
> > On Sun, 2016-08-21 at 22:52 +0200, Heinrich Schuchardt wrote:
> > >
> > > It does not make sense to check if table is NULL
> > > and afterwards to dereference it without
> > > considering the result.
> > This makes no sense.
> > > The inconsistency was indicated by cppcheck.
> > Perhaps this is a defect in cppcheck?
> > > An actual NULL pointer dereference was not observed.
> > []
> > > diff --git a/drivers/gpu/drm/radeon/si_dpm.c b/drivers/gpu/drm/radeon/si_dpm.c
> > []
> > > @@ -2962,7 +2962,7 @@ static int si_get_vce_clock_voltage(struct radeon_device *rdev,
> > > &rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table;
> > >
> > > if (((evclk == 0) && (ecclk == 0)) ||
> > > - (table && (table->count == 0))) {
> > Here table is only dereferenced if table is non-null
> > >
> > > + table == NULL || table->count == 0) {
> > > *voltage = 0;
> > > return 0;
> > > }
> > Perhaps the unnecessary parentheses can be reduce though.
> >
> > if ((evclk == 0 && ecclk == 0) || (table && table->count == 0)) {
> >
> The possible NULL pointer dereference would occur here:
>
> 2970 for (i = 0; i < table->count; i++) {
This still doesn't make any sense as table is known non-null
at line 2961
struct radeon_vce_clock_voltage_dependency_table *table =
&rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table;
So I now suggest simply removing the test for table.
Perhaps cppcheck can be improved to know about known non-null pointers.
next prev parent reply other threads:[~2016-08-21 21:31 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-21 20:52 [PATCH 1/1] drm/radeon: avoid NULL dereference, si_get_vce_clock_voltage Heinrich Schuchardt
2016-08-21 21:06 ` Joe Perches
2016-08-21 21:06 ` Joe Perches
2016-08-21 21:20 ` Heinrich Schuchardt
2016-08-21 21:31 ` Joe Perches [this message]
2016-08-21 21:31 ` Joe Perches
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=1471815064.3746.29.camel@perches.com \
--to=joe@perches.com \
--cc=alexander.deucher@amd.com \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=xypron.debian@gmx.de \
--cc=xypron.glpk@gmx.de \
/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.