Bladeren bron

touch: goodix: fix static code analyze warnings

Fix static code analyze warnings.

Change-Id: Iabfd2a8fc1fee52c463fc16e0db6b9287c3f50bf
Signed-off-by: Yu Wu <[email protected]>
Yu Wu 3 jaren geleden
bovenliggende
commit
a4a18f9bf8
2 gewijzigde bestanden met toevoegingen van 27 en 16 verwijderingen
  1. 10 5
      goodix_berlin_driver/goodix_ts_inspect.c
  2. 17 11
      goodix_berlin_driver/goodix_ts_utils.c

+ 10 - 5
goodix_berlin_driver/goodix_ts_inspect.c

@@ -584,6 +584,10 @@ static int goodix_init_testlimits(struct goodix_ts_test *ts_test)
 		ts_err("limits file [%s] not available", limit_file);
 		return -EINVAL;
 	}
+	if (!firmware) {
+		ts_err("request_firmware failed");
+		return -EINVAL;
+	}
 	if (firmware->size <= 0) {
 		ts_err("request_firmware, limits param length error,len:%zu",
 			firmware->size);
@@ -699,8 +703,7 @@ static int goodix_init_testlimits(struct goodix_ts_test *ts_test)
 
 exit_free:
 	kfree(temp_buf);
-	if (firmware)
-		release_firmware(firmware);
+	release_firmware(firmware);
 	return ret;
 }
 
@@ -1542,7 +1545,7 @@ static void goodix_cache_deltadata(struct goodix_ts_test *ts_test)
 				max_val = MAX(max_val, temp);
 			}
 			/* calcu delta with left node */
-			if (j % tx) {
+			if (j > 0 && j % tx) {
 				temp = ts_test->rawdata[i].data[j - 1];
 				temp = ABS(temp - raw);
 				max_val = MAX(max_val, temp);
@@ -2839,7 +2842,8 @@ static void goodix_put_test_result(struct goodix_ts_test *ts_test,
 
 	/* calculate self_rawdata min avg max value*/
 	if (ts_test->test_params.test_items[GTP_SELFCAP_TEST]) {
-		if (ts_test->self_rawdata.size) {
+		if (ts_test->self_rawdata.size <=
+			sizeof(ts_test->self_rawdata.data) / sizeof(ts_test->self_rawdata.data[0])) {
 			goodix_data_statistics(
 					ts_test->self_rawdata.data,
 					ts_test->self_rawdata.size,
@@ -2856,7 +2860,8 @@ static void goodix_put_test_result(struct goodix_ts_test *ts_test,
 
 	/* calculate self_noisedata min avg max value*/
 	if (ts_test->test_params.test_items[GTP_SELFNOISE_TEST]) {
-		if (ts_test->self_noisedata.size) {
+		if (ts_test->self_noisedata.size <=
+			sizeof(ts_test->self_noisedata.data) / sizeof(ts_test->self_noisedata.data[0])) {
 			goodix_data_statistics(
 					ts_test->self_noisedata.data,
 					ts_test->self_noisedata.size,

+ 17 - 11
goodix_berlin_driver/goodix_ts_utils.c

@@ -70,23 +70,29 @@ int checksum_cmp(const u8 *data, int size, int mode)
 	u32 r_checksum = 0;
 	u32 i;
 
+	if (((mode == CHECKSUM_MODE_U8_LE) && (size < 2)) ||
+		((mode == CHECKSUM_MODE_U16_LE) && (size < 4)))
+		return 1;
+
 	if (mode == CHECKSUM_MODE_U8_LE) {
-		if (size < 2)
-			return 1;
 		for (i = 0; i < size - 2; i++)
 			cal_checksum += data[i];
-
-		r_checksum = data[size - 2] + (data[size - 1] << 8);
+		r_checksum += data[i++];
+		r_checksum += (data[i] << 8);
 		return (cal_checksum & 0xFFFF) == r_checksum ? 0 : 1;
 	}
 
-	if (size < 4)
-		return 1;
-	for (i = 0; i < size - 4; i += 2)
-		cal_checksum += data[i] + (data[i + 1] << 8);
-	r_checksum = data[size - 4] + (data[size - 3] << 8) +
-		(data[size - 2] << 16) + (data[size - 1] << 24);
-	return cal_checksum == r_checksum ? 0 : 1;
+	if (mode == CHECKSUM_MODE_U16_LE) {
+		for (i = 0; i < size - 4; i += 2)
+			cal_checksum += data[i] + (data[i + 1] << 8);
+		r_checksum += data[i++];
+		r_checksum += (data[i++] << 8);
+		r_checksum += (data[i++] << 16);
+		r_checksum += (data[i] << 24);
+		return cal_checksum == r_checksum ? 0 : 1;
+	}
+
+	return 1;
 }
 
 /* return 1 if all data is zero or ff