Skip to contentSkip to conversation

iio: adc: rockchip_saradc: add NULL check on of_match_device() return value

PATCH Applied Gustavo A. R. Silva 2 participants 3 messages Jul 7, 2017 – Jul 17, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: adc: rockchip_saradc: add NULL check on of_match_device() return value

Check return value from call to of_match_device()
in order to prevent a NULL pointer dereference.

In case of NULL print error message and return -ENODEV

---
 drivers/iio/adc/rockchip_saradc.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/iio/adc/rockchip_saradc.c +5 -0
index ae6d332..2bf2ed1 100644
@@ -224,6 +224,11 @@ static int rockchip_saradc_probe(struct platform_device *pdev)
 	info = iio_priv(indio_dev);
 
 	match = of_match_device(rockchip_saradc_match, &pdev->dev);
+	if (!match) {
+		dev_err(&pdev->dev, "failed to match device\n");
+		return -ENODEV;
+	}
+
 	info->data = match->data;
 
 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Signature · 1 line
2.5.0
maintainer Applied
#1 lore raw
Quoted 6 lines · On Fri, 7 Jul 2017 01:51:31 -0500 "Gustavo A. R. Silva"…

Check return value from call to of_match_device()
in order to prevent a NULL pointer dereference.

In case of NULL print error message and return -ENODEV

Applied.

Thanks,

Jonathan

Quoted 20 lines
---
 drivers/iio/adc/rockchip_saradc.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/iio/adc/rockchip_saradc.c +5 -0
index ae6d332..2bf2ed1 100644
@@ -224,6 +224,11 @@ static int rockchip_saradc_probe(struct platform_device *pdev)
 	info = iio_priv(indio_dev);
 
 	match = of_match_device(rockchip_saradc_match, &pdev->dev);
+	if (!match) {
+		dev_err(&pdev->dev, "failed to match device\n");
+		return -ENODEV;
+	}
+
 	info->data = match->data;
 
 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
#2 lore raw
Quoted 11 lines · Jonathan Cameron
Quoted 6 lines · On Fri, 7 Jul 2017 01:51:31 -0500 "Gustavo A. R. Silva"…

Check return value from call to of_match_device()
in order to prevent a NULL pointer dereference.

In case of NULL print error message and return -ENODEV

Applied.

Thank you, Jonathan.

Signature · 1 line
Gustavo A. R. Silva