All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] drm/radeon: avoid NULL dereference, si_get_vce_clock_voltage
@ 2016-08-21 20:52 Heinrich Schuchardt
  2016-08-21 21:06   ` Joe Perches
  0 siblings, 1 reply; 6+ messages in thread
From: Heinrich Schuchardt @ 2016-08-21 20:52 UTC (permalink / raw)
  To: Alex Deucher, Christian König
  Cc: David Airlie, dri-devel, linux-kernel, Heinrich Schuchardt

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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] drm/radeon: avoid NULL dereference, si_get_vce_clock_voltage
  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
  0 siblings, 0 replies; 6+ messages in thread
From: Joe Perches @ 2016-08-21 21:06 UTC (permalink / raw)
  To: Heinrich Schuchardt, Alex Deucher, Christian König
  Cc: David Airlie, dri-devel, linux-kernel

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)) {

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] drm/radeon: avoid NULL dereference, si_get_vce_clock_voltage
@ 2016-08-21 21:06   ` Joe Perches
  0 siblings, 0 replies; 6+ messages in thread
From: Joe Perches @ 2016-08-21 21:06 UTC (permalink / raw)
  To: Heinrich Schuchardt, Alex Deucher, Christian König
  Cc: linux-kernel, dri-devel

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)) {
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] drm/radeon: avoid NULL dereference, si_get_vce_clock_voltage
  2016-08-21 21:06   ` Joe Perches
  (?)
@ 2016-08-21 21:20   ` Heinrich Schuchardt
  2016-08-21 21:31       ` Joe Perches
  -1 siblings, 1 reply; 6+ messages in thread
From: Heinrich Schuchardt @ 2016-08-21 21:20 UTC (permalink / raw)
  To: Joe Perches, Heinrich Schuchardt, Alex Deucher, Christian König
  Cc: David Airlie, dri-devel, linux-kernel

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++) {

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] drm/radeon: avoid NULL dereference, si_get_vce_clock_voltage
  2016-08-21 21:20   ` Heinrich Schuchardt
@ 2016-08-21 21:31       ` Joe Perches
  0 siblings, 0 replies; 6+ messages in thread
From: Joe Perches @ 2016-08-21 21:31 UTC (permalink / raw)
  To: Heinrich Schuchardt, Heinrich Schuchardt, Alex Deucher,
	Christian König
  Cc: David Airlie, dri-devel, linux-kernel

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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] drm/radeon: avoid NULL dereference, si_get_vce_clock_voltage
@ 2016-08-21 21:31       ` Joe Perches
  0 siblings, 0 replies; 6+ messages in thread
From: Joe Perches @ 2016-08-21 21:31 UTC (permalink / raw)
  To: Heinrich Schuchardt, Heinrich Schuchardt, Alex Deucher,
	Christian König
  Cc: linux-kernel, dri-devel

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-08-21 21:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2016-08-21 21:31       ` Joe Perches

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.