drm/nv04/crtc: Bail out if FB is not bound to crtc

This commit resolves a possible 'NULL pointer dereference'
It uses the same approach as radeon, intel and nouveau/nv50

Fixes bug 'Nouveau: Kernel oops when unplugging external monitor'
https://bugs.freedesktop.org/show_bug.cgi?id=40336

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>

authored by Emil Velikov and committed by Ben Skeggs 0e83bb4e 1bf27066

Changed files
+13 -2
drivers
gpu
drm
nouveau
+13 -2
drivers/gpu/drm/nouveau/nv04_crtc.c
··· 781 781 struct drm_device *dev = crtc->dev; 782 782 struct drm_nouveau_private *dev_priv = dev->dev_private; 783 783 struct nv04_crtc_reg *regp = &dev_priv->mode_reg.crtc_reg[nv_crtc->index]; 784 - struct drm_framebuffer *drm_fb = nv_crtc->base.fb; 785 - struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb); 784 + struct drm_framebuffer *drm_fb; 785 + struct nouveau_framebuffer *fb; 786 786 int arb_burst, arb_lwm; 787 787 int ret; 788 + 789 + NV_DEBUG_KMS(dev, "index %d\n", nv_crtc->index); 790 + 791 + /* no fb bound */ 792 + if (!atomic && !crtc->fb) { 793 + NV_DEBUG_KMS(dev, "No FB bound\n"); 794 + return 0; 795 + } 796 + 788 797 789 798 /* If atomic, we want to switch to the fb we were passed, so 790 799 * now we update pointers to do that. (We don't pin; just ··· 803 794 drm_fb = passed_fb; 804 795 fb = nouveau_framebuffer(passed_fb); 805 796 } else { 797 + drm_fb = crtc->fb; 798 + fb = nouveau_framebuffer(crtc->fb); 806 799 /* If not atomic, we can go ahead and pin, and unpin the 807 800 * old fb we were passed. 808 801 */