diff mbox series

drm/sched: Fix passing zero to 'PTR_ERR' warning

Message ID 1572361484-9828-1-git-send-email-andrey.grodzovsky@amd.com (mailing list archive)
State New, archived
Headers show
Series drm/sched: Fix passing zero to 'PTR_ERR' warning | expand

Commit Message

Andrey Grodzovsky Oct. 29, 2019, 3:04 p.m. UTC
Fix a static code checker warning.

Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com>
---
 drivers/gpu/drm/scheduler/sched_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Christian König Oct. 29, 2019, 1:06 p.m. UTC | #1
Am 29.10.19 um 16:04 schrieb Andrey Grodzovsky:
> Fix a static code checker warning.
>
> Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com>

Well that one was even new to me.

Patch is Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>   drivers/gpu/drm/scheduler/sched_main.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c
> index f39b97e..898b0c9 100644
> --- a/drivers/gpu/drm/scheduler/sched_main.c
> +++ b/drivers/gpu/drm/scheduler/sched_main.c
> @@ -497,7 +497,7 @@ void drm_sched_resubmit_jobs(struct drm_gpu_scheduler *sched)
>   
>   		if (IS_ERR_OR_NULL(fence)) {
>   			s_job->s_fence->parent = NULL;
> -			dma_fence_set_error(&s_fence->finished, PTR_ERR(fence));
> +			dma_fence_set_error(&s_fence->finished, PTR_ERR_OR_ZERO(fence));
>   		} else {
>   			s_job->s_fence->parent = fence;
>   		}
> @@ -742,7 +742,7 @@ static int drm_sched_main(void *param)
>   			dma_fence_put(fence);
>   		} else {
>   
> -			dma_fence_set_error(&s_fence->finished, PTR_ERR(fence));
> +			dma_fence_set_error(&s_fence->finished, PTR_ERR_OR_ZERO(fence));
>   			drm_sched_process_job(NULL, &sched_job->cb);
>   		}
>
Dan Carpenter Oct. 29, 2019, 5:51 p.m. UTC | #2
On Tue, Oct 29, 2019 at 11:04:44AM -0400, Andrey Grodzovsky wrote:
> Fix a static code checker warning.
> 
> Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com>
> ---
>  drivers/gpu/drm/scheduler/sched_main.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c
> index f39b97e..898b0c9 100644
> --- a/drivers/gpu/drm/scheduler/sched_main.c
> +++ b/drivers/gpu/drm/scheduler/sched_main.c
> @@ -497,7 +497,7 @@ void drm_sched_resubmit_jobs(struct drm_gpu_scheduler *sched)
>  
>  		if (IS_ERR_OR_NULL(fence)) {
>  			s_job->s_fence->parent = NULL;
> -			dma_fence_set_error(&s_fence->finished, PTR_ERR(fence));
> +			dma_fence_set_error(&s_fence->finished, PTR_ERR_OR_ZERO(fence));

This will silence the static checker warning, but it will still trigger
a WARN_ON().  And it sort of has inspired me to generate a new warning
because that's not how PTR_ERR_OR_ZERO() is supposed to be used.  :P

PTR_ERR_OR_ZERO() is short hand for this situation:

-	if (IS_ERR(fence))
-		return PTR_ERR(fence);
-	return 0;
+	return PTR_ERR_OR_ZERO(fence);

regards,
dan carpenter
Dan Carpenter Oct. 29, 2019, 6:03 p.m. UTC | #3
On Tue, Oct 29, 2019 at 11:04:44AM -0400, Andrey Grodzovsky wrote:
> Fix a static code checker warning.
> 
> Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com>
> ---
>  drivers/gpu/drm/scheduler/sched_main.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c
> index f39b97e..898b0c9 100644
> --- a/drivers/gpu/drm/scheduler/sched_main.c
> +++ b/drivers/gpu/drm/scheduler/sched_main.c
> @@ -497,7 +497,7 @@ void drm_sched_resubmit_jobs(struct drm_gpu_scheduler *sched)
> 		fence = sched->ops->run_job(s_job);
>  
>  		if (IS_ERR_OR_NULL(fence)) {
>  			s_job->s_fence->parent = NULL;
> -			dma_fence_set_error(&s_fence->finished, PTR_ERR(fence));
> +			dma_fence_set_error(&s_fence->finished, PTR_ERR_OR_ZERO(fence));

I feel like I should explain better.  It's generally bad to mix NULL and
error pointers.  The situation where you would do it is when NULL is a
special case of success.  A typical situation is you request a feature,
like maybe logging for example:

	p = get_logger();

If there isn't enough memory then get_logger() returns ERR_PTR(-ENOMEM);
but if the user has disabled logging then we can't return a valid
pointer but it's also not an error so we return NULL.  It's a special
case of success.

In this situation sched->ops->run_job(s_job); appears to only ever
return NULL and it's not a special case of success, it's a regular old
error.  I guess we are transitioning from returning NULL to returning
error pointers?

So we should just do something like:

	fence = sched->ops->run_job(s_job);

	/* FIXME: Oct 2019: Remove this code when fence can't be NULL. */
	if (!fence)
		fence = ERR_PTR(-EINVAL);

	if (IS_ERR(fence)) {
		...

regards,
dan carpenter
Andrey Grodzovsky Oct. 29, 2019, 6:10 p.m. UTC | #4
On 10/29/19 2:03 PM, Dan Carpenter wrote:
> On Tue, Oct 29, 2019 at 11:04:44AM -0400, Andrey Grodzovsky wrote:
>> Fix a static code checker warning.
>>
>> Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com>
>> ---
>>   drivers/gpu/drm/scheduler/sched_main.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c
>> index f39b97e..898b0c9 100644
>> --- a/drivers/gpu/drm/scheduler/sched_main.c
>> +++ b/drivers/gpu/drm/scheduler/sched_main.c
>> @@ -497,7 +497,7 @@ void drm_sched_resubmit_jobs(struct drm_gpu_scheduler *sched)
>> 		fence = sched->ops->run_job(s_job);
>>   
>>   		if (IS_ERR_OR_NULL(fence)) {
>>   			s_job->s_fence->parent = NULL;
>> -			dma_fence_set_error(&s_fence->finished, PTR_ERR(fence));
>> +			dma_fence_set_error(&s_fence->finished, PTR_ERR_OR_ZERO(fence));
> I feel like I should explain better.  It's generally bad to mix NULL and
> error pointers.  The situation where you would do it is when NULL is a
> special case of success.  A typical situation is you request a feature,
> like maybe logging for example:
>
> 	p = get_logger();
>
> If there isn't enough memory then get_logger() returns ERR_PTR(-ENOMEM);
> but if the user has disabled logging then we can't return a valid
> pointer but it's also not an error so we return NULL.  It's a special
> case of success.
>
> In this situation sched->ops->run_job(s_job); appears to only ever
> return NULL and it's not a special case of success, it's a regular old
> error.  I guess we are transitioning from returning NULL to returning
> error pointers?


No, check patch 'drm/amdgpu: If amdgpu_ib_schedule fails return back the 
error.' , amdgpu_job_run will pack an actual error code into ERR_PTR

Andrey


>
> So we should just do something like:
>
> 	fence = sched->ops->run_job(s_job);
>
> 	/* FIXME: Oct 2019: Remove this code when fence can't be NULL. */
> 	if (!fence)
> 		fence = ERR_PTR(-EINVAL);
>
> 	if (IS_ERR(fence)) {
> 		...
>
> regards,
> dan carpenter
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c
index f39b97e..898b0c9 100644
--- a/drivers/gpu/drm/scheduler/sched_main.c
+++ b/drivers/gpu/drm/scheduler/sched_main.c
@@ -497,7 +497,7 @@  void drm_sched_resubmit_jobs(struct drm_gpu_scheduler *sched)
 
 		if (IS_ERR_OR_NULL(fence)) {
 			s_job->s_fence->parent = NULL;
-			dma_fence_set_error(&s_fence->finished, PTR_ERR(fence));
+			dma_fence_set_error(&s_fence->finished, PTR_ERR_OR_ZERO(fence));
 		} else {
 			s_job->s_fence->parent = fence;
 		}
@@ -742,7 +742,7 @@  static int drm_sched_main(void *param)
 			dma_fence_put(fence);
 		} else {
 
-			dma_fence_set_error(&s_fence->finished, PTR_ERR(fence));
+			dma_fence_set_error(&s_fence->finished, PTR_ERR_OR_ZERO(fence));
 			drm_sched_process_job(NULL, &sched_job->cb);
 		}