SDL: Only use the default gamepad mapping if an automatic mapping isn't available (80d36)

From 80d36aba5b2f3f3229a6b9642d19143a49ac32a4 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 3 Jul 2024 11:43:43 -0700
Subject: [PATCH] Only use the default gamepad mapping if an automatic mapping
 isn't available

Fixes https://github.com/libsdl-org/SDL/issues/10162

(cherry picked from commit 0f8054cf87e6b221659acca70d2471e05f2133e1)
(cherry picked from commit cd8ea5e3f169250cfe435f58d3b4c6c0d42dd2b2)
---
 src/joystick/SDL_gamecontroller.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c
index a7d3303b3161a..1cf8c2e417dba 100644
--- a/src/joystick/SDL_gamecontroller.c
+++ b/src/joystick/SDL_gamecontroller.c
@@ -1391,9 +1391,6 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForNameAndGUID(const
     }
 #endif /* __LINUX__ */
 
-    if (!mapping) {
-        mapping = s_pDefaultMapping;
-    }
     return mapping;
 }
 
@@ -1506,6 +1503,9 @@ static ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index)
         }
     }
 
+    if (!mapping) {
+        mapping = s_pDefaultMapping;
+    }
     return mapping;
 }
 
@@ -2059,7 +2059,7 @@ SDL_bool SDL_IsGameControllerNameAndGUID(const char *name, SDL_JoystickGUID guid
 
     SDL_LockJoysticks();
     {
-        if (SDL_PrivateGetControllerMappingForNameAndGUID(name, guid) != NULL) {
+        if (s_pDefaultMapping || SDL_PrivateGetControllerMappingForNameAndGUID(name, guid) != NULL) {
             retval = SDL_TRUE;
         } else {
             retval = SDL_FALSE;