drm/fbdev: Update legacy plane->fb refcounting for atomic restore
drm/fbdev: Update legacy plane->fb refcounting for atomic restore

Starting with commit

        commit 28cc504e8d52248962f5b485bdc65f539e3fe21d
        Author: Rob Clark <915c10c999604870200b6defbe633d857c856ca0@gmail.com>
        Date:   Tue Aug 25 15:36:00 2015 -0400

            drm/i915: enable atomic fb-helper

I've been seeing some panics on i915 when the DRM master shuts down that appear
to be caused by using an already-freed framebuffer (i.e., we're unexpectedly
dropping our initial FB's reference count to 0 and freeing it, which causes a
crash when we try to restore it later).  Digging deeper, the state FB
refcounting is working as expected, but we seem to be missing proper
refcounting on the legacy plane->fb pointers in the new atomic fbdev code.

Tracking plane->old_fb and then doing a ref/unref at the end of the
fbdev restore like we do in the legacy ioctl's ensures we don't miscount
references on plane->fb and avoids the panics.

v2 from Daniel:

Really do what the atomic ioctl does:
- Also update plane->fb and plane->crtc.
- Clear out plane->old_fb on failures too.

v3: git add everything. Oops.

v4: Also clear old_fb in all other failure paths, spotted by David.

Cc: Rob Clark <915c10c999604870200b6defbe633d857c856ca0@gmail.com>
Cc: 3bdb751c0325ad49637e109aee01945d1dd19dd5@lists.freedesktop.org
Cc: David Herrmann <fb53b2ddb8d141e0cb39d7c67c2f81b6bc2eb0f7@gmail.com>
Cc: Maarten Lankhorst <743c2818a341d71b99ed2b566f9f80c2fc288f93@linux.intel.com>
Signed-off-by: Matt Roper <f1605a76cb9f6387d99228a0a9260318379b62de@intel.com> (v1)
Reviewd-by: David Herrmann <fb53b2ddb8d141e0cb39d7c67c2f81b6bc2eb0f7@gmail.com>
Signed-off-by: Daniel Vetter <c1b6782c4af8f0673da8923a0702a1832e5940f4@ffwll.ch>

KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs