Skip to content

Commit e2f8fd7

Browse files
committed
drm/omap: fix race issue when unloading omapdrm
At module unload, omap_fbdev_free() gets called which releases the framebuffers. However, the framebuffers are still used by crtcs, and will be released only later at vsync. The driver doesn't wait for this, and goes on to release the rest of the resources, which often causes a crash. This patchs adds a omap_crtc_flush() function which waits until the crtc has finished with its apply queue and page flips. The function utilizes a simple polling while-loop, as the performance is not an issue here. Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com> Reviewed-by: Rob Clark <robdclark@gmail.com>
1 parent ea7e3a6 commit e2f8fd7

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

‎drivers/gpu/drm/omapdrm/omap_crtc.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,25 @@ static void omap_crtc_post_apply(struct omap_drm_apply *apply)
621621
/* nothing needed for post-apply */
622622
}
623623

624+
void omap_crtc_flush(struct drm_crtc *crtc)
625+
{
626+
struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
627+
int loops = 0;
628+
629+
while (!list_empty(&omap_crtc->pending_applies) ||
630+
!list_empty(&omap_crtc->queued_applies) ||
631+
omap_crtc->event || omap_crtc->old_fb) {
632+
633+
if (++loops > 10) {
634+
dev_err(crtc->dev->dev,
635+
"omap_crtc_flush() timeout\n");
636+
break;
637+
}
638+
639+
schedule_timeout_uninterruptible(msecs_to_jiffies(20));
640+
}
641+
}
642+
624643
static const char *channel_names[] = {
625644
[OMAP_DSS_CHANNEL_LCD] = "lcd",
626645
[OMAP_DSS_CHANNEL_DIGIT] = "tv",

‎drivers/gpu/drm/omapdrm/omap_drv.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,12 +513,18 @@ static int dev_load(struct drm_device *dev, unsigned long flags)
513513
static int dev_unload(struct drm_device *dev)
514514
{
515515
struct omap_drm_private *priv = dev->dev_private;
516+
int i;
516517

517518
DBG("unload: dev=%p", dev);
518519

519520
drm_kms_helper_poll_fini(dev);
520521

521522
omap_fbdev_free(dev);
523+
524+
/* flush crtcs so the fbs get released */
525+
for (i = 0; i < priv->num_crtcs; i++)
526+
omap_crtc_flush(priv->crtcs[i]);
527+
522528
omap_modeset_free(dev);
523529
omap_gem_deinit(dev);
524530

‎drivers/gpu/drm/omapdrm/omap_drv.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ void omap_crtc_pre_init(void);
163163
void omap_crtc_pre_uninit(void);
164164
struct drm_crtc *omap_crtc_init(struct drm_device *dev,
165165
struct drm_plane *plane, enum omap_channel channel, int id);
166+
void omap_crtc_flush(struct drm_crtc *crtc);
166167

167168
struct drm_plane *omap_plane_init(struct drm_device *dev,
168169
int plane_id, bool private_plane);

0 commit comments

Comments
 (0)