[Intel-gfx] [PATCH] drm/i915/gvt: clean up intel_gvt.h as interface for i915 core

Chris Wilson chris at chris-wilson.co.uk
Thu Oct 20 07:41:37 UTC 2016


On Thu, Oct 20, 2016 at 03:29:13PM +0800, Zhenyu Wang wrote:
> @@ -214,9 +215,15 @@ int intel_gvt_init_device(struct drm_i915_private *dev_priv)
>  	if (WARN_ON(!intel_gvt_host.initialized))
>  		return -EINVAL;
>  
> -	if (WARN_ON(gvt->initialized))
> +	if (WARN_ON(dev_priv->gvt))
>  		return -EEXIST;
>  
> +	dev_priv->gvt = kzalloc(sizeof(struct intel_gvt), GFP_KERNEL);
> +	if (!dev_priv->gvt)
> +		return -ENOMEM;
> +
> +	gvt = to_gvt(dev_priv);
> +
>  	gvt_dbg_core("init gvt device\n");
>  
>  	mutex_init(&gvt->lock);
> @@ -280,5 +287,6 @@ out_free_firmware:
>  	intel_gvt_free_firmware(gvt);
>  out_clean_mmio_info:
>  	intel_gvt_clean_mmio_info(gvt);
> +	kfree(dev_priv->gvt);

And now dev_priv->gvt points where? What does
intel_gvt_active() think about that?

Allocate to the local gvt, and assign that to dev_priv->gvt at the end
once initialised and it has passed all the tests.

> diff --git a/drivers/gpu/drm/i915/gvt/gvt.h b/drivers/gpu/drm/i915/gvt/gvt.h
> index 1564554..fd33e6b 100644
> --- a/drivers/gpu/drm/i915/gvt/gvt.h
> +++ b/drivers/gpu/drm/i915/gvt/gvt.h
> @@ -213,6 +213,8 @@ struct intel_gvt {
>  	unsigned long service_request;
>  };
>  
> +#define to_gvt(dev_priv) (struct intel_gvt *)(dev_priv->gvt)

Why so few brackets? Like to play dangerously?

> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index 4d1133f..964d33d 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -1778,7 +1778,7 @@ struct drm_i915_private {
>  
>  	struct i915_virtual_gpu vgpu;
>  
> -	struct intel_gvt gvt;
> +	void *gvt;

Better to have a struct intel_gvt forward declaration than a void *.

>  	struct intel_guc guc;
>  
> @@ -2992,7 +2992,7 @@ int intel_wait_for_register_fw(struct drm_i915_private *dev_priv,
>  
>  static inline bool intel_gvt_active(struct drm_i915_private *dev_priv)
>  {
> -	return dev_priv->gvt.initialized;
> +	return (dev_priv->gvt != NULL);

(Why (so (many (brackets))))? Why redundant tests, why not Zoidberg?

>  }
>  
>  static inline bool intel_vgpu_active(struct drm_i915_private *dev_priv)
> diff --git a/drivers/gpu/drm/i915/intel_gvt.c b/drivers/gpu/drm/i915/intel_gvt.c
> index 8e8596d..bae1a7d 100644
> --- a/drivers/gpu/drm/i915/intel_gvt.c
> +++ b/drivers/gpu/drm/i915/intel_gvt.c
> @@ -103,4 +103,5 @@ void intel_gvt_cleanup(struct drm_i915_private *dev_priv)
>  		return;
>  
>  	intel_gvt_clean_device(dev_priv);
> +	kfree(dev_priv->gvt);

It wasn't allocated in intel_gvt.c, it shouldn't be freed here either.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre


More information about the Intel-gfx mailing list