joystick: Ensure HIDAPI is initialized before calling it
diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c
index 8e5c96c..c2d9519 100644
--- a/src/joystick/hidapi/SDL_hidapijoystick.c
+++ b/src/joystick/hidapi/SDL_hidapijoystick.c
@@ -99,6 +99,7 @@
 static int SDL_HIDAPI_numdrivers = 0;
 static SDL_HIDAPI_Device *SDL_HIDAPI_devices;
 static int SDL_HIDAPI_numjoysticks = 0;
+static SDL_bool initialized = SDL_FALSE;
 
 #if defined(SDL_USE_LIBUDEV)
 static const SDL_UDEV_Symbols * usyms = NULL;
@@ -696,6 +697,10 @@
 {
     int i;
 
+    if (initialized) {
+        return 0;
+    }
+
     if (hid_init() < 0) {
         SDL_SetError("Couldn't initialize hidapi");
         return -1;
@@ -709,6 +714,9 @@
                         SDL_HIDAPIDriverHintChanged, NULL);
     HIDAPI_InitializeDiscovery();
     HIDAPI_JoystickDetect();
+
+    initialized = SDL_TRUE;
+
     return 0;
 }
 
@@ -1059,6 +1067,8 @@
     SDL_HIDAPI_numjoysticks = 0;
 
     hid_exit();
+
+    initialized = SDL_FALSE;
 }
 
 SDL_JoystickDriver SDL_HIDAPI_JoystickDriver =
diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c
index ad83091..55b558a 100644
--- a/src/joystick/linux/SDL_sysjoystick.c
+++ b/src/joystick/linux/SDL_sysjoystick.c
@@ -120,6 +120,8 @@
     }
 
 #ifdef SDL_JOYSTICK_HIDAPI
+    SDL_HIDAPI_JoystickDriver.Init();
+
     if (HIDAPI_IsDevicePresent(inpid.vendor, inpid.product, inpid.version)) {
         /* The HIDAPI driver is taking care of this device */
         return 0;