Commit 53ce4d4a authored by Gustavo A. R. Silva's avatar Gustavo A. R. Silva Committed by Greg Kroah-Hartman

iio: multiplexer: add NULL check on devm_kzalloc() and devm_kmemdup() return values

[ Upstream commit dd92d5ea ]

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

Fixes: 7ba9df54 ("iio: multiplexer: new iio category and iio-mux driver")
Signed-off-by: default avatarGustavo A. R. Silva <>
Acked-by: default avatarPeter Rosin <>
Signed-off-by: default avatarJonathan Cameron <>
Signed-off-by: default avatarSasha Levin <>
Signed-off-by: default avatarGreg Kroah-Hartman <>
parent 68744edd
......@@ -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,
if (!child->ext_info_cache[i].data)
return -ENOMEM;
child->ext_info_cache[i].data[ret] = 0;
child->ext_info_cache[i].size = ret;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment