Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1467243 > unrolled thread

[PATCH 1/1] drm/radeon: avoid NULL dereference, si_get_vce_clock_voltage

Started byHeinrich Schuchardt <xypron.glpk@gmx.de>
First post2016-08-21 23:00 +0200
Last post2016-08-21 23:40 +0200
Articles 4 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 1/1] drm/radeon: avoid NULL dereference, si_get_vce_clock_voltage Heinrich Schuchardt <xypron.glpk@gmx.de> - 2016-08-21 23:00 +0200
    Re: [PATCH 1/1] drm/radeon: avoid NULL dereference,  si_get_vce_clock_voltage Joe Perches <joe@perches.com> - 2016-08-21 23:10 +0200
      Re: [PATCH 1/1] drm/radeon: avoid NULL dereference,  si_get_vce_clock_voltage Heinrich Schuchardt <xypron.debian@gmx.de> - 2016-08-21 23:30 +0200
        Re: [PATCH 1/1] drm/radeon: avoid NULL dereference,  si_get_vce_clock_voltage Joe Perches <joe@perches.com> - 2016-08-21 23:40 +0200

#1467243 — [PATCH 1/1] drm/radeon: avoid NULL dereference, si_get_vce_clock_voltage

FromHeinrich Schuchardt <xypron.glpk@gmx.de>
Date2016-08-21 23:00 +0200
Subject[PATCH 1/1] drm/radeon: avoid NULL dereference, si_get_vce_clock_voltage
Message-ID<s8I0x-5f3-7@gated-at.bofh.it>
It does not make sense to check if table is NULL
and afterwards to dereference it without
considering the result.

The inconsistency was indicated by cppcheck.
An actual NULL pointer dereference was not observed.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 drivers/gpu/drm/radeon/si_dpm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/radeon/si_dpm.c b/drivers/gpu/drm/radeon/si_dpm.c
index e6abc09..ba2cf12 100644
--- 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))) {
+	    table == NULL || table->count == 0) {
 		*voltage = 0;
 		return 0;
 	}
-- 
2.1.4

[toc] | [next] | [standalone]


#1467244 — Re: [PATCH 1/1] drm/radeon: avoid NULL dereference, si_get_vce_clock_voltage

FromJoe Perches <joe@perches.com>
Date2016-08-21 23:10 +0200
SubjectRe: [PATCH 1/1] drm/radeon: avoid NULL dereference, si_get_vce_clock_voltage
Message-ID<s8Iad-5xs-5@gated-at.bofh.it>
In reply to#1467243
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)) {

[toc] | [prev] | [next] | [standalone]


#1467271 — Re: [PATCH 1/1] drm/radeon: avoid NULL dereference, si_get_vce_clock_voltage

FromHeinrich Schuchardt <xypron.debian@gmx.de>
Date2016-08-21 23:30 +0200
SubjectRe: [PATCH 1/1] drm/radeon: avoid NULL dereference, si_get_vce_clock_voltage
Message-ID<s8ItA-5Ge-35@gated-at.bofh.it>
In reply to#1467244
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++) {

[toc] | [prev] | [next] | [standalone]


#1467282 — Re: [PATCH 1/1] drm/radeon: avoid NULL dereference, si_get_vce_clock_voltage

FromJoe Perches <joe@perches.com>
Date2016-08-21 23:40 +0200
SubjectRe: [PATCH 1/1] drm/radeon: avoid NULL dereference, si_get_vce_clock_voltage
Message-ID<s8IDg-5Jn-29@gated-at.bofh.it>
In reply to#1467271
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.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web