[PATCH] drm/xe/guc: Fix deference after check

Everest K.C. posted 1 patch 1 month, 2 weeks ago
drivers/gpu/drm/xe/xe_guc_log.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] drm/xe/guc: Fix deference after check
Posted by Everest K.C. 1 month, 2 weeks ago
The `if (!snapshot->copy)` evaluates to True only when `snapshot->copy`
is Null. Thus, derefrencing `snapshot->copy` inside this if block is
equivalent to Null pointer derefrencing.
The `if` condition is now changed to evaluate to true only when
`snapshot->copy` is not Null.
This issue was reported by Coverity Scan.

Signed-off-by: Everest K.C. <everestkc@everestkc.com.np>
---
 drivers/gpu/drm/xe/xe_guc_log.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/xe/xe_guc_log.c b/drivers/gpu/drm/xe/xe_guc_log.c
index 7fbc56cceaba..4e1a5e8ba1e3 100644
--- a/drivers/gpu/drm/xe/xe_guc_log.c
+++ b/drivers/gpu/drm/xe/xe_guc_log.c
@@ -122,7 +122,7 @@ void xe_guc_log_snapshot_free(struct xe_guc_log_snapshot *snapshot)
 	if (!snapshot)
 		return;
 
-	if (!snapshot->copy) {
+	if (snapshot->copy) {
 		for (i = 0; i < snapshot->num_chunks; i++)
 			kfree(snapshot->copy[i]);
 		kfree(snapshot->copy);
-- 
2.43.0
Re: [PATCH] drm/xe/guc: Fix deference after check
Posted by Nirmoy Das 1 month, 2 weeks ago
On 10/8/2024 10:53 PM, Everest K.C. wrote:
> The `if (!snapshot->copy)` evaluates to True only when `snapshot->copy`
> is Null. Thus, derefrencing `snapshot->copy` inside this if block is
> equivalent to Null pointer derefrencing.
> The `if` condition is now changed to evaluate to true only when
> `snapshot->copy` is not Null.
> This issue was reported by Coverity Scan.
>
> Signed-off-by: Everest K.C. <everestkc@everestkc.com.np>

Fixes: d8ce1a977226 ("drm/xe/guc: Use a two stage dump for GuC logs and add more info")

Reviewed-by: Nirmoy Das <nirmoy.das@intel.com>

> ---
>  drivers/gpu/drm/xe/xe_guc_log.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_guc_log.c b/drivers/gpu/drm/xe/xe_guc_log.c
> index 7fbc56cceaba..4e1a5e8ba1e3 100644
> --- a/drivers/gpu/drm/xe/xe_guc_log.c
> +++ b/drivers/gpu/drm/xe/xe_guc_log.c
> @@ -122,7 +122,7 @@ void xe_guc_log_snapshot_free(struct xe_guc_log_snapshot *snapshot)
>  	if (!snapshot)
>  		return;
>  
> -	if (!snapshot->copy) {
> +	if (snapshot->copy) {
>  		for (i = 0; i < snapshot->num_chunks; i++)
>  			kfree(snapshot->copy[i]);
>  		kfree(snapshot->copy);