drm: mxsfb: Fix NULL pointer dereference crash on unload
Subsystems (4)
Marek Vasut
maintainerPATCH 1/1 drm: mxsfb: Fix NULL pointer dereference crash on unload
The mxsfb->crtc.funcs may already be NULL when unloading the driver, in which case calling mxsfb_irq_disable() via drm_irq_uninstall() from mxsfb_unload() leads to NULL pointer dereference.
Since all we care about is masking the IRQ and mxsfb->base is still valid, just use that to clear and mask the IRQ.
--- drivers/gpu/drm/mxsfb/mxsfb_drv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/mxsfb/mxsfb_drv.c +5 -1
@@ -173,7 +173,11 @@ static void mxsfb_irq_disable(struct drm_device *drm)struct mxsfb_drm_private *mxsfb = drm->dev_private;mxsfb_enable_axi_clk (mxsfb); - mxsfb->crtc.funcs->disable_vblank (&mxsfb->crtc); + +/* Disable and clear VBLANK IRQ */ +writel (CTRL1_CUR_FRAME_DONE_IRQ_EN , mxsfb->base +LCDC_CTRL1 +REG_CLR ); +writel (CTRL1_CUR_FRAME_DONE_IRQ , mxsfb->base +LCDC_CTRL1 +REG_CLR ); +mxsfb_disable_axi_clk (mxsfb); }
Signature · 1 line
2.33.0
Quoted 7 lines · Marek Vasut
The
mxsfb->crtc.funcsmay already be NULL when unloading the driver, in which case callingmxsfb_irq_disable()viadrm_irq_uninstall()frommxsfb_unload()leads to NULL pointer dereference.Since all we care about is masking the IRQ and
mxsfb->baseis still valid, just use that to clear and mask the IRQ.
Quoted 7 lines
Fixes ae1ed00932819 ("drm: mxsfb: Stop using DRM simple display pipeline helper")Signed-off-by Marek Vasut <[email protected]>Cc Daniel Abrecht <[email protected]>Cc Emil Velikov <[email protected]>Cc Laurent Pinchart <[email protected]>Cc Sam Ravnborg <[email protected]>Cc Stefan Agner <[email protected]>
You probably want a drm_atomic_helper_shutdown instead of trying to do all that manually. We've also added a bunch more devm and drmm_ functions to automate the cleanup a lot more here, e.g. your drm_mode_config_cleanup is in the wrong place.
Also I'm confused because I'm not even seeing this function anywhere in upstream.
-Daniel
Quoted 24 lines
--- drivers/gpu/drm/mxsfb/mxsfb_drv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/gpu/drm/mxsfb/mxsfb_drv.c +5
-1@@ -173,7 +173,11 @@ static void mxsfb_irq_disable(struct drm_device *drm)struct mxsfb_drm_private *mxsfb = drm->dev_private;mxsfb_enable_axi_clk (mxsfb); - mxsfb->crtc.funcs->disable_vblank (&mxsfb->crtc); + +/* Disable and clear VBLANK IRQ */ +writel (CTRL1_CUR_FRAME_DONE_IRQ_EN , mxsfb->base +LCDC_CTRL1 +REG_CLR ); +writel (CTRL1_CUR_FRAME_DONE_IRQ , mxsfb->base +LCDC_CTRL1 +REG_CLR ); +mxsfb_disable_axi_clk (mxsfb); }Signature · 1 line
2.33.0
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Marek Vasut
maintainerQuoted 16 lines · Daniel Vetter
Quoted 7 lines · Marek Vasut
The
mxsfb->crtc.funcsmay already be NULL when unloading the driver, in which case callingmxsfb_irq_disable()viadrm_irq_uninstall()frommxsfb_unload()leads to NULL pointer dereference.Since all we care about is masking the IRQ and
mxsfb->baseis still valid, just use that to clear and mask the IRQ.Quoted 7 lines
Fixes ae1ed00932819 ("drm: mxsfb: Stop using DRM simple display pipeline helper")Signed-off-by Marek Vasut <[email protected]>Cc Daniel Abrecht <[email protected]>Cc Emil Velikov <[email protected]>Cc Laurent Pinchart <[email protected]>Cc Sam Ravnborg <[email protected]>Cc Stefan Agner <[email protected]>
Quoted 7 lines
You probably want a
drm_atomic_helper_shutdowninstead of trying to do all that manually. We've also added a bunch more devm anddrmm_functions to automate the cleanup a lot more here, e.g. yourdrm_mode_config_cleanupis in the wrong place.Also I'm confused because I'm not even seeing this function anywhere in upstream.
It is still here:
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/gpu/drm/mxsfb/mxsfb_drv.c#n171
as of:999569d59a0aa ("Add linux-next specific files for 20210908")
Is there some other tree I should be looking at ?
Sam Ravnborg
AppliedHi Marek,
Quoted 16 lines · Daniel Vetter
Quoted 7 lines · Marek Vasut
The
mxsfb->crtc.funcsmay already be NULL when unloading the driver, in which case callingmxsfb_irq_disable()viadrm_irq_uninstall()frommxsfb_unload()leads to NULL pointer dereference.Since all we care about is masking the IRQ and
mxsfb->baseis still valid, just use that to clear and mask the IRQ.Quoted 7 lines
Fixes ae1ed00932819 ("drm: mxsfb: Stop using DRM simple display pipeline helper")Signed-off-by Marek Vasut <[email protected]>Cc Daniel Abrecht <[email protected]>Cc Emil Velikov <[email protected]>Cc Laurent Pinchart <[email protected]>Cc Sam Ravnborg <[email protected]>Cc Stefan Agner <[email protected]>
Quoted 4 lines
You probably want a
drm_atomic_helper_shutdowninstead of trying to do all that manually. We've also added a bunch more devm anddrmm_functions to automate the cleanup a lot more here, e.g. yourdrm_mode_config_cleanupis in the wrong place.
I have applied v2 of this patch today - but failed to see any response in v2 to this comment from Daniel. Was it lost somehow?
Sam
Marek Vasut
maintainerQuoted 19 lines · Sam Ravnborg
Hi Marek,
Quoted 16 lines · Daniel Vetter
Quoted 14 lines · Marek Vasut
The
mxsfb->crtc.funcsmay already be NULL when unloading the driver, in which case callingmxsfb_irq_disable()viadrm_irq_uninstall()frommxsfb_unload()leads to NULL pointer dereference.Since all we care about is masking the IRQ and
mxsfb->baseis still valid, just use that to clear and mask the IRQ.Fixes ae1ed00932819 ("drm: mxsfb: Stop using DRM simple display pipeline helper")Signed-off-by Marek Vasut <[email protected]>Cc Daniel Abrecht <[email protected]>Cc Emil Velikov <[email protected]>Cc Laurent Pinchart <[email protected]>Cc Sam Ravnborg <[email protected]>Cc Stefan Agner <[email protected]>
Quoted 7 lines
Quoted 4 lines
You probably want a
drm_atomic_helper_shutdowninstead of trying to do all that manually. We've also added a bunch more devm anddrmm_functions to automate the cleanup a lot more here, e.g. yourdrm_mode_config_cleanupis in the wrong place.I have applied v2 of this patch today - but failed to see any response in v2 to this comment from Daniel. Was it lost somehow?
Hmmm, I'll investigate that ^ in the next round of mxsfb clean ups.
Quoted 26 lines · Marek Vasut
Quoted 24 lines · Sam Ravnborg
Hi Marek,
Quoted 20 lines · Daniel Vetter
Quoted 7 lines · Marek Vasut
The
mxsfb->crtc.funcsmay already be NULL when unloading the driver, in which case callingmxsfb_irq_disable()viadrm_irq_uninstall()frommxsfb_unload()leads to NULL pointer dereference.Since all we care about is masking the IRQ and
mxsfb->baseis still valid, just use that to clear and mask the IRQ.Quoted 7 lines
Fixes ae1ed00932819 ("drm: mxsfb: Stop using DRM simple display pipeline helper")Signed-off-by Marek Vasut <[email protected]>Cc Daniel Abrecht <[email protected]>Cc Emil Velikov <[email protected]>Cc Laurent Pinchart <[email protected]>Cc Sam Ravnborg <[email protected]>Cc Stefan Agner <[email protected]>You probably want a
drm_atomic_helper_shutdowninstead of trying to do all that manually. We've also added a bunch more devm anddrmm_functions to automate the cleanup a lot more here, e.g. yourdrm_mode_config_cleanupis in the wrong place.
Quoted 4 lines
Quoted 2 lines
I have applied v2 of this patch today - but failed to see any response in v2 to this comment from Daniel. Was it lost somehow?
Hmmm, I'll investigate that ^ in the next round of mxsfb clean ups.
Yeah this was just a quick comment about how to do this cleanly, not meant to hold up a bugfix or anything like that.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch