[V2,5/6] drm/i915/gvt: Assign NULL to the pointer after memory free.

Submitted by Aleksei Gimbitskii on April 11, 2019, 10:46 a.m.

Details

Message ID 20190411104631.7627-6-aleksei.gimbitskii@intel.com
State New
Headers show
Series "Fix issues reported by klocwork" ( rev: 1 ) in Intel GVT devel

Not browsing as part of any series.

Commit Message

Aleksei Gimbitskii April 11, 2019, 10:46 a.m.
The klocwork static code analyzer complains about using pointer after
being freed, because further we pass it to the gvt_vgpu_err() function.
Assign pointer to be NULL intentionaly, to meet requirements of the code
analyzer.

This patch fixed the issue #648 reported as error by klocwork.

Signed-off-by: Aleksei Gimbitskii <aleksei.gimbitskii@intel.com>
Cc: Zhenyu Wang <zhenyuw@linux.intel.com>
Cc: Zhi Wang <zhi.a.wang@intel.com>
---
 drivers/gpu/drm/i915/gvt/gtt.c | 1 +
 1 file changed, 1 insertion(+)

Patch hide | download patch | download mbox

diff --git a/drivers/gpu/drm/i915/gvt/gtt.c b/drivers/gpu/drm/i915/gvt/gtt.c
index e44ddb328b4b..95cd8f25d6f9 100644
--- a/drivers/gpu/drm/i915/gvt/gtt.c
+++ b/drivers/gpu/drm/i915/gvt/gtt.c
@@ -1100,6 +1100,7 @@  static struct intel_vgpu_ppgtt_spt *ppgtt_populate_spt_by_guest_entry(
 
 err_free_spt:
 	ppgtt_free_spt(spt);
+	spt = NULL;
 err:
 	gvt_vgpu_err("fail: shadow page %p guest entry 0x%llx type %d\n",
 		     spt, we->val64, we->type);

Comments

On 2019-04-11 18:46, Aleksei Gimbitskii wrote:
> The klocwork static code analyzer complains about using pointer after
> being freed, because further we pass it to the gvt_vgpu_err() function.
> Assign pointer to be NULL intentionaly, to meet requirements of the code
> analyzer.
>
> This patch fixed the issue #648 reported as error by klocwork.
>
> Signed-off-by: Aleksei Gimbitskii <aleksei.gimbitskii@intel.com>
> Cc: Zhenyu Wang <zhenyuw@linux.intel.com>
> Cc: Zhi Wang <zhi.a.wang@intel.com>
> ---
>   drivers/gpu/drm/i915/gvt/gtt.c | 1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/drivers/gpu/drm/i915/gvt/gtt.c b/drivers/gpu/drm/i915/gvt/gtt.c
> index e44ddb328b4b..95cd8f25d6f9 100644
> --- a/drivers/gpu/drm/i915/gvt/gtt.c
> +++ b/drivers/gpu/drm/i915/gvt/gtt.c
> @@ -1100,6 +1100,7 @@ static struct intel_vgpu_ppgtt_spt *ppgtt_populate_spt_by_guest_entry(
>   
>   err_free_spt:
>   	ppgtt_free_spt(spt);
> +	spt = NULL;

Seems v2 is same as v1?

Set stp to NULL could guarantee the succeeding gvt_vgpu_err won't access it after freed.
However you won't know which spt fails at enable_page_track() or ppgtt_populate_spt().
You could add another gvt_vgpu_err before this ppgtt_free_spt(), and return after spt
set to NULL. By doing this the spt fail log could be more helpful in case of err_free_spt.

>   err:
>   	gvt_vgpu_err("fail: shadow page %p guest entry 0x%llx type %d\n",
>   		     spt, we->val64, we->type);