All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu: Modify error handling in amdgpu_ttm
@ 2016-08-04 15:42 Amitoj Kaur Chawla
  2016-08-05  8:04   ` Christian König
  0 siblings, 1 reply; 3+ messages in thread
From: Amitoj Kaur Chawla @ 2016-08-04 15:42 UTC (permalink / raw)
  To: airlied, dri-devel, linux-kernel; +Cc: julia.lawall

To indicate an error, debugfs_create_file can return an ERR_PTR for
!CONFIG_DEBUG_FS and NULL otherwise, so in case the result is
dereferenced there should be a previous IS_ERR and a NULL check.

The Coccinelle semantic patch used to find the issue is as follows:
@@
expression e;
identifier f;
@@

*  e = debugfs_create_file(...);
... when != e == NULL
e->f

Signed-off-by: Amitoj Kaur Chawla <amitoj1606@gmail.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 8a1752f..9ff70a7 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -1198,6 +1198,8 @@ static int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev)
 				  adev, &amdgpu_ttm_vram_fops);
 	if (IS_ERR(ent))
 		return PTR_ERR(ent);
+	if (!ent)
+		return -ENOMEM;
 	i_size_write(ent->d_inode, adev->mc.mc_vram_size);
 	adev->mman.vram = ent;
 
@@ -1205,6 +1207,8 @@ static int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev)
 				  adev, &amdgpu_ttm_gtt_fops);
 	if (IS_ERR(ent))
 		return PTR_ERR(ent);
+	if (!ent)
+		return -ENOMEM;
 	i_size_write(ent->d_inode, adev->mc.gtt_size);
 	adev->mman.gtt = ent;
 
-- 
1.9.1

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

* Re: [PATCH] drm/amdgpu: Modify error handling in amdgpu_ttm
  2016-08-04 15:42 [PATCH] drm/amdgpu: Modify error handling in amdgpu_ttm Amitoj Kaur Chawla
@ 2016-08-05  8:04   ` Christian König
  0 siblings, 0 replies; 3+ messages in thread
From: Christian König @ 2016-08-05  8:04 UTC (permalink / raw)
  To: Amitoj Kaur Chawla, airlied, dri-devel, linux-kernel; +Cc: julia.lawall

Am 04.08.2016 um 17:42 schrieb Amitoj Kaur Chawla:
> To indicate an error, debugfs_create_file can return an ERR_PTR for
> !CONFIG_DEBUG_FS and NULL otherwise, so in case the result is
> dereferenced there should be a previous IS_ERR and a NULL check.
>
> The Coccinelle semantic patch used to find the issue is as follows:
> @@
> expression e;
> identifier f;
> @@
>
> *  e = debugfs_create_file(...);
> ... when != e == NULL
> e->f
>
> Signed-off-by: Amitoj Kaur Chawla <amitoj1606@gmail.com>

The whole section is surrounded by CONFIG_DEBUG_FS, so I suggest to just 
replace the check or IS_ERR with a NULL check.

Regards,
Christian.

> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 4 ++++
>   1 file changed, 4 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> index 8a1752f..9ff70a7 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> @@ -1198,6 +1198,8 @@ static int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev)
>   				  adev, &amdgpu_ttm_vram_fops);
>   	if (IS_ERR(ent))
>   		return PTR_ERR(ent);
> +	if (!ent)
> +		return -ENOMEM;
>   	i_size_write(ent->d_inode, adev->mc.mc_vram_size);
>   	adev->mman.vram = ent;
>   
> @@ -1205,6 +1207,8 @@ static int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev)
>   				  adev, &amdgpu_ttm_gtt_fops);
>   	if (IS_ERR(ent))
>   		return PTR_ERR(ent);
> +	if (!ent)
> +		return -ENOMEM;
>   	i_size_write(ent->d_inode, adev->mc.gtt_size);
>   	adev->mman.gtt = ent;
>   

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

* Re: [PATCH] drm/amdgpu: Modify error handling in amdgpu_ttm
@ 2016-08-05  8:04   ` Christian König
  0 siblings, 0 replies; 3+ messages in thread
From: Christian König @ 2016-08-05  8:04 UTC (permalink / raw)
  To: Amitoj Kaur Chawla, airlied, dri-devel, linux-kernel; +Cc: julia.lawall

Am 04.08.2016 um 17:42 schrieb Amitoj Kaur Chawla:
> To indicate an error, debugfs_create_file can return an ERR_PTR for
> !CONFIG_DEBUG_FS and NULL otherwise, so in case the result is
> dereferenced there should be a previous IS_ERR and a NULL check.
>
> The Coccinelle semantic patch used to find the issue is as follows:
> @@
> expression e;
> identifier f;
> @@
>
> *  e = debugfs_create_file(...);
> ... when != e == NULL
> e->f
>
> Signed-off-by: Amitoj Kaur Chawla <amitoj1606@gmail.com>

The whole section is surrounded by CONFIG_DEBUG_FS, so I suggest to just 
replace the check or IS_ERR with a NULL check.

Regards,
Christian.

> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 4 ++++
>   1 file changed, 4 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> index 8a1752f..9ff70a7 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> @@ -1198,6 +1198,8 @@ static int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev)
>   				  adev, &amdgpu_ttm_vram_fops);
>   	if (IS_ERR(ent))
>   		return PTR_ERR(ent);
> +	if (!ent)
> +		return -ENOMEM;
>   	i_size_write(ent->d_inode, adev->mc.mc_vram_size);
>   	adev->mman.vram = ent;
>   
> @@ -1205,6 +1207,8 @@ static int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev)
>   				  adev, &amdgpu_ttm_gtt_fops);
>   	if (IS_ERR(ent))
>   		return PTR_ERR(ent);
> +	if (!ent)
> +		return -ENOMEM;
>   	i_size_write(ent->d_inode, adev->mc.gtt_size);
>   	adev->mman.gtt = ent;
>   


_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-04 15:42 [PATCH] drm/amdgpu: Modify error handling in amdgpu_ttm Amitoj Kaur Chawla
2016-08-05  8:04 ` Christian König
2016-08-05  8:04   ` Christian König

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.