@@ -1778,8 +1778,10 @@ static int dualshock4_get_calibration_data(struct dualshock4 *ds4)
1778
1778
int retries ;
1779
1779
1780
1780
buf = kzalloc (DS4_FEATURE_REPORT_CALIBRATION_SIZE , GFP_KERNEL );
1781
- if (!buf )
1782
- return - ENOMEM ;
1781
+ if (!buf ) {
1782
+ ret = - ENOMEM ;
1783
+ goto no_buffer_tail_check ;
1784
+ }
1783
1785
1784
1786
/* We should normally receive the feature report data we asked
1785
1787
* for, but hidraw applications such as Steam can issue feature
@@ -1796,26 +1798,27 @@ static int dualshock4_get_calibration_data(struct dualshock4 *ds4)
1796
1798
continue ;
1797
1799
}
1798
1800
1799
- hid_err (hdev , "Failed to retrieve DualShock4 calibration info: %d\n" , ret );
1801
+ hid_warn (hdev , "Failed to retrieve DualShock4 calibration info: %d\n" , ret );
1800
1802
ret = - EILSEQ ;
1801
- goto err_free ;
1802
1803
} else {
1803
1804
break ;
1804
1805
}
1805
1806
}
1806
1807
} else { /* Bluetooth */
1807
1808
buf = kzalloc (DS4_FEATURE_REPORT_CALIBRATION_BT_SIZE , GFP_KERNEL );
1808
- if (!buf )
1809
- return - ENOMEM ;
1809
+ if (!buf ) {
1810
+ ret = - ENOMEM ;
1811
+ goto no_buffer_tail_check ;
1812
+ }
1810
1813
1811
1814
ret = ps_get_report (hdev , DS4_FEATURE_REPORT_CALIBRATION_BT , buf ,
1812
1815
DS4_FEATURE_REPORT_CALIBRATION_BT_SIZE , true);
1813
- if (ret ) {
1814
- hid_err (hdev , "Failed to retrieve DualShock4 calibration info: %d\n" , ret );
1815
- goto err_free ;
1816
- }
1816
+
1817
+ if (ret )
1818
+ hid_warn (hdev , "Failed to retrieve DualShock4 calibration info: %d\n" , ret );
1817
1819
}
1818
1820
1821
+ /* Parse buffer. If the transfer failed, this safely copies zeroes. */
1819
1822
gyro_pitch_bias = get_unaligned_le16 (& buf [1 ]);
1820
1823
gyro_yaw_bias = get_unaligned_le16 (& buf [3 ]);
1821
1824
gyro_roll_bias = get_unaligned_le16 (& buf [5 ]);
@@ -1867,6 +1870,11 @@ static int dualshock4_get_calibration_data(struct dualshock4 *ds4)
1867
1870
ds4 -> gyro_calib_data [2 ].sens_denom = abs (gyro_roll_plus - gyro_roll_bias ) +
1868
1871
abs (gyro_roll_minus - gyro_roll_bias );
1869
1872
1873
+ /* Done parsing the buffer, so let's free it. */
1874
+ kfree (buf );
1875
+
1876
+ no_buffer_tail_check :
1877
+
1870
1878
/*
1871
1879
* Sanity check gyro calibration data. This is needed to prevent crashes
1872
1880
* during report handling of virtual, clone or broken devices not implementing
@@ -1919,8 +1927,6 @@ static int dualshock4_get_calibration_data(struct dualshock4 *ds4)
1919
1927
}
1920
1928
}
1921
1929
1922
- err_free :
1923
- kfree (buf );
1924
1930
return ret ;
1925
1931
}
1926
1932
@@ -2568,8 +2574,8 @@ static struct ps_device *dualshock4_create(struct hid_device *hdev)
2568
2574
2569
2575
ret = dualshock4_get_calibration_data (ds4 );
2570
2576
if (ret ) {
2571
- hid_err (hdev , "Failed to get calibration data from DualShock4\n" );
2572
- goto err ;
2577
+ hid_warn (hdev , "Failed to get calibration data from DualShock4\n" );
2578
+ hid_warn ( hdev , "Gyroscope and accelerometer will be inaccurate.\n" ) ;
2573
2579
}
2574
2580
2575
2581
ds4 -> gamepad = ps_gamepad_create (hdev , dualshock4_play_effect );
0 commit comments