linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: multiplexer: add NULL check on devm_kzalloc() return value
@ 2017-07-06 22:08 Gustavo A. R. Silva
  2017-07-07  4:07 ` Peter Rosin
  0 siblings, 1 reply; 12+ messages in thread
From: Gustavo A. R. Silva @ 2017-07-06 22:08 UTC (permalink / raw)
  To: Peter Rosin, Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler
  Cc: linux-iio, linux-kernel, Gustavo A. R. Silva

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/iio/multiplexer/iio-mux.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/iio/multiplexer/iio-mux.c b/drivers/iio/multiplexer/iio-mux.c
index 37ba007..a8d672b 100644
--- a/drivers/iio/multiplexer/iio-mux.c
+++ b/drivers/iio/multiplexer/iio-mux.c
@@ -285,6 +285,9 @@ static int mux_configure_channel(struct device *dev, struct mux *mux,
 	child->ext_info_cache = devm_kzalloc(dev,
 					     sizeof(*child->ext_info_cache) *
 					     num_ext_info, GFP_KERNEL);
+	if (!child->ext_info_cache)
+		return -ENOMEM;
+
 	for (i = 0; i < num_ext_info; ++i) {
 		child->ext_info_cache[i].size = -1;
 
-- 
2.5.0


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

end of thread, other threads:[~2017-09-03 12:13 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-06 22:08 [PATCH] iio: multiplexer: add NULL check on devm_kzalloc() return value Gustavo A. R. Silva
2017-07-07  4:07 ` Peter Rosin
2017-07-07  4:35   ` Gustavo A. R. Silva
2017-07-07  4:46     ` Peter Rosin
2017-07-07  4:51       ` Gustavo A. R. Silva
2017-07-07  4:53         ` [PATCH] iio: multiplexer: add NULL check on devm_kzalloc() and devm_kmemdup() return values Gustavo A. R. Silva
2017-07-07  4:57           ` Peter Rosin
2017-07-07  9:26             ` Peter Rosin
2017-07-09 17:10               ` Jonathan Cameron
2017-07-10 19:44                 ` Gustavo A. R. Silva
2017-08-26  6:09                 ` Peter Rosin
2017-09-03 12:13                   ` Jonathan Cameron

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).