Skip to content

Commit 7eb85b0

Browse files
committed
kmsdrm: Fix one more place that doesn't try to drop master
1 parent dab4f85 commit 7eb85b0

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/video/kmsdrm/SDL_kmsdrmvideo.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,19 @@ static drmModeModeInfo *KMSDRM_GetClosestDisplayMode(SDL_VideoDisplay *display,
530530
/* _this is a SDL_VideoDevice * */
531531
/*****************************************************************************/
532532

533+
static SDL_bool KMSDRM_DropMaster(_THIS)
534+
{
535+
SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata);
536+
537+
/* Check if we have DRM master to begin with */
538+
if (KMSDRM_drmAuthMagic(viddata->drm_fd, 0) == -EACCES) {
539+
/* Nope, nothing to do then */
540+
return SDL_TRUE;
541+
}
542+
543+
return KMSDRM_drmDropMaster(viddata->drm_fd) < 0 ? SDL_FALSE : SDL_TRUE;
544+
}
545+
533546
/* Deinitializes the driverdata of the SDL Displays in the SDL display list. */
534547
static void KMSDRM_DeinitDisplays(_THIS)
535548
{
@@ -992,7 +1005,7 @@ static int KMSDRM_InitDisplays(_THIS)
9921005
/* Vulkan requires DRM master on its own FD to work, so try to drop master
9931006
on our FD. This will only work without root on kernels v5.8 and later.
9941007
If it doesn't work, just close the FD and we'll reopen it later. */
995-
if (KMSDRM_drmDropMaster(viddata->drm_fd) < 0) {
1008+
if (!KMSDRM_DropMaster(_this)) {
9961009
close(viddata->drm_fd);
9971010
viddata->drm_fd = -1;
9981011
}
@@ -1057,8 +1070,9 @@ static void KMSDRM_GBMDeinit(_THIS, SDL_DisplayData *dispdata)
10571070
viddata->gbm_dev = NULL;
10581071
}
10591072

1060-
/* Finally close DRM FD. May be reopen on next non-vulkan window creation. */
1061-
if (viddata->drm_fd >= 0) {
1073+
/* Finally drop DRM master if possible, otherwise close DRM FD.
1074+
May be reopened on next non-vulkan window creation. */
1075+
if (viddata->drm_fd >= 0 && !KMSDRM_DropMaster(_this)) {
10621076
close(viddata->drm_fd);
10631077
viddata->drm_fd = -1;
10641078
}

0 commit comments

Comments
 (0)