@@ -1787,7 +1787,7 @@ static int dualshock4_get_calibration_data(struct dualshock4 *ds4)
1787
1787
buf = kzalloc (DS4_FEATURE_REPORT_CALIBRATION_SIZE , GFP_KERNEL );
1788
1788
if (!buf ) {
1789
1789
ret = - ENOMEM ;
1790
- goto no_buffer_tail_check ;
1790
+ goto transfer_failed ;
1791
1791
}
1792
1792
1793
1793
/* We should normally receive the feature report data we asked
@@ -1807,6 +1807,7 @@ static int dualshock4_get_calibration_data(struct dualshock4 *ds4)
1807
1807
1808
1808
hid_warn (hdev , "Failed to retrieve DualShock4 calibration info: %d\n" , ret );
1809
1809
ret = - EILSEQ ;
1810
+ goto transfer_failed ;
1810
1811
} else {
1811
1812
break ;
1812
1813
}
@@ -1815,17 +1816,19 @@ static int dualshock4_get_calibration_data(struct dualshock4 *ds4)
1815
1816
buf = kzalloc (DS4_FEATURE_REPORT_CALIBRATION_BT_SIZE , GFP_KERNEL );
1816
1817
if (!buf ) {
1817
1818
ret = - ENOMEM ;
1818
- goto no_buffer_tail_check ;
1819
+ goto transfer_failed ;
1819
1820
}
1820
1821
1821
1822
ret = ps_get_report (hdev , DS4_FEATURE_REPORT_CALIBRATION_BT , buf ,
1822
1823
DS4_FEATURE_REPORT_CALIBRATION_BT_SIZE , true);
1823
1824
1824
- if (ret )
1825
+ if (ret ) {
1825
1826
hid_warn (hdev , "Failed to retrieve DualShock4 calibration info: %d\n" , ret );
1827
+ goto transfer_failed ;
1828
+ }
1826
1829
}
1827
1830
1828
- /* Parse buffer. If the transfer failed, this safely copies zeroes . */
1831
+ /* Transfer succeeded - parse the calibration data received . */
1829
1832
gyro_pitch_bias = get_unaligned_le16 (& buf [1 ]);
1830
1833
gyro_yaw_bias = get_unaligned_le16 (& buf [3 ]);
1831
1834
gyro_roll_bias = get_unaligned_le16 (& buf [5 ]);
@@ -1854,6 +1857,9 @@ static int dualshock4_get_calibration_data(struct dualshock4 *ds4)
1854
1857
acc_z_plus = get_unaligned_le16 (& buf [31 ]);
1855
1858
acc_z_minus = get_unaligned_le16 (& buf [33 ]);
1856
1859
1860
+ /* Done parsing the buffer, so let's free it. */
1861
+ kfree (buf );
1862
+
1857
1863
/*
1858
1864
* Set gyroscope calibration and normalization parameters.
1859
1865
* Data values will be normalized to 1/DS4_GYRO_RES_PER_DEG_S degree/s.
@@ -1877,26 +1883,6 @@ static int dualshock4_get_calibration_data(struct dualshock4 *ds4)
1877
1883
ds4 -> gyro_calib_data [2 ].sens_denom = abs (gyro_roll_plus - gyro_roll_bias ) +
1878
1884
abs (gyro_roll_minus - gyro_roll_bias );
1879
1885
1880
- /* Done parsing the buffer, so let's free it. */
1881
- kfree (buf );
1882
-
1883
- no_buffer_tail_check :
1884
-
1885
- /*
1886
- * Sanity check gyro calibration data. This is needed to prevent crashes
1887
- * during report handling of virtual, clone or broken devices not implementing
1888
- * calibration data properly.
1889
- */
1890
- for (i = 0 ; i < ARRAY_SIZE (ds4 -> gyro_calib_data ); i ++ ) {
1891
- if (ds4 -> gyro_calib_data [i ].sens_denom == 0 ) {
1892
- hid_warn (hdev , "Invalid gyro calibration data for axis (%d), disabling calibration." ,
1893
- ds4 -> gyro_calib_data [i ].abs_code );
1894
- ds4 -> gyro_calib_data [i ].bias = 0 ;
1895
- ds4 -> gyro_calib_data [i ].sens_numer = DS4_GYRO_RANGE ;
1896
- ds4 -> gyro_calib_data [i ].sens_denom = S16_MAX ;
1897
- }
1898
- }
1899
-
1900
1886
/*
1901
1887
* Set accelerometer calibration and normalization parameters.
1902
1888
* Data values will be normalized to 1/DS4_ACC_RES_PER_G g.
@@ -1919,13 +1905,31 @@ static int dualshock4_get_calibration_data(struct dualshock4 *ds4)
1919
1905
ds4 -> accel_calib_data [2 ].sens_numer = 2 * DS4_ACC_RES_PER_G ;
1920
1906
ds4 -> accel_calib_data [2 ].sens_denom = range_2g ;
1921
1907
1908
+ transfer_failed :
1909
+ /*
1910
+ * Sanity check gyro calibration data. This is needed to prevent crashes
1911
+ * during report handling of virtual, clone or broken devices not implementing
1912
+ * calibration data properly.
1913
+ */
1914
+ for (i = 0 ; i < ARRAY_SIZE (ds4 -> gyro_calib_data ); i ++ ) {
1915
+ if (ds4 -> gyro_calib_data [i ].sens_denom == 0 ) {
1916
+ ds4 -> gyro_calib_data [i ].abs_code = ABS_RX + i ;
1917
+ hid_warn (hdev , "Invalid gyro calibration data for axis (%d), disabling calibration." ,
1918
+ ds4 -> gyro_calib_data [i ].abs_code );
1919
+ ds4 -> gyro_calib_data [i ].bias = 0 ;
1920
+ ds4 -> gyro_calib_data [i ].sens_numer = DS4_GYRO_RANGE ;
1921
+ ds4 -> gyro_calib_data [i ].sens_denom = S16_MAX ;
1922
+ }
1923
+ }
1924
+
1922
1925
/*
1923
1926
* Sanity check accelerometer calibration data. This is needed to prevent crashes
1924
1927
* during report handling of virtual, clone or broken devices not implementing calibration
1925
1928
* data properly.
1926
1929
*/
1927
1930
for (i = 0 ; i < ARRAY_SIZE (ds4 -> accel_calib_data ); i ++ ) {
1928
1931
if (ds4 -> accel_calib_data [i ].sens_denom == 0 ) {
1932
+ ds4 -> accel_calib_data [i ].abs_code = ABS_X + i ;
1929
1933
hid_warn (hdev , "Invalid accelerometer calibration data for axis (%d), disabling calibration." ,
1930
1934
ds4 -> accel_calib_data [i ].abs_code );
1931
1935
ds4 -> accel_calib_data [i ].bias = 0 ;
0 commit comments