All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Jesse Barnes <jbarnes@virtuousgeek.org>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>,
	Intel Graphics Development <intel-gfx@lists.freedesktop.org>
Subject: Re: [PATCH 2/2] drm/i915: Fix error path leak in fbdev fb allocation
Date: Tue, 11 Feb 2014 00:19:39 +0100	[thread overview]
Message-ID: <20140210231939.GG17001@phenom.ffwll.local> (raw)
In-Reply-To: <20140210094710.721ae3b2@jbarnes-desktop>

On Mon, Feb 10, 2014 at 09:47:10AM -0800, Jesse Barnes wrote:
> On Mon, 10 Feb 2014 18:00:39 +0100
> Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
> 
> > In Jesse's patch to switch the fbdev framebuffer from an embedded
> > struct to a pointer the kfree in case of an error was missed. Fix this
> > up by using our own internal fb allocation helper directly instead of
> > reinventing that wheel.
> > 
> > We need a to_intel_framebuffer cast unfortunately since all the other
> > callers of _create still look better whith using a drm_framebuffer as
> > return pointer.
> > 
> > v2: Add an unlocked __intel_framebuffer_create function since our
> > dev->struct_mutex locking is too much a mess. With ppgtt we even need
> > it to take a look at the global gtt offset of pinned objects, since
> > the vma list might chance from underneath us. At least with the
> > current global gtt lookup functions. Reported by Mika.
> > 
> > Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com>
> > Cc: Jesse Barnes <jbarnes@virtuousgeek.org>
> > Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> > ---
> >  drivers/gpu/drm/i915/intel_display.c | 35 ++++++++++++++++++++++++++---------
> >  drivers/gpu/drm/i915/intel_drv.h     |  4 ++--
> >  drivers/gpu/drm/i915/intel_fbdev.c   | 20 ++++++++------------
> >  3 files changed, 36 insertions(+), 23 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
> > index 6600931f213c..6ac4c23acc77 100644
> > --- a/drivers/gpu/drm/i915/intel_display.c
> > +++ b/drivers/gpu/drm/i915/intel_display.c
> > @@ -7690,10 +7690,15 @@ static struct drm_display_mode load_detect_mode = {
> >  		 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
> >  };
> >  
> > -static struct drm_framebuffer *
> > -intel_framebuffer_create(struct drm_device *dev,
> > -			 struct drm_mode_fb_cmd2 *mode_cmd,
> > -			 struct drm_i915_gem_object *obj)
> > +static int intel_framebuffer_init(struct drm_device *dev,
> > +				  struct intel_framebuffer *ifb,
> > +				  struct drm_mode_fb_cmd2 *mode_cmd,
> > +				  struct drm_i915_gem_object *obj);
> > +
> > +struct drm_framebuffer *
> > +__intel_framebuffer_create(struct drm_device *dev,
> > +			   struct drm_mode_fb_cmd2 *mode_cmd,
> > +			   struct drm_i915_gem_object *obj)
> >  {
> >  	struct intel_framebuffer *intel_fb;
> >  	int ret;
> > @@ -7704,12 +7709,7 @@ intel_framebuffer_create(struct drm_device *dev,
> >  		return ERR_PTR(-ENOMEM);
> >  	}
> >  
> > -	ret = i915_mutex_lock_interruptible(dev);
> > -	if (ret)
> > -		goto err;
> > -
> >  	ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj);
> > -	mutex_unlock(&dev->struct_mutex);
> >  	if (ret)
> >  		goto err;
> >  
> > @@ -7721,6 +7721,23 @@ err:
> >  	return ERR_PTR(ret);
> >  }
> >  
> > +struct drm_framebuffer *
> > +intel_framebuffer_create(struct drm_device *dev,
> > +			 struct drm_mode_fb_cmd2 *mode_cmd,
> > +			 struct drm_i915_gem_object *obj)
> > +{
> > +	struct drm_framebuffer *fb;
> > +	int ret;
> > +
> > +	ret = i915_mutex_lock_interruptible(dev);
> > +	if (ret)
> > +		return ERR_PTR(ret);
> > +	fb = __intel_framebuffer_create(dev, mode_cmd, obj);
> > +	mutex_unlock(&dev->struct_mutex);
> > +
> > +	return fb;
> > +}
> > +
> >  static u32
> >  intel_framebuffer_pitch_for_width(int width, int bpp)
> >  {
> > diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
> > index 59348a4d0238..aff9171a91d8 100644
> > --- a/drivers/gpu/drm/i915/intel_drv.h
> > +++ b/drivers/gpu/drm/i915/intel_drv.h
> > @@ -681,8 +681,8 @@ int intel_pin_and_fence_fb_obj(struct drm_device *dev,
> >  			       struct drm_i915_gem_object *obj,
> >  			       struct intel_ring_buffer *pipelined);
> >  void intel_unpin_fb_obj(struct drm_i915_gem_object *obj);
> > -int intel_framebuffer_init(struct drm_device *dev,
> > -			   struct intel_framebuffer *ifb,
> > +struct drm_framebuffer *
> > +__intel_framebuffer_create(struct drm_device *dev,
> >  			   struct drm_mode_fb_cmd2 *mode_cmd,
> >  			   struct drm_i915_gem_object *obj);
> >  void intel_prepare_page_flip(struct drm_device *dev, int plane);
> > diff --git a/drivers/gpu/drm/i915/intel_fbdev.c b/drivers/gpu/drm/i915/intel_fbdev.c
> > index e4f45293ccf5..12cc19d3eecb 100644
> > --- a/drivers/gpu/drm/i915/intel_fbdev.c
> > +++ b/drivers/gpu/drm/i915/intel_fbdev.c
> > @@ -62,20 +62,12 @@ static int intelfb_alloc(struct drm_fb_helper *helper,
> >  {
> >  	struct intel_fbdev *ifbdev =
> >  		container_of(helper, struct intel_fbdev, helper);
> > -	struct intel_framebuffer *fb;
> > +	struct drm_framebuffer *fb;
> >  	struct drm_device *dev = helper->dev;
> >  	struct drm_mode_fb_cmd2 mode_cmd = {};
> >  	struct drm_i915_gem_object *obj;
> >  	int size, ret;
> >  
> > -	fb = kzalloc(sizeof(*fb), GFP_KERNEL);
> > -	if (!fb) {
> > -		ret = -ENOMEM;
> > -		goto out;
> > -	}
> > -
> > -	ifbdev->fb = fb;
> > -
> >  	/* we don't do packed 24bpp */
> >  	if (sizes->surface_bpp == 24)
> >  		sizes->surface_bpp = 32;
> > @@ -102,13 +94,17 @@ static int intelfb_alloc(struct drm_fb_helper *helper,
> >  	/* Flush everything out, we'll be doing GTT only from now on */
> >  	ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
> >  	if (ret) {
> > -		DRM_ERROR("failed to pin fb: %d\n", ret);
> > +		DRM_ERROR("failed to pin obj: %d\n", ret);
> >  		goto out_unref;
> >  	}
> >  
> > -	ret = intel_framebuffer_init(dev, ifbdev->fb, &mode_cmd, obj);
> > -	if (ret)
> > +	fb = __intel_framebuffer_create(dev, &mode_cmd, obj);
> > +	if (IS_ERR(fb)) {
> > +		ret = PTR_ERR(fb);
> >  		goto out_unpin;
> > +	}
> > +
> > +	ifbdev->fb = to_intel_framebuffer(fb);
> >  
> >  	return 0;
> >  
> 
> Yeah I think this looks ok, though I'm not sure if it makes things
> clearer or not.

It looked much better before I had to add the __ version due to
dev->struct_mutex madness ... Maybe we should extract the framebuffer
handling code into intel_fb.c to clear up this maze a bit. And maybe we'll
eventually get saner locking ;-)

> Reviewed-by: Jesse Barnes <jbarnes@virtuousgeek.org>

Pulled in both patches, thanks for the review.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

  reply	other threads:[~2014-02-10 23:19 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-07 20:10 [PATCH 1/6] drm/i915: split aligned height calculation out v2 Jesse Barnes
2014-02-07 20:10 ` [PATCH 2/6] drm/i915: get_plane_config for i9xx v10 Jesse Barnes
2014-02-10 23:35   ` Daniel Vetter
2014-02-07 20:10 ` [PATCH 3/6] drm/i915: get_plane_config support for ILK+ Jesse Barnes
2014-02-07 20:10 ` [PATCH 4/6] drm/i915: alloc intel_fb in the intel_fbdev struct Jesse Barnes
2014-02-10  9:38   ` Daniel Vetter
2014-02-10 10:01   ` [PATCH 1/2] drm/i915: Use normal fb deref for the fbcon framebuffer Daniel Vetter
2014-02-10 10:01     ` [PATCH 2/2] drm/i915: Fix error path leak in fbdev fb allocation Daniel Vetter
2014-02-10 17:00   ` [PATCH 1/2] drm/i915: Use normal fb deref for the fbcon framebuffer Daniel Vetter
2014-02-10 17:00     ` [PATCH 2/2] drm/i915: Fix error path leak in fbdev fb allocation Daniel Vetter
2014-02-10 17:47       ` Jesse Barnes
2014-02-10 23:19         ` Daniel Vetter [this message]
2014-02-10 17:38     ` [PATCH 1/2] drm/i915: Use normal fb deref for the fbcon framebuffer Jesse Barnes
2014-02-07 20:10 ` [PATCH 5/6] drm/i915: allow re-use BIOS connector config for initial fbdev config Jesse Barnes
2014-02-10 10:22   ` Daniel Vetter
2014-02-07 20:10 ` [PATCH 6/6] drm/i915: Wrap the preallocated BIOS framebuffer and preserve for KMS fbcon v10 Jesse Barnes

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=20140210231939.GG17001@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=daniel.vetter@ffwll.ch \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jbarnes@virtuousgeek.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.