Skip to contentSkip to conversation

fpga: altera-hps2fpga: add NULL check on of_match_device() return value

PATCH In review Gustavo A. R. Silva 3 participants 5 messages Jul 7, 2017 – Jul 17, 2017 FPGA manager framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fpga: altera-hps2fpga: 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/fpga/altera-hps2fpga.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/fpga/altera-hps2fpga.c +5 -0
index 3066b80..ca8212c 100644
@@ -143,6 +143,11 @@ static int alt_fpga_bridge_probe(struct platform_device *pdev)
 	int ret;
 
 	of_id = of_match_device(altera_fpga_of_match, dev);
+	if (!of_id) {
+		dev_err(dev, "failed to match device\n");
+		return -ENODEV;
+	}
+
 	priv = (struct altera_hps2fpga_data *)of_id->data;
 
 	priv->bridge_reset = of_reset_control_get_by_index(dev->of_node, 0);
Signature · 1 line
2.5.0
Acked-by on v1 1/1
#1 lore raw

On Fri, Jul 7, 2017 at 1:22 AM, Gustavo A. R. Silva

Hi Gustavo,

Thanks for the fix!

Alan

Quoted 6 lines · <[email protected]> wrote:

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

Quoted 23 lines
---
 drivers/fpga/altera-hps2fpga.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/fpga/altera-hps2fpga.c +5 -1
index 3066b80..ca8212c 100644
@@ -143,6 +143,11 @@ static int alt_fpga_bridge_probe(struct platform_device *pdev)
        int ret;
 
        of_id = of_match_device(altera_fpga_of_match, dev);
+       if (!of_id) {
+               dev_err(dev, "failed to match device\n");
+               return -ENODEV;
+       }
+
        priv = (struct altera_hps2fpga_data *)of_id->data;
 
        priv->bridge_reset = of_reset_control_get_by_index(dev->of_node, 0);
--

2.5.0

#2 lore raw

Hi Alan,

Quoting Alan Tull <[email protected]>:

Quoted 6 lines

On Fri, Jul 7, 2017 at 1:22 AM, Gustavo A. R. Silva

Hi Gustavo,

Thanks for the fix!

Absolutely, glad to help. :)

Quoted 32 lines

Alan

Quoted 6 lines · <[email protected]> wrote:

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

Quoted 20 lines
---
 drivers/fpga/altera-hps2fpga.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/fpga/altera-hps2fpga.c +5 -0
index 3066b80..ca8212c 100644
@@ -143,6 +143,11 @@ static int alt_fpga_bridge_probe(struct  
 platform_device *pdev)
        int ret;
 
        of_id = of_match_device(altera_fpga_of_match, dev);
+       if (!of_id) {
+               dev_err(dev, "failed to match device\n");
+               return -ENODEV;
+       }
+
        priv = (struct altera_hps2fpga_data *)of_id->data;
 
Quoted 4 lines
Quoted 4 lines
        priv->bridge_reset = of_reset_control_get_by_index(dev->of_node, 0);

--
2.5.0

--
Gustavo A. R. Silva

Reviewed-by on v1 1/1
#3 lore raw
In reply to Gustavo A. R. Silva
Quoted 6 lines · 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

Quoted 23 lines
---
 drivers/fpga/altera-hps2fpga.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/fpga/altera-hps2fpga.c +5 -1
index 3066b80..ca8212c 100644
@@ -143,6 +143,11 @@ static int alt_fpga_bridge_probe(struct platform_device *pdev)
        int ret;
 
        of_id = of_match_device(altera_fpga_of_match, dev);
+       if (!of_id) {
+               dev_err(dev, "failed to match device\n");
+               return -ENODEV;
+       }
+
        priv = (struct altera_hps2fpga_data *)of_id->data;
 
        priv->bridge_reset = of_reset_control_get_by_index(dev->of_node, 0);
--

2.5.0

#4 lore raw
Quoted 9 lines · Moritz Fischer
Quoted 6 lines · 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

Thank you, Moritz.

Quoted 23 lines
Quoted 23 lines
---
 drivers/fpga/altera-hps2fpga.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/fpga/altera-hps2fpga.c +5 -1
index 3066b80..ca8212c 100644
@@ -143,6 +143,11 @@ static int alt_fpga_bridge_probe(struct platform_device *pdev)
        int ret;
 
        of_id = of_match_device(altera_fpga_of_match, dev);
+       if (!of_id) {
+               dev_err(dev, "failed to match device\n");
+               return -ENODEV;
+       }
+
        priv = (struct altera_hps2fpga_data *)of_id->data;
 
        priv->bridge_reset = of_reset_control_get_by_index(dev->of_node, 0);
--

2.5.0

Signature · 1 line
Gustavo A. R. Silva