Jelajahi Sumber

msm: camera: common: Add checking for regulator count

This change adds a checking for regulator count,
since the regulator array has fixed length, so
add a protection to avoid meeting index ouf of
bounds issue.

CRs-Fixed: 3250328
Change-Id: I123ffa993ee7b1deb06e3789fa4add6ca5ce6b9f
Signed-off-by: Depeng Shao <[email protected]>
Depeng Shao 2 tahun lalu
induk
melakukan
8f0ed15532
1 mengubah file dengan 13 tambahan dan 0 penghapusan
  1. 13 0
      drivers/cam_utils/cam_soc_util.c

+ 13 - 0
drivers/cam_utils/cam_soc_util.c

@@ -1938,6 +1938,12 @@ static int cam_soc_util_get_dt_regulator_info
 		return 0;
 	}
 
+	if (soc_info->num_rgltr > CAM_SOC_MAX_REGULATOR) {
+		CAM_ERR(CAM_UTIL, "Invalid regulator count:%d",
+			soc_info->num_rgltr);
+		return -EINVAL;
+	}
+
 	for (i = 0; i < soc_info->num_rgltr; i++) {
 		rc = of_property_read_string_index(of_node,
 			"regulator-names", i, &soc_info->rgltr_name[i]);
@@ -2393,6 +2399,13 @@ static int cam_soc_util_regulator_enable_default(
 	int j = 0, rc = 0;
 	uint32_t num_rgltr = soc_info->num_rgltr;
 
+	if (num_rgltr > CAM_SOC_MAX_REGULATOR) {
+		CAM_ERR(CAM_UTIL,
+			"%s has invalid regulator number %d",
+			soc_info->dev_name, num_rgltr);
+		return -EINVAL;
+	}
+
 	for (j = 0; j < num_rgltr; j++) {
 		if (soc_info->rgltr_ctrl_support == true) {
 			rc = cam_soc_util_regulator_enable(soc_info->rgltr[j],