summaryrefslogtreecommitdiffstats
path: root/drivers/iio/multiplexer
diff options
context:
space:
mode:
authorGustavo A. R. Silva <garsilva@embeddedor.com>2017-07-06 23:53:11 -0500
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2017-09-03 18:10:29 +0100
commitdd92d5ea20ef8a42be7aeda08c669c586c730451 (patch)
tree0f5a81bb6c4116cf56d9ae2f09f3008b78a5bb6c /drivers/iio/multiplexer
parent9d2f715d592eb4d0e643f6219f4a160fbd62934d (diff)
downloadlinux-stable-dd92d5ea20ef8a42be7aeda08c669c586c730451.tar.gz
linux-stable-dd92d5ea20ef8a42be7aeda08c669c586c730451.tar.bz2
linux-stable-dd92d5ea20ef8a42be7aeda08c669c586c730451.zip
iio: multiplexer: add NULL check on devm_kzalloc() and devm_kmemdup() return values
Check return values from call to devm_kzalloc() and devm_kmemup() 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 Fixes: 7ba9df54b091 ("iio: multiplexer: new iio category and iio-mux driver") Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com> Acked-by: Peter Rosin <peda@axentia.se> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/iio/multiplexer')
-rw-r--r--drivers/iio/multiplexer/iio-mux.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/drivers/iio/multiplexer/iio-mux.c b/drivers/iio/multiplexer/iio-mux.c
index 92495d309193..60621ccd67e4 100644
--- a/drivers/iio/multiplexer/iio-mux.c
+++ b/drivers/iio/multiplexer/iio-mux.c
@@ -284,6 +284,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;
@@ -308,6 +311,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;
}