From 2f3b8368f63fa02928df70d11860c71587d99506 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Mon, 15 Feb 2021 06:21:20 +0300
Subject: [PATCH] fix USB joystick input for FreeBSD 9.0+ (bug #1552)
patch from Marcus von Appen.
---
WhatsNew | 1 +
docs.html | 3 +++
src/joystick/bsd/SDL_sysjoystick.c | 12 ++++++++++--
3 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/WhatsNew b/WhatsNew
index 7ebf39e2..503c8095 100644
--- a/WhatsNew
+++ b/WhatsNew
@@ -75,6 +75,7 @@ Changes include:
- Linux, joystick: enhance detection of gamepads.
- Linux, joystick: allow for custom joystick names.
- FreeBSD, joystick: compile fixes.
+- BSD, joystick: fix USB joystick input for FreeBSD 9.0+ (bug 1552)
- BSD, joystick: increase the number of uhid devices to scan (bug 1561)
- Linux, ALSA: fix excessive I/O causing high CPU usage (bug 4941.)
- Linux, evdev: ignore joystick axis events if they aren't in a sane
diff --git a/docs.html b/docs.html
index b28238fd..3191e763 100644
--- a/docs.html
+++ b/docs.html
@@ -181,6 +181,9 @@ <H2> SDL 1.2.16 Release Notes </H2>
<P>
FreeBSD, joystick: compile fixes.
</P>
+<P>
+ BSD, joystick: fix USB joystick input for FreeBSD 9.0+ (bug <a href="https://bugzilla.libsdl.org/show_bug.cgi?id=1552">1552</a>)
+</P>
<P>
BSD, joystick: increase the number of uhid devices to scan (bug <a href="https://bugzilla.libsdl.org/show_bug.cgi?id=1561">1561</a>)
</P>
diff --git a/src/joystick/bsd/SDL_sysjoystick.c b/src/joystick/bsd/SDL_sysjoystick.c
index 882fa5f9..a5cbf355 100644
--- a/src/joystick/bsd/SDL_sysjoystick.c
+++ b/src/joystick/bsd/SDL_sysjoystick.c
@@ -82,7 +82,9 @@
#define MAX_JOYS (MAX_UHID_JOYS + MAX_JOY_JOYS)
struct report {
-#if defined(__FREEBSD__) && (__FreeBSD_kernel_version > 800063)
+#if defined(__FREEBSD__) && (__FreeBSD_kernel_version > 900000)
+ void *buf; /* Buffer */
+#elif defined(__FREEBSD__) && (__FreeBSD_kernel_version > 800063)
struct usb_gen_descriptor *buf; /* Buffer */
#else
struct usb_ctl_report *buf; /* Buffer */
@@ -148,8 +150,10 @@ static char *joydevnames[MAX_JOYS];
static int report_alloc(struct report *, struct report_desc *, int);
static void report_free(struct report *);
-#if defined(USBHID_UCR_DATA)
+#if defined(USBHID_UCR_DATA) || (defined(__FreeBSD_kernel__) && __FreeBSD_kernel_version <= 800063)
#define REP_BUF_DATA(rep) ((rep)->buf->ucr_data)
+#elif (defined(__FREEBSD__) && (__FreeBSD_kernel_version > 900000))
+#define REP_BUF_DATA(rep) ((rep)->buf)
#elif (defined(__FREEBSD__) && (__FreeBSD_kernel_version > 800063))
#define REP_BUF_DATA(rep) ((rep)->buf->ugd_data)
#else
@@ -582,8 +586,12 @@ report_alloc(struct report *r, struct report_desc *rd, int repind)
r->size = len;
if (r->size > 0) {
+#if defined(__FREEBSD__) && (__FreeBSD_kernel_version > 900000)
+ r->buf = SDL_malloc(r->size);
+#else
r->buf = SDL_malloc(sizeof(*r->buf) - sizeof(REP_BUF_DATA(r)) +
r->size);
+#endif
if (r->buf == NULL) {
SDL_OutOfMemory();
return (-1);