提交 a9bbb453 编写于 作者: A Axel Lin 提交者: Mark Brown

regulator: vctrl: Fix out of bounds array access for vctrl->vtable

Current code only allocates rdesc->n_voltages entries for vctrl->vtable.
Thus use rdesc->n_voltages instead of n_voltages in the for loop.

While at it, also switch to use devm_kcalloc instead of devm_kmalloc_array
+ __GFP_ZERO flag and fix the argument order.
Signed-off-by: NAxel Lin <axel.lin@ingics.com>
Signed-off-by: NMark Brown <broonie@kernel.org>
上级 9dee7a72
...@@ -345,9 +345,9 @@ static int vctrl_init_vtable(struct platform_device *pdev) ...@@ -345,9 +345,9 @@ static int vctrl_init_vtable(struct platform_device *pdev)
return -EINVAL; return -EINVAL;
} }
vctrl->vtable = devm_kmalloc_array( vctrl->vtable = devm_kcalloc(&pdev->dev, rdesc->n_voltages,
&pdev->dev, sizeof(struct vctrl_voltage_table), sizeof(struct vctrl_voltage_table),
rdesc->n_voltages, GFP_KERNEL | __GFP_ZERO); GFP_KERNEL);
if (!vctrl->vtable) if (!vctrl->vtable)
return -ENOMEM; return -ENOMEM;
...@@ -371,7 +371,7 @@ static int vctrl_init_vtable(struct platform_device *pdev) ...@@ -371,7 +371,7 @@ static int vctrl_init_vtable(struct platform_device *pdev)
NULL); NULL);
/* pre-calculate OVP-safe downward transitions */ /* pre-calculate OVP-safe downward transitions */
for (i = n_voltages - 1; i > 0; i--) { for (i = rdesc->n_voltages - 1; i > 0; i--) {
int j; int j;
int ovp_min_uV = (vctrl->vtable[i].out * int ovp_min_uV = (vctrl->vtable[i].out *
(100 - vctrl->ovp_threshold)) / 100; (100 - vctrl->ovp_threshold)) / 100;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册