public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] regulator: vctrl: Fix out of bounds array access for vctrl->vtable
@ 2017-04-14  2:50 Axel Lin
  2017-04-14 17:11 ` Matthias Kaehlcke
  2017-04-14 17:12 ` Applied "regulator: vctrl: Fix out of bounds array access for vctrl->vtable" to the regulator tree Mark Brown
  0 siblings, 2 replies; 4+ messages in thread
From: Axel Lin @ 2017-04-14  2:50 UTC (permalink / raw)
  To: Mark Brown
  Cc: Matthias Kaehlcke, Rob Herring, Liam Girdwood, linux-kernel,
	Axel Lin

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: Axel Lin <axel.lin@ingics.com>
---
 drivers/regulator/vctrl-regulator.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/regulator/vctrl-regulator.c b/drivers/regulator/vctrl-regulator.c
index 6baadef..78de002 100644
--- a/drivers/regulator/vctrl-regulator.c
+++ b/drivers/regulator/vctrl-regulator.c
@@ -345,9 +345,9 @@ static int vctrl_init_vtable(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	vctrl->vtable = devm_kmalloc_array(
-		&pdev->dev, sizeof(struct vctrl_voltage_table),
-		rdesc->n_voltages, GFP_KERNEL | __GFP_ZERO);
+	vctrl->vtable = devm_kcalloc(&pdev->dev, rdesc->n_voltages,
+				     sizeof(struct vctrl_voltage_table),
+				     GFP_KERNEL);
 	if (!vctrl->vtable)
 		return -ENOMEM;
 
@@ -371,7 +371,7 @@ static int vctrl_init_vtable(struct platform_device *pdev)
 	     NULL);
 
 	/* 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 ovp_min_uV = (vctrl->vtable[i].out *
 				  (100 - vctrl->ovp_threshold)) / 100;
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-04-14 19:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-14  2:50 [PATCH] regulator: vctrl: Fix out of bounds array access for vctrl->vtable Axel Lin
2017-04-14 17:11 ` Matthias Kaehlcke
2017-04-14 19:01   ` Matthias Kaehlcke
2017-04-14 17:12 ` Applied "regulator: vctrl: Fix out of bounds array access for vctrl->vtable" to the regulator tree Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox