public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Chris Wilson <chris@chris-wilson.co.uk>
Cc: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org,
	Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
	Sumit Semwal <sumit.semwal@linaro.org>,
	Daniel Vetter <daniel.vetter@ffwll.ch>,
	linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org
Subject: Re: [PATCH] dma-buf: Release module reference on creation failure
Date: Mon, 18 Jul 2016 14:10:25 +0200	[thread overview]
Message-ID: <20160718121025.GY17101@phenom.ffwll.local> (raw)
In-Reply-To: <1468840582-21469-1-git-send-email-chris@chris-wilson.co.uk>

On Mon, Jul 18, 2016 at 12:16:22PM +0100, Chris Wilson wrote:
> If we fail to create the anon file, we need to remember to release the
> module reference on the owner.
> 
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> Cc: Sumit Semwal <sumit.semwal@linaro.org>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Cc: linux-media@vger.kernel.org
> Cc: dri-devel@lists.freedesktop.org
> Cc: linaro-mm-sig@lists.linaro.org
> ---
>  drivers/dma-buf/dma-buf.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
> index 20ce0687b111..ddaee60ae52a 100644
> --- a/drivers/dma-buf/dma-buf.c
> +++ b/drivers/dma-buf/dma-buf.c
> @@ -334,6 +334,7 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
>  	struct reservation_object *resv = exp_info->resv;
>  	struct file *file;
>  	size_t alloc_size = sizeof(struct dma_buf);
> +	int ret;

Not sure this really helps readability, but meh. Will apply to drm-misc,
with a cc: stable.
-Daniel

>  
>  	if (!exp_info->resv)
>  		alloc_size += sizeof(struct reservation_object);
> @@ -357,8 +358,8 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
>  
>  	dmabuf = kzalloc(alloc_size, GFP_KERNEL);
>  	if (!dmabuf) {
> -		module_put(exp_info->owner);
> -		return ERR_PTR(-ENOMEM);
> +		ret = -ENOMEM;
> +		goto err_module;
>  	}
>  
>  	dmabuf->priv = exp_info->priv;
> @@ -379,8 +380,8 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
>  	file = anon_inode_getfile("dmabuf", &dma_buf_fops, dmabuf,
>  					exp_info->flags);
>  	if (IS_ERR(file)) {
> -		kfree(dmabuf);
> -		return ERR_CAST(file);
> +		ret = PTR_ERR(file);
> +		goto err_dmabuf;
>  	}
>  
>  	file->f_mode |= FMODE_LSEEK;
> @@ -394,6 +395,12 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
>  	mutex_unlock(&db_list.lock);
>  
>  	return dmabuf;
> +
> +err_dmabuf:
> +	kfree(dmabuf);
> +err_module:
> +	module_put(exp_info->owner);
> +	return ERR_PTR(ret);
>  }
>  EXPORT_SYMBOL_GPL(dma_buf_export);
>  
> -- 
> 2.8.1
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

  reply	other threads:[~2016-07-18 12:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-18 11:16 [PATCH] dma-buf: Release module reference on creation failure Chris Wilson
2016-07-18 12:10 ` Daniel Vetter [this message]
2016-07-18 13:03   ` Sumit Semwal
  -- strict thread matches above, loose matches on Subject: below --
2016-03-31  8:35 Chris Wilson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160718121025.GY17101@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=chris@chris-wilson.co.uk \
    --cc=daniel.vetter@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-media@vger.kernel.org \
    --cc=sumit.semwal@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox