mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-27 04:47:05 +00:00
hid-for-linus-2023121901
-----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIVAwUAZYDb9KZi849r7WBJAQKmWQ//aIRZ7AUCanUQNDPI4UhbXtoIl3I6l9KB K1g+fZVQe1dYEmc88EyEoDpsNkM/RtvRYpbldId5URPILw9k1L0iLcRnazrr/Zmr hspSvcMdn3BNaZZm8ZttEUC/D0LaEvbaKZDQzGogkxawPxCHDAJvKr+2RFnr8pAH i6BFY5uoMXKBehAARSaYYoAwo3DNvONmlVT8Hzc59Z5VWSTQ/psxVpZvEAoAlkKV nmZSmSPr4ImeofiqY+RCZUTmWac7CSiQNIvc7AQmr+KXjV7Kqt+/Ufw6C84n+eSy jrhmnf/EC34HQUwndScHaJz2qsteYuptg9PTmzety084rhfOzrNfpVx8sb5H6mic B3icdagb9eapDKWBH9PUWdGdESmHHMQK81cw7heIjJczLl+DDqRq5SxBMxje5pvI GcVZ5HATb8V7CCAiltfiDOhbnkHJmQOSDPmahq7/QvA7Bbcm/h6LxKCAxTVGfwli 6ycT57RuDs8eJtje+HnkF7cJl84IMvc0bsucrdx3bA4ptfRapzsuZoU9405eZcJL CbirsuB0BaXEFHxZM5iST0NGuRqOmpEdkWZGqHKm2DxFLeNYqKbZeR5hFEJzeH9F xoEiEP4juMHbqb0HVGqh8+XBBoIRn7+kcNMbP30cF+foWPKcWiYVsoLkPmSR9lPQ dTJBDiwV3PE= =Z8bG -----END PGP SIGNATURE----- Merge tag 'hid-for-linus-2023121901' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid Pull HID fixes from Jiri Kosina: - fix for division by zero in Nintendo driver when generic joycon is attached, reported and fixed by SteamOS folks (Guilherme G. Piccoli) - GCC-7 build fix (which is a good cleanup anyway) for Nintendo driver (Ryan McClelland) * tag 'hid-for-linus-2023121901' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid: HID: nintendo: Prevent divide-by-zero on code HID: nintendo: fix initializer element is not constant error
This commit is contained in:
commit
3f10e214a9
1 changed files with 42 additions and 29 deletions
|
@ -325,28 +325,28 @@ struct joycon_imu_cal {
|
|||
* All the controller's button values are stored in a u32.
|
||||
* They can be accessed with bitwise ANDs.
|
||||
*/
|
||||
static const u32 JC_BTN_Y = BIT(0);
|
||||
static const u32 JC_BTN_X = BIT(1);
|
||||
static const u32 JC_BTN_B = BIT(2);
|
||||
static const u32 JC_BTN_A = BIT(3);
|
||||
static const u32 JC_BTN_SR_R = BIT(4);
|
||||
static const u32 JC_BTN_SL_R = BIT(5);
|
||||
static const u32 JC_BTN_R = BIT(6);
|
||||
static const u32 JC_BTN_ZR = BIT(7);
|
||||
static const u32 JC_BTN_MINUS = BIT(8);
|
||||
static const u32 JC_BTN_PLUS = BIT(9);
|
||||
static const u32 JC_BTN_RSTICK = BIT(10);
|
||||
static const u32 JC_BTN_LSTICK = BIT(11);
|
||||
static const u32 JC_BTN_HOME = BIT(12);
|
||||
static const u32 JC_BTN_CAP = BIT(13); /* capture button */
|
||||
static const u32 JC_BTN_DOWN = BIT(16);
|
||||
static const u32 JC_BTN_UP = BIT(17);
|
||||
static const u32 JC_BTN_RIGHT = BIT(18);
|
||||
static const u32 JC_BTN_LEFT = BIT(19);
|
||||
static const u32 JC_BTN_SR_L = BIT(20);
|
||||
static const u32 JC_BTN_SL_L = BIT(21);
|
||||
static const u32 JC_BTN_L = BIT(22);
|
||||
static const u32 JC_BTN_ZL = BIT(23);
|
||||
#define JC_BTN_Y BIT(0)
|
||||
#define JC_BTN_X BIT(1)
|
||||
#define JC_BTN_B BIT(2)
|
||||
#define JC_BTN_A BIT(3)
|
||||
#define JC_BTN_SR_R BIT(4)
|
||||
#define JC_BTN_SL_R BIT(5)
|
||||
#define JC_BTN_R BIT(6)
|
||||
#define JC_BTN_ZR BIT(7)
|
||||
#define JC_BTN_MINUS BIT(8)
|
||||
#define JC_BTN_PLUS BIT(9)
|
||||
#define JC_BTN_RSTICK BIT(10)
|
||||
#define JC_BTN_LSTICK BIT(11)
|
||||
#define JC_BTN_HOME BIT(12)
|
||||
#define JC_BTN_CAP BIT(13) /* capture button */
|
||||
#define JC_BTN_DOWN BIT(16)
|
||||
#define JC_BTN_UP BIT(17)
|
||||
#define JC_BTN_RIGHT BIT(18)
|
||||
#define JC_BTN_LEFT BIT(19)
|
||||
#define JC_BTN_SR_L BIT(20)
|
||||
#define JC_BTN_SL_L BIT(21)
|
||||
#define JC_BTN_L BIT(22)
|
||||
#define JC_BTN_ZL BIT(23)
|
||||
|
||||
enum joycon_msg_type {
|
||||
JOYCON_MSG_TYPE_NONE,
|
||||
|
@ -927,14 +927,27 @@ static int joycon_request_calibration(struct joycon_ctlr *ctlr)
|
|||
*/
|
||||
static void joycon_calc_imu_cal_divisors(struct joycon_ctlr *ctlr)
|
||||
{
|
||||
int i;
|
||||
int i, divz = 0;
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
ctlr->imu_cal_accel_divisor[i] = ctlr->accel_cal.scale[i] -
|
||||
ctlr->accel_cal.offset[i];
|
||||
ctlr->imu_cal_gyro_divisor[i] = ctlr->gyro_cal.scale[i] -
|
||||
ctlr->gyro_cal.offset[i];
|
||||
|
||||
if (ctlr->imu_cal_accel_divisor[i] == 0) {
|
||||
ctlr->imu_cal_accel_divisor[i] = 1;
|
||||
divz++;
|
||||
}
|
||||
|
||||
if (ctlr->imu_cal_gyro_divisor[i] == 0) {
|
||||
ctlr->imu_cal_gyro_divisor[i] = 1;
|
||||
divz++;
|
||||
}
|
||||
}
|
||||
|
||||
if (divz)
|
||||
hid_warn(ctlr->hdev, "inaccurate IMU divisors (%d)\n", divz);
|
||||
}
|
||||
|
||||
static const s16 DFLT_ACCEL_OFFSET /*= 0*/;
|
||||
|
@ -1163,16 +1176,16 @@ static void joycon_parse_imu_report(struct joycon_ctlr *ctlr,
|
|||
JC_IMU_SAMPLES_PER_DELTA_AVG) {
|
||||
ctlr->imu_avg_delta_ms = ctlr->imu_delta_samples_sum /
|
||||
ctlr->imu_delta_samples_count;
|
||||
/* don't ever want divide by zero shenanigans */
|
||||
if (ctlr->imu_avg_delta_ms == 0) {
|
||||
ctlr->imu_avg_delta_ms = 1;
|
||||
hid_warn(ctlr->hdev,
|
||||
"calculated avg imu delta of 0\n");
|
||||
}
|
||||
ctlr->imu_delta_samples_count = 0;
|
||||
ctlr->imu_delta_samples_sum = 0;
|
||||
}
|
||||
|
||||
/* don't ever want divide by zero shenanigans */
|
||||
if (ctlr->imu_avg_delta_ms == 0) {
|
||||
ctlr->imu_avg_delta_ms = 1;
|
||||
hid_warn(ctlr->hdev, "calculated avg imu delta of 0\n");
|
||||
}
|
||||
|
||||
/* useful for debugging IMU sample rate */
|
||||
hid_dbg(ctlr->hdev,
|
||||
"imu_report: ms=%u last_ms=%u delta=%u avg_delta=%u\n",
|
||||
|
|
Loading…
Reference in a new issue