浏览代码

cnss2: Add NULL check for 'cfg_arr' pointer

Add NULL check for 'cfg_arr' pointer before passing to
'of_property_read_string_array' function

Change-Id: Ief30b57145af5842cfd8e9533fcc5d15ab5ea0f1
CRs-Fixed: 3409579
Sai Kumar Kunchala 2 年之前
父节点
当前提交
3b1df6da05
共有 1 个文件被更改,包括 40 次插入27 次删除
  1. 40 27
      cnss2/power.c

+ 40 - 27
cnss2/power.c

@@ -1619,13 +1619,16 @@ void cnss_power_misc_params_init(struct cnss_plat_data *plat_priv)
 		plat_priv->pdc_init_table =
 			kcalloc(plat_priv->pdc_init_table_len,
 				sizeof(char *), GFP_KERNEL);
-		ret =
-		of_property_read_string_array(dev->of_node,
-					      "qcom,pdc_init_table",
-					      plat_priv->pdc_init_table,
-					      plat_priv->pdc_init_table_len);
-		if (ret < 0)
-			cnss_pr_err("Failed to get PDC Init Table\n");
+		if (plat_priv->pdc_init_table) {
+			ret = of_property_read_string_array(dev->of_node,
+							    "qcom,pdc_init_table",
+							    plat_priv->pdc_init_table,
+							    plat_priv->pdc_init_table_len);
+			if (ret < 0)
+				cnss_pr_err("Failed to get PDC Init Table\n");
+		} else {
+			cnss_pr_err("Failed to alloc PDC Init Table mem\n");
+		}
 	} else {
 		cnss_pr_dbg("PDC Init Table not configured\n");
 	}
@@ -1637,13 +1640,16 @@ void cnss_power_misc_params_init(struct cnss_plat_data *plat_priv)
 		plat_priv->vreg_pdc_map =
 			kcalloc(plat_priv->vreg_pdc_map_len,
 				sizeof(char *), GFP_KERNEL);
-		ret =
-		of_property_read_string_array(dev->of_node,
-					      "qcom,vreg_pdc_map",
-					      plat_priv->vreg_pdc_map,
-					      plat_priv->vreg_pdc_map_len);
-		if (ret < 0)
-			cnss_pr_err("Failed to get VReg PDC Mapping\n");
+		if (plat_priv->vreg_pdc_map) {
+			ret = of_property_read_string_array(dev->of_node,
+							    "qcom,vreg_pdc_map",
+							    plat_priv->vreg_pdc_map,
+							    plat_priv->vreg_pdc_map_len);
+			if (ret < 0)
+				cnss_pr_err("Failed to get VReg PDC Mapping\n");
+		} else {
+			cnss_pr_err("Failed to alloc VReg PDC mem\n");
+		}
 	} else {
 		cnss_pr_dbg("VReg PDC Mapping not configured\n");
 	}
@@ -1654,12 +1660,16 @@ void cnss_power_misc_params_init(struct cnss_plat_data *plat_priv)
 	if (plat_priv->pmu_vreg_map_len > 0) {
 		plat_priv->pmu_vreg_map = kcalloc(plat_priv->pmu_vreg_map_len,
 						  sizeof(char *), GFP_KERNEL);
-		ret =
-		of_property_read_string_array(dev->of_node, "qcom,pmu_vreg_map",
-					      plat_priv->pmu_vreg_map,
-					      plat_priv->pmu_vreg_map_len);
-		if (ret < 0)
-			cnss_pr_err("Fail to get PMU VReg Mapping\n");
+		if (plat_priv->pmu_vreg_map) {
+			ret = of_property_read_string_array(dev->of_node,
+							    "qcom,pmu_vreg_map",
+							    plat_priv->pmu_vreg_map,
+							    plat_priv->pmu_vreg_map_len);
+			if (ret < 0)
+				cnss_pr_err("Fail to get PMU VReg Mapping\n");
+		} else {
+			cnss_pr_err("Failed to alloc PMU VReg mem\n");
+		}
 	} else {
 		cnss_pr_dbg("PMU VReg Mapping not configured\n");
 	}
@@ -1684,13 +1694,16 @@ void cnss_power_misc_params_init(struct cnss_plat_data *plat_priv)
 	if (ret > 0) {
 		cfg_arr_size = ret;
 		cfg_arr = kcalloc(cfg_arr_size, sizeof(*cfg_arr), GFP_KERNEL);
-
-		ret = of_property_read_u32_array(plat_priv->plat_dev->dev.of_node,
-						 "qcom,on-chip-pmic-support", cfg_arr,
-						 cfg_arr_size);
-		if (!ret) {
-			plat_priv->on_chip_pmic_devices_count = cfg_arr_size;
-			plat_priv->on_chip_pmic_board_ids = cfg_arr;
+		if (cfg_arr) {
+			ret = of_property_read_u32_array(plat_priv->plat_dev->dev.of_node,
+							 "qcom,on-chip-pmic-support",
+							 cfg_arr, cfg_arr_size);
+			if (!ret) {
+				plat_priv->on_chip_pmic_devices_count = cfg_arr_size;
+				plat_priv->on_chip_pmic_board_ids = cfg_arr;
+			}
+		} else {
+			cnss_pr_err("Failed to alloc cfg table mem\n");
 		}
 	} else {
 		cnss_pr_dbg("On chip PMIC device ids not configured\n");