Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1c6d9e22 authored by David Collins's avatar David Collins
Browse files

regulator: cpr3-regulator: replace kzalloc with kcalloc for arrays



Use kcalloc() and devm_kcalloc() in place of kzalloc() and
devm_kzalloc() for array memory allocations.  kcalloc() performs
a sanity check to ensure that arithmetic overflow does not occur
when calculating the full size of an array.

This issue was found with checkpatch.

Change-Id: I3e65b2b296f1865c7314f3225e48c5df52f39e01
Signed-off-by: default avatarDavid Collins <collinsd@codeaurora.org>
parent cfdf33da
Loading
Loading
Loading
Loading
+14 −15
Original line number Diff line number Diff line
@@ -513,9 +513,9 @@ static int cpr3_msm8996_hmss_calculate_open_loop_voltages(
	int *fuse_volt;
	int *fmax_corner;

	fuse_volt = kzalloc(sizeof(*fuse_volt) * thread->fuse_corner_count,
	fuse_volt = kcalloc(thread->fuse_corner_count, sizeof(*fuse_volt),
				GFP_KERNEL);
	fmax_corner = kzalloc(sizeof(*fmax_corner) * thread->fuse_corner_count,
	fmax_corner = kcalloc(thread->fuse_corner_count, sizeof(*fmax_corner),
				GFP_KERNEL);
	if (!fuse_volt || !fmax_corner) {
		rc = -ENOMEM;
@@ -745,9 +745,8 @@ static int cpr3_hmss_parse_closed_loop_voltage_adjustments(
		return -EINVAL;
	}

	ro_all_scale = kzalloc(sizeof(*ro_all_scale)
				* thread->fuse_corner_count * CPR3_RO_COUNT,
				GFP_KERNEL);
	ro_all_scale = kcalloc(thread->fuse_corner_count * CPR3_RO_COUNT,
				sizeof(*ro_all_scale), GFP_KERNEL);
	if (!ro_all_scale)
		return -ENOMEM;

@@ -889,17 +888,17 @@ static int cpr3_msm8996_hmss_calculate_target_quotients(
	if (fuse->limitation == MSM8996_CPR_LIMITATION_NO_CPR_OR_INTERPOLATION)
		allow_interpolation = false;

	volt_adjust = kzalloc(sizeof(*volt_adjust) * thread->corner_count,
	volt_adjust = kcalloc(thread->corner_count, sizeof(*volt_adjust),
					GFP_KERNEL);
	volt_adjust_fuse = kzalloc(sizeof(*volt_adjust_fuse)
				       * thread->fuse_corner_count, GFP_KERNEL);
	ro_scale = kzalloc(sizeof(*ro_scale) * thread->fuse_corner_count,
	volt_adjust_fuse = kcalloc(thread->fuse_corner_count,
					sizeof(*volt_adjust_fuse), GFP_KERNEL);
	ro_scale = kcalloc(thread->fuse_corner_count, sizeof(*ro_scale),
					GFP_KERNEL);
	fmax_corner = kzalloc(sizeof(*fmax_corner) * thread->fuse_corner_count,
	fmax_corner = kcalloc(thread->fuse_corner_count, sizeof(*fmax_corner),
					GFP_KERNEL);
	quot_low = kzalloc(sizeof(*quot_low) * thread->fuse_corner_count,
	quot_low = kcalloc(thread->fuse_corner_count, sizeof(*quot_low),
					GFP_KERNEL);
	quot_high = kzalloc(sizeof(*quot_high) * thread->fuse_corner_count,
	quot_high = kcalloc(thread->fuse_corner_count, sizeof(*quot_high),
					GFP_KERNEL);
	if (!volt_adjust || !volt_adjust_fuse || !ro_scale ||
	    !fmax_corner || !quot_low || !quot_high) {
@@ -1341,8 +1340,8 @@ static int cpr3_hmss_init_controller(struct cpr3_controller *ctrl)

	ctrl->sensor_count = MSM8996_HMSS_CPR_SENSOR_COUNT;

	ctrl->sensor_owner = devm_kzalloc(ctrl->dev,
		sizeof(*ctrl->sensor_owner) * ctrl->sensor_count, GFP_KERNEL);
	ctrl->sensor_owner = devm_kcalloc(ctrl->dev, ctrl->sensor_count,
		sizeof(*ctrl->sensor_owner), GFP_KERNEL);
	if (!ctrl->sensor_owner)
		return -ENOMEM;

+9 −9
Original line number Diff line number Diff line
@@ -209,7 +209,7 @@ static int cpr3_mmss_parse_corner_data(struct cpr3_thread *thread,
		return rc;
	}

	temp = kzalloc(sizeof(*temp) * thread->corner_count * CPR3_RO_COUNT,
	temp = kcalloc(thread->corner_count * CPR3_RO_COUNT, sizeof(*temp),
			GFP_KERNEL);
	if (!temp)
		return -ENOMEM;
@@ -260,10 +260,10 @@ static int cpr3_mmss_adjust_target_quotients(struct cpr3_thread *thread,
		return -EINVAL;
	}

	volt_adjust = kzalloc(sizeof(*volt_adjust) * thread->corner_count,
	volt_adjust = kcalloc(thread->corner_count, sizeof(*volt_adjust),
				GFP_KERNEL);
	ro_scale = kzalloc(sizeof(*ro_scale) * thread->corner_count
				* CPR3_RO_COUNT, GFP_KERNEL);
	ro_scale = kcalloc(thread->corner_count * CPR3_RO_COUNT,
				sizeof(*ro_scale), GFP_KERNEL);
	if (!volt_adjust || !ro_scale) {
		rc = -ENOMEM;
		goto done;
@@ -347,9 +347,9 @@ static int cpr3_msm8996_mmss_calculate_open_loop_voltages(
	int *fuse_volt;
	int *fmax_corner;

	fuse_volt = kzalloc(sizeof(*fuse_volt) * thread->fuse_corner_count,
	fuse_volt = kcalloc(thread->fuse_corner_count, sizeof(*fuse_volt),
				GFP_KERNEL);
	fmax_corner = kzalloc(sizeof(*fmax_corner) * thread->fuse_corner_count,
	fmax_corner = kcalloc(thread->fuse_corner_count, sizeof(*fmax_corner),
				GFP_KERNEL);
	if (!fuse_volt || !fmax_corner) {
		rc = -ENOMEM;
@@ -565,8 +565,8 @@ static int cpr3_mmss_init_controller(struct cpr3_controller *ctrl)
	 * MMSS only has one thread (0) so the zeroed array does not need
	 * further modification.
	 */
	ctrl->sensor_owner = devm_kzalloc(ctrl->dev,
		sizeof(*ctrl->sensor_owner) * ctrl->sensor_count, GFP_KERNEL);
	ctrl->sensor_owner = devm_kcalloc(ctrl->dev, ctrl->sensor_count,
				sizeof(*ctrl->sensor_owner), GFP_KERNEL);
	if (!ctrl->sensor_owner)
		return -ENOMEM;

+8 −9
Original line number Diff line number Diff line
@@ -88,8 +88,8 @@ int cpr3_allocate_threads(struct cpr3_controller *ctrl, u32 min_thread_id,
		ctrl->thread_count++;
	}

	ctrl->thread = devm_kzalloc(dev,
			sizeof(*ctrl->thread) * ctrl->thread_count, GFP_KERNEL);
	ctrl->thread = devm_kcalloc(dev, ctrl->thread_count,
			sizeof(*ctrl->thread), GFP_KERNEL);
	if (!ctrl->thread)
		return -ENOMEM;

@@ -401,7 +401,7 @@ int cpr3_parse_common_corner_data(struct cpr3_thread *thread, int *corner_sum,

	thread->fuse_combos_supported = max_fuse_combos;

	combo_corners = kzalloc(sizeof(*combo_corners) * max_fuse_combos,
	combo_corners = kcalloc(max_fuse_combos, sizeof(*combo_corners),
				GFP_KERNEL);
	if (!combo_corners)
		return -ENOMEM;
@@ -434,10 +434,9 @@ int cpr3_parse_common_corner_data(struct cpr3_thread *thread, int *corner_sum,

	kfree(combo_corners);

	thread->corner = devm_kzalloc(thread->ctrl->dev,
			sizeof(*thread->corner) * thread->corner_count,
			GFP_KERNEL);
	temp = kzalloc(sizeof(*temp) * thread->corner_count, GFP_KERNEL);
	thread->corner = devm_kcalloc(thread->ctrl->dev, thread->corner_count,
			sizeof(*thread->corner), GFP_KERNEL);
	temp = kcalloc(thread->corner_count, sizeof(*temp), GFP_KERNEL);
	if (!thread->corner || !temp)
		return -ENOMEM;

@@ -819,7 +818,7 @@ int cpr3_adjust_fused_open_loop_voltages(struct cpr3_thread *thread,
		return 0;
	}

	volt_adjust = kzalloc(sizeof(*volt_adjust) * thread->fuse_corner_count,
	volt_adjust = kcalloc(thread->fuse_corner_count, sizeof(*volt_adjust),
				GFP_KERNEL);
	if (!volt_adjust)
		return -ENOMEM;
@@ -871,7 +870,7 @@ int cpr3_adjust_open_loop_voltages(struct cpr3_thread *thread, int corner_sum,
		return 0;
	}

	volt_adjust = kzalloc(sizeof(*volt_adjust) * thread->corner_count,
	volt_adjust = kcalloc(thread->corner_count, sizeof(*volt_adjust),
				GFP_KERNEL);
	if (!volt_adjust)
		return -ENOMEM;