Haptic/Linux: Keep track of device numbers properly to track duplicates. Fixes Bugzilla #3014.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
diff --git a/src/haptic/linux/SDL_syshaptic.c b/src/haptic/linux/SDL_syshaptic.c
index f72edfc..ab0a570 100644
--- a/src/haptic/linux/SDL_syshaptic.c
+++ b/src/haptic/linux/SDL_syshaptic.c
@@ -59,6 +59,7 @@ typedef struct SDL_hapticlist_item
{
char *fname; /* Dev path name (like /dev/input/event1) */
SDL_Haptic *haptic; /* Associated haptic. */
+ dev_t dev_num;
struct SDL_hapticlist_item *next;
} SDL_hapticlist_item;
@@ -236,15 +237,11 @@ void haptic_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class, const
static int
MaybeAddDevice(const char *path)
{
- dev_t dev_nums[MAX_HAPTICS];
struct stat sb;
int fd;
- int k;
- int duplicate;
int success;
SDL_hapticlist_item *item;
-
if (path == NULL) {
return -1;
}
@@ -255,15 +252,11 @@ MaybeAddDevice(const char *path)
}
/* check for duplicates */
- duplicate = 0;
- for (k = 0; (k < numhaptics) && !duplicate; ++k) {
- if (sb.st_rdev == dev_nums[k]) {
- duplicate = 1;
+ for (item = SDL_hapticlist; item != NULL; item = item->next) {
+ if (item->dev_num == sb.st_rdev) {
+ return -1; /* duplicate. */
}
}
- if (duplicate) {
- return -1;
- }
/* try to open */
fd = open(path, O_RDWR, 0);
@@ -293,6 +286,8 @@ MaybeAddDevice(const char *path)
return -1;
}
+ item->dev_num = sb.st_rdev;
+
/* TODO: should we add instance IDs? */
if (SDL_hapticlist_tail == NULL) {
SDL_hapticlist = SDL_hapticlist_tail = item;
@@ -301,8 +296,6 @@ MaybeAddDevice(const char *path)
SDL_hapticlist_tail = item;
}
- dev_nums[numhaptics] = sb.st_rdev;
-
++numhaptics;
/* !!! TODO: Send a haptic add event? */
@@ -546,7 +539,6 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
int ret;
SDL_hapticlist_item *item;
-
/* Find the joystick in the haptic list. */
for (item = SDL_hapticlist; item; item = item->next) {
if (SDL_strcmp(item->fname, joystick->hwdata->fname) == 0) {