Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1682909
| From | "Gustavo A. R. Silva" <garsilva@embeddedor.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH] iio: multiplexer: add NULL check on devm_kzalloc() and devm_kmemdup() return values |
| Date | 2017-07-07 07:00 +0200 |
| Message-ID | <u0twZ-7l9-3@gated-at.bofh.it> (permalink) |
| References | <u0twZ-7l9-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
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
Cc: Peter Rosin <peda@axentia.se>
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
Changes in v2:
Add NULL check on devm_kmemup() return value.
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 37ba007..74831fc 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.5.0
Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread
[PATCH] iio: multiplexer: add NULL check on devm_kzalloc() and devm_kmemdup() return values "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-07-07 07:00 +0200
Re: [PATCH] iio: multiplexer: add NULL check on devm_kzalloc() and devm_kmemdup() return values Jonathan Cameron <jic23@kernel.org> - 2017-07-09 19:20 +0200
Re: [PATCH] iio: multiplexer: add NULL check on devm_kzalloc() and devm_kmemdup() return values "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-07-10 21:50 +0200
csiph-web