From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>,
dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH 1/3] drm: Balance error path for GEM handle allocation
Date: Mon, 4 Jan 2016 17:33:45 +0200 [thread overview]
Message-ID: <20160104153345.GA4437@intel.com> (raw)
In-Reply-To: <20160104101850.GA12349@nuc-i3427.alporthouse.com>
On Mon, Jan 04, 2016 at 10:18:50AM +0000, Chris Wilson wrote:
> On Mon, Jan 04, 2016 at 10:10:59AM +0000, Chris Wilson wrote:
> > The current error path for failure when establishing a handle for a GEM
> > object is unbalance, e.g. we call object_close() without calling first
> > object_open(). Use the typical onion structure to only undo what has
> > been set up prior to the error.
> >
> > Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> > ---
> > drivers/gpu/drm/drm_gem.c | 29 +++++++++++++++++------------
> > 1 file changed, 17 insertions(+), 12 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
> > index 2e10bba4468b..a08176debc0e 100644
> > --- a/drivers/gpu/drm/drm_gem.c
> > +++ b/drivers/gpu/drm/drm_gem.c
> > @@ -343,27 +343,32 @@ drm_gem_handle_create_tail(struct drm_file *file_priv,
> > spin_unlock(&file_priv->table_lock);
> > idr_preload_end();
> > mutex_unlock(&dev->object_name_lock);
> > - if (ret < 0) {
> > - drm_gem_object_handle_unreference_unlocked(obj);
> > - return ret;
> > - }
> > + if (ret < 0)
> > + goto err_unref;
> > +
> > *handlep = ret;
> >
> > ret = drm_vma_node_allow(&obj->vma_node, file_priv->filp);
> > - if (ret) {
> > - drm_gem_handle_delete(file_priv, *handlep);
> > - return ret;
> > - }
> > + if (ret)
> > + goto err_remove;
> >
> > if (dev->driver->gem_open_object) {
> > ret = dev->driver->gem_open_object(obj, file_priv);
> > - if (ret) {
> > - drm_gem_handle_delete(file_priv, *handlep);
> > - return ret;
> > - }
> > + if (ret)
> > + goto err_revoke;
> > }
> >
> > return 0;
> > +
> > +err_revoke:
> > + drm_vma_node_revoke(&obj->vma_node, file_priv->filp);
> > +err_remove:
> > + spin_lock(&file_priv->table_lock);
> > + idr_remove(&file_priv->object_idr, *handlep);
>
> For bonus points, we could *handlep = 0; here.
For these sort of things I usually prefer to not clobber any
return parameters unless the whole operation suceeds.
>
> > + spin_unlock(&file_priv->table_lock);
> > +err_unref:
> > + drm_gem_object_handle_unreference_unlocked(obj);
> > + return ret;
> > }
>
> --
> Chris Wilson, Intel Open Source Technology Centre
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
--
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2016-01-04 15:33 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-04 10:10 [PATCH 1/3] drm: Balance error path for GEM handle allocation Chris Wilson
2016-01-04 10:11 ` [PATCH 2/3] drm: Only bump object-reference count when adding first handle Chris Wilson
2016-01-04 15:29 ` Ville Syrjälä
2016-01-04 10:11 ` [PATCH 3/3] drm: Use a normal idr allocation for the obj->name Chris Wilson
2016-01-04 15:31 ` Ville Syrjälä
2016-01-05 8:00 ` Daniel Vetter
2016-01-04 10:18 ` [PATCH 1/3] drm: Balance error path for GEM handle allocation Chris Wilson
2016-01-04 15:33 ` Ville Syrjälä [this message]
2016-01-04 15:37 ` Chris Wilson
2016-01-04 10:49 ` ✗ failure: Fi.CI.BAT Patchwork
2016-01-04 15:24 ` [PATCH 1/3] drm: Balance error path for GEM handle allocation Ville Syrjälä
2016-01-04 15:37 ` Ville Syrjälä
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=20160104153345.GA4437@intel.com \
--to=ville.syrjala@linux.intel.com \
--cc=chris@chris-wilson.co.uk \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.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