[PATCH 02/12] drm/ttm: Add a default BO destructor to simplify code

Ville Syrjälä ville.syrjala at linux.intel.com
Fri Jan 26 19:34:19 UTC 2018


On Fri, Jan 26, 2018 at 02:23:39PM -0500, Felix Kuehling wrote:
> On 2018-01-26 01:29 PM, Tom St Denis wrote:
> > Signed-off-by: Tom St Denis <tom.stdenis at amd.com>
> > ---
> >  drivers/gpu/drm/ttm/ttm_bo.c | 14 +++++++++-----
> >  1 file changed, 9 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> > index 8cf89da7030d..4e85c32fea26 100644
> > --- a/drivers/gpu/drm/ttm/ttm_bo.c
> > +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> > @@ -49,6 +49,12 @@ static struct attribute ttm_bo_count = {
> >  	.mode = S_IRUGO
> >  };
> >  
> > +/* default destructor */
> > +static void ttm_bo_default_destroy(struct ttm_buffer_object *bo)
> > +{
> > +	kfree(bo);
> > +};
> 
> Stray semicolon.
> 
> > +
> >  static inline int ttm_mem_type_from_place(const struct ttm_place *place,
> >  					  uint32_t *mem_type)
> >  {
> > @@ -147,10 +153,7 @@ static void ttm_bo_release_list(struct kref *list_kref)
> >  	dma_fence_put(bo->moving);
> >  	reservation_object_fini(&bo->ttm_resv);
> >  	mutex_destroy(&bo->wu_mutex);
> > -	if (bo->destroy)
> > -		bo->destroy(bo);
> > -	else
> > -		kfree(bo);
> > +	bo->destroy(bo);
> >  	ttm_mem_global_free(bdev->glob->mem_glob, acc_size);
> >  }
> >  
> > @@ -1176,7 +1179,8 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
> >  		ttm_mem_global_free(mem_glob, acc_size);
> >  		return -EINVAL;
> >  	}
> > -	bo->destroy = destroy;
> > +	bo->destroy =
> > +		(destroy == NULL) ? ttm_bo_default_destroy : destroy;
> 
> This could be written shorter as "!destroy ? ttm_bo_default_destroy :
> destroy", or even "destroy ? destroy : ttm_bo_default_destroy".

Or even 'destroy ?: ttm_bo_default_destroy' if you think
the gcc extension is cool enough. It is used elsewhere in
the kernel.

-- 
Ville Syrjälä
Intel OTC


More information about the amd-gfx mailing list