iio: max9611: fix a NULL pointer dereference
PATCH 1/1 iio: max9611: fix a NULL pointer dereference
of_match_device may return NULL when it fails, and in this case, there will be a NULL pointer dereference. The fix returns EINVAL when of_match_device returns NULL.
--- drivers/iio/adc/max9611.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/iio/adc/max9611.c +5 -2
@@ -524,13 +524,16 @@ static int max9611_probe(struct i2c_client *client, {const char *const shunt_res_prop ="shunt-resistor-micro-ohms" ;const struct device_node *of_node = client->dev.of_node; -const struct of_device_id *of_id = -of_match_device (max9611_of_table, &client->dev); +const struct of_device_id *of_id;struct max9611_dev *max9611;struct iio_dev *indio_dev;unsigned int of_shunt;int ret; + of_id =of_match_device (max9611_of_table, &client->dev); +if (!of_id) +return -EINVAL ; + indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*max9611));if (!indio_dev)return -ENOMEM ;
Signature · 1 line
2.17.1
Quoted 14 lines · Kangjie Lu
of_match_devicemay return NULL when it fails, and in this case, there will be a NULL pointer dereference. The fix returns EINVAL whenof_match_devicereturns NULL.Signed-off-by Kangjie Lu <[email protected]>--- drivers/iio/adc/max9611.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/iio/adc/max9611.c +0
-0
drivers/iio/adc/max9611.c static int max9611_probe(struct i2c_client *client, · line 528
Quoted 5 lines
drivers/iio/adc/max9611.c +0
-2@@ -524,13 +524,16 @@ static int max9611_probe(struct i2c_client *client, {const char *const shunt_res_prop ="shunt-resistor-micro-ohms" ;const struct device_node *of_node = client->dev.of_node; -const struct of_device_id *of_id = -of_match_device (max9611_of_table, &client->dev);
Given we got to this point how this can go wrong?
Quoted 16 lines
drivers/iio/adc/max9611.c +5
-1+const struct of_device_id *of_id;struct max9611_dev *max9611;struct iio_dev *indio_dev;unsigned int of_shunt;int ret; + of_id =of_match_device (max9611_of_table, &client->dev); +if (!of_id) +return -EINVAL ; + indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*max9611));if (!indio_dev)return -ENOMEM ; --2.17.1
Jonathan Cameron
maintainerQuoted 10 lines · On Sat, 9 Mar 2019 16:19:17 +0100 Tomasz Duszynski <[email protected]> wrote:
Quoted 9 lines · Kangjie Lu
of_match_devicemay return NULL when it fails, and in this case, there will be a NULL pointer dereference. The fix returns EINVAL whenof_match_devicereturns NULL.Signed-off-by Kangjie Lu <[email protected]>--- drivers/iio/adc/max9611.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
Quoted 12 lines
drivers/iio/adc/max9611.c static int max9611_probe(struct i2c_client *client, · line 528
Quoted 10 lines
drivers/iio/adc/max9611.c +0
-2@@ -524,13 +524,16 @@ static int max9611_probe(struct i2c_client *client, {const char *const shunt_res_prop ="shunt-resistor-micro-ohms" ;const struct device_node *of_node = client->dev.of_node; -const struct of_device_id *of_id = -of_match_device (max9611_of_table, &client->dev);Given we got to this point how this can go wrong?
If this is to squash a warning then there may be some argument even though it can't actually fail. If there is such a warning please put it in the patch description.
Thanks,
Jonathan
Quoted 17 lines
Quoted 17 lines
drivers/iio/adc/max9611.c +5
-1+const struct of_device_id *of_id;struct max9611_dev *max9611;struct iio_dev *indio_dev;unsigned int of_shunt;int ret; + of_id =of_match_device (max9611_of_table, &client->dev); +if (!of_id) +return -EINVAL ; + indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*max9611));if (!indio_dev)return -ENOMEM ; --2.17.1