Procházet zdrojové kódy

kmsdrm: Fix one more place that doesn't try to drop master

(cherry picked from commit 7eb85b07e0b76c7e8ae5bfdde5932af7249df395)
Cameron Gutman před 6 měsíci
rodič
revize
5e90dd3507
1 změnil soubory, kde provedl 17 přidání a 3 odebrání
  1. 17 3
      src/video/kmsdrm/SDL_kmsdrmvideo.c

+ 17 - 3
src/video/kmsdrm/SDL_kmsdrmvideo.c

@@ -530,6 +530,19 @@ static drmModeModeInfo *KMSDRM_GetClosestDisplayMode(SDL_VideoDisplay *display,
 /* _this is a SDL_VideoDevice *                                              */
 /*****************************************************************************/
 
+static SDL_bool KMSDRM_DropMaster(_THIS)
+{
+    SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata);
+
+    /* Check if we have DRM master to begin with */
+    if (KMSDRM_drmAuthMagic(viddata->drm_fd, 0) == -EACCES) {
+        /* Nope, nothing to do then */
+        return SDL_TRUE;
+    }
+
+    return KMSDRM_drmDropMaster(viddata->drm_fd) < 0 ? SDL_FALSE : SDL_TRUE;
+}
+
 /* Deinitializes the driverdata of the SDL Displays in the SDL display list. */
 static void KMSDRM_DeinitDisplays(_THIS)
 {
@@ -992,7 +1005,7 @@ static int KMSDRM_InitDisplays(_THIS)
     /* Vulkan requires DRM master on its own FD to work, so try to drop master
        on our FD. This will only work without root on kernels v5.8 and later.
        If it doesn't work, just close the FD and we'll reopen it later. */
-    if (KMSDRM_drmDropMaster(viddata->drm_fd) < 0) {
+    if (!KMSDRM_DropMaster(_this)) {
         close(viddata->drm_fd);
         viddata->drm_fd = -1;
     }
@@ -1057,8 +1070,9 @@ static void KMSDRM_GBMDeinit(_THIS, SDL_DisplayData *dispdata)
         viddata->gbm_dev = NULL;
     }
 
-    /* Finally close DRM FD. May be reopen on next non-vulkan window creation. */
-    if (viddata->drm_fd >= 0) {
+    /* Finally drop DRM master if possible, otherwise close DRM FD.
+       May be reopened on next non-vulkan window creation. */
+    if (viddata->drm_fd >= 0 && !KMSDRM_DropMaster(_this)) {
         close(viddata->drm_fd);
         viddata->drm_fd = -1;
     }