[PATCH v2 1/8] drm/omap: use refcount API to track the number of users of dma_addr
Tomi Valkeinen
tomi.valkeinen at ti.com
Thu Aug 1 09:06:45 UTC 2019
On 08/07/2019 13:45, Jean-Jacques Hiblot wrote:
> This would give us a WARN_ON() if the pin/unpin calls are unbalanced.
>
> Proposed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
> Signed-off-by: Jean-Jacques Hiblot <jjhiblot at ti.com>
> ---
> drivers/gpu/drm/omapdrm/omap_gem.c | 45 +++++++++++++++---------------
> 1 file changed, 23 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/gpu/drm/omapdrm/omap_gem.c b/drivers/gpu/drm/omapdrm/omap_gem.c
> index 37378dbc50d0..0b6eef120cc9 100644
> --- a/drivers/gpu/drm/omapdrm/omap_gem.c
> +++ b/drivers/gpu/drm/omapdrm/omap_gem.c
> @@ -65,7 +65,7 @@ struct omap_gem_object {
> /**
> * # of users of dma_addr
> */
> - u32 dma_addr_cnt;
> + refcount_t dma_addr_cnt;
>
> /**
> * If the buffer has been imported from a dmabuf the OMAP_DB_DMABUF flag
> @@ -771,13 +771,15 @@ int omap_gem_pin(struct drm_gem_object *obj, dma_addr_t *dma_addr)
> mutex_lock(&omap_obj->lock);
>
> if (!omap_gem_is_contiguous(omap_obj) && priv->has_dmm) {
> - if (omap_obj->dma_addr_cnt == 0) {
> + if (refcount_read(&omap_obj->dma_addr_cnt) == 0) {
> u32 npages = obj->size >> PAGE_SHIFT;
> enum tiler_fmt fmt = gem2fmt(omap_obj->flags);
> struct tiler_block *block;
>
> BUG_ON(omap_obj->block);
>
> + refcount_set(&omap_obj->dma_addr_cnt, 1);
> +
> ret = omap_gem_attach_pages(obj);
> if (ret)
> goto fail;
> @@ -811,10 +813,10 @@ int omap_gem_pin(struct drm_gem_object *obj, dma_addr_t *dma_addr)
> omap_obj->block = block;
>
> DBG("got dma address: %pad", &omap_obj->dma_addr);
> + } else {
> + refcount_inc(&omap_obj->dma_addr_cnt);
> }
>
> - omap_obj->dma_addr_cnt++;
> -
Was there a reason to not have refcount_inc() here, but to use
refcount_set above?
Reviewed-by: Tomi Valkeinen <tomi.valkeinen at ti.com>
Tomi
--
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
More information about the dri-devel
mailing list