From: Max Staudt <max@enpas.org>
To: Roderick Colenbrander <roderick.colenbrander@sony.com>,
Jiri Kosina <jikos@kernel.org>,
Benjamin Tissoires <benjamin.tissoires@redhat.com>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, max@enpas.org
Subject: [PATCH v1 4/7] HID: playstation: DS4: Don't fail on calibration data request
Date: Mon, 15 Jan 2024 23:45:35 +0900 [thread overview]
Message-ID: <20240115144538.12018-5-max@enpas.org> (raw)
In-Reply-To: <20240115144538.12018-1-max@enpas.org>
Some third-party controllers can't report calibration data for the
gyro/accelerometer.
We can still use the gamepad as-is, so let's do that.
Signed-off-by: Max Staudt <max@enpas.org>
---
drivers/hid/hid-playstation.c | 28 +++++++++++++++++-----------
1 file changed, 17 insertions(+), 11 deletions(-)
diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
index 12321cae4416..2bf44bd3cc8a 100644
--- a/drivers/hid/hid-playstation.c
+++ b/drivers/hid/hid-playstation.c
@@ -1778,8 +1778,10 @@ static int dualshock4_get_calibration_data(struct dualshock4 *ds4)
int retries;
buf = kzalloc(DS4_FEATURE_REPORT_CALIBRATION_SIZE, GFP_KERNEL);
- if (!buf)
- return -ENOMEM;
+ if (!buf) {
+ ret = -ENOMEM;
+ goto no_buffer_tail_check;
+ }
/* We should normally receive the feature report data we asked
* for, but hidraw applications such as Steam can issue feature
@@ -1798,24 +1800,25 @@ static int dualshock4_get_calibration_data(struct dualshock4 *ds4)
hid_err(hdev, "Failed to retrieve DualShock4 calibration info: %d\n", ret);
ret = -EILSEQ;
- goto err_free;
} else {
break;
}
}
} else { /* Bluetooth */
buf = kzalloc(DS4_FEATURE_REPORT_CALIBRATION_BT_SIZE, GFP_KERNEL);
- if (!buf)
- return -ENOMEM;
+ if (!buf) {
+ ret = -ENOMEM;
+ goto no_buffer_tail_check;
+ }
ret = ps_get_report(hdev, DS4_FEATURE_REPORT_CALIBRATION_BT, buf,
DS4_FEATURE_REPORT_CALIBRATION_BT_SIZE, true);
- if (ret) {
+
+ if (ret)
hid_err(hdev, "Failed to retrieve DualShock4 calibration info: %d\n", ret);
- goto err_free;
- }
}
+ /* Parse buffer. If the transfer failed, this safely copies zeroes. */
gyro_pitch_bias = get_unaligned_le16(&buf[1]);
gyro_yaw_bias = get_unaligned_le16(&buf[3]);
gyro_roll_bias = get_unaligned_le16(&buf[5]);
@@ -1867,6 +1870,11 @@ static int dualshock4_get_calibration_data(struct dualshock4 *ds4)
ds4->gyro_calib_data[2].sens_denom = abs(gyro_roll_plus - gyro_roll_bias) +
abs(gyro_roll_minus - gyro_roll_bias);
+ /* Done parsing the buffer, so let's free it. */
+ kfree(buf);
+
+no_buffer_tail_check:
+
/*
* Sanity check gyro calibration data. This is needed to prevent crashes
* during report handling of virtual, clone or broken devices not implementing
@@ -1919,8 +1927,6 @@ static int dualshock4_get_calibration_data(struct dualshock4 *ds4)
}
}
-err_free:
- kfree(buf);
return ret;
}
@@ -2571,7 +2577,7 @@ static struct ps_device *dualshock4_create(struct hid_device *hdev)
ret = dualshock4_get_calibration_data(ds4);
if (ret) {
hid_err(hdev, "Failed to get calibration data from DualShock4\n");
- goto err;
+ hid_err(hdev, "Gyroscope and accelerometer will be inaccurate.\n");
}
ds4->gamepad = ps_gamepad_create(hdev, dualshock4_play_effect);
--
2.39.2
next prev parent reply other threads:[~2024-01-15 14:48 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-15 14:45 [PATCH v1 0/7] HID: playstation: DS4: LED bugfix, third-party gamepad support Max Staudt
2024-01-15 14:45 ` [PATCH v1 1/7] HID: playstation: DS4: Fix LED blinking Max Staudt
2024-01-15 14:45 ` [PATCH v1 2/7] HID: playstation: DS4: Don't fail on MAC address request Max Staudt
2024-01-25 0:39 ` Roderick Colenbrander
2024-01-27 8:51 ` Max Staudt
2024-01-30 20:59 ` Roderick Colenbrander
2024-01-31 15:05 ` Max Staudt
2024-01-15 14:45 ` [PATCH v1 3/7] HID: playstation: DS4: Don't fail on FW/HW version request Max Staudt
2024-01-25 0:43 ` Roderick Colenbrander
2024-01-27 8:56 ` Max Staudt
2024-01-15 14:45 ` Max Staudt [this message]
2024-01-15 14:45 ` [PATCH v1 5/7] HID: playstation: DS4: Parse minimal report 0x01 Max Staudt
2024-01-25 0:54 ` Roderick Colenbrander
2024-01-27 9:00 ` Max Staudt
2024-01-15 14:45 ` [PATCH v1 6/7] HID: playstation: Simplify device type ID Max Staudt
2024-01-25 1:01 ` Roderick Colenbrander
2024-01-15 14:45 ` [PATCH v1 7/7] HID: playstation: DS4: Add VID/PID for SZ-MYPOWER controllers Max Staudt
2024-01-25 1:03 ` Roderick Colenbrander
2024-01-27 11:16 ` Max Staudt
2024-01-30 21:07 ` Roderick Colenbrander
2024-01-31 14:48 ` Max Staudt
2024-01-31 16:34 ` Roderick Colenbrander
2024-02-01 15:56 ` Max Staudt
2024-01-23 9:47 ` [PATCH v1 0/7] HID: playstation: DS4: LED bugfix, third-party gamepad support Jiri Kosina
2024-01-24 22:24 ` Roderick Colenbrander
2024-01-27 11:52 ` Max Staudt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240115144538.12018-5-max@enpas.org \
--to=max@enpas.org \
--cc=benjamin.tissoires@redhat.com \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=roderick.colenbrander@sony.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome