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


Groups > linux.kernel > #1720534 > unrolled thread

[PATCH] iio: multiplexer: check memory allocation failure

Started byChristophe JAILLET <christophe.jaillet@wanadoo.fr>
First post2017-08-26 08:00 +0200
Last post2017-08-26 08:00 +0200
Articles 1 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH] iio: multiplexer: check memory allocation failure Christophe JAILLET <christophe.jaillet@wanadoo.fr> - 2017-08-26 08:00 +0200

#1720534 — [PATCH] iio: multiplexer: check memory allocation failure

FromChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Date2017-08-26 08:00 +0200
Subject[PATCH] iio: multiplexer: check memory allocation failure
Message-ID<uiCit-5Jh-3@gated-at.bofh.it>
Check memory allocation failures and return -ENOMEM in such cases, as
already done few lines above for another memory allocation.

This avoids NULL pointers dereference.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/iio/multiplexer/iio-mux.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/iio/multiplexer/iio-mux.c b/drivers/iio/multiplexer/iio-mux.c
index 37ba007f8dca..74831fcd0313 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;
 
@@ -309,6 +312,9 @@ static int mux_configure_channel(struct device *dev, struct mux *mux,
 
 		child->ext_info_cache[i].data = devm_kmemdup(dev, page, ret + 1,
 							     GFP_KERNEL);
+		if (!child->ext_info_cache[i].data)
+			return -ENOMEM;
+
 		child->ext_info_cache[i].data[ret] = 0;
 		child->ext_info_cache[i].size = ret;
 	}
-- 
2.11.0

[toc] | [standalone]


Back to top | Article view | linux.kernel


csiph-web