linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFT] regulator: lp8788-buck: Silence build warning
@ 2013-01-10  2:33 Axel Lin
  2013-01-10  4:14 ` Fengguang Wu
  2013-01-10 12:57 ` Mark Brown
  0 siblings, 2 replies; 3+ messages in thread
From: Axel Lin @ 2013-01-10  2:33 UTC (permalink / raw)
  To: Mark Brown; +Cc: Fengguang Wu, Milo(Woogyom) Kim, Liam Girdwood, linux-kernel

This driver use id as array index, thus add bounder checking for id.

This patch fixes below build warning:
drivers/regulator/lp8788-buck.c: In function 'lp8788_buck_probe':
drivers/regulator/lp8788-buck.c:490:8: warning: array subscript is above array bounds [-Warray-bounds]
drivers/regulator/lp8788-buck.c:489:63: warning: array subscript is above array bounds [-Warray-bounds]

Reported-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
Hi Fengguang,
My toolchain does not show the warning you mentioned,
can you test if this patch indeed silence the build warning?

Thanks,
Axel
 drivers/regulator/lp8788-buck.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/regulator/lp8788-buck.c b/drivers/regulator/lp8788-buck.c
index 1161949..ef845c7 100644
--- a/drivers/regulator/lp8788-buck.c
+++ b/drivers/regulator/lp8788-buck.c
@@ -474,7 +474,7 @@ static int lp8788_init_dvs(struct platform_device *pdev,
 	u8 default_dvs_mode[] = { LP8788_BUCK1_DVS_I2C, LP8788_BUCK2_DVS_I2C };
 
 	/* no dvs for buck3, 4 */
-	if (id == BUCK3 || id == BUCK4)
+	if (id > BUCK2)
 		return 0;
 
 	/* no dvs platform data, then dvs will be selected by I2C registers */
@@ -505,6 +505,9 @@ static int lp8788_buck_probe(struct platform_device *pdev)
 	struct regulator_dev *rdev;
 	int ret;
 
+	if (id >= LP8788_NUM_BUCKS)
+		return -EINVAL;
+
 	buck = devm_kzalloc(&pdev->dev, sizeof(struct lp8788_buck), GFP_KERNEL);
 	if (!buck)
 		return -ENOMEM;
-- 
1.7.9.5




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

* Re: [PATCH RFT] regulator: lp8788-buck: Silence build warning
  2013-01-10  2:33 [PATCH RFT] regulator: lp8788-buck: Silence build warning Axel Lin
@ 2013-01-10  4:14 ` Fengguang Wu
  2013-01-10 12:57 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Fengguang Wu @ 2013-01-10  4:14 UTC (permalink / raw)
  To: Axel Lin; +Cc: Mark Brown, Milo(Woogyom) Kim, Liam Girdwood, linux-kernel


Thanks for the fix! It works!

Tested-by: Fengguang Wu <fengguang.wu@intel.com> 


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

* Re: [PATCH RFT] regulator: lp8788-buck: Silence build warning
  2013-01-10  2:33 [PATCH RFT] regulator: lp8788-buck: Silence build warning Axel Lin
  2013-01-10  4:14 ` Fengguang Wu
@ 2013-01-10 12:57 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2013-01-10 12:57 UTC (permalink / raw)
  To: Axel Lin; +Cc: Fengguang Wu, Milo(Woogyom) Kim, Liam Girdwood, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 147 bytes --]

On Thu, Jan 10, 2013 at 10:33:06AM +0800, Axel Lin wrote:
> This driver use id as array index, thus add bounder checking for id.

Applied, thanks.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

end of thread, other threads:[~2013-01-10 12:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-10  2:33 [PATCH RFT] regulator: lp8788-buck: Silence build warning Axel Lin
2013-01-10  4:14 ` Fengguang Wu
2013-01-10 12:57 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).