Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1682718

[PATCH] regulator: axp20x: add NULL check on devm_kzalloc() return value

From "Gustavo A. R. Silva" <garsilva@embeddedor.com>
Newsgroups linux.kernel
Subject [PATCH] regulator: axp20x: add NULL check on devm_kzalloc() return value
Date 2017-07-06 23:30 +0200
Message-ID <u0mvv-2IA-1@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


Check return value from call to devm_kzalloc()
in order to prevent a NULL pointer dereference.

This issue was detected using Coccinelle and the following semantic patch:

@@
expression x;
identifier fld;
@@

* x = devm_kzalloc(...);
  ... when != x == NULL
  x->fld

Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
 drivers/regulator/axp20x-regulator.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/regulator/axp20x-regulator.c b/drivers/regulator/axp20x-regulator.c
index e2608fe..770227b 100644
--- a/drivers/regulator/axp20x-regulator.c
+++ b/drivers/regulator/axp20x-regulator.c
@@ -691,6 +691,9 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
 		    (regulators == axp809_regulators && i == AXP809_DC1SW)) {
 			new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc),
 						GFP_KERNEL);
+			if (!new_desc)
+				return -ENOMEM;
+
 			*new_desc = regulators[i];
 			new_desc->supply_name = dcdc1_name;
 			desc = new_desc;
-- 
2.5.0

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH] regulator: axp20x: add NULL check on devm_kzalloc() return  value "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-07-06 23:30 +0200
  [PATCH v2] regulator: axp20x: add NULL check on devm_kzalloc()  return value "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-07-07 00:00 +0200

csiph-web