Skip to contentSkip to conversation

soc: qcom: geni: Fix NULL pointer dereference

PATCH Superseded Akash Asthana 3 participants 4 messages Jul 17, 2020 – Jul 20, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 soc: qcom: geni: Fix NULL pointer dereference

pdev struct doesn't exits for the devices whose status are disabled from DT node, in such cases NULL is returned from 'of_find_device_by_node' Later when we try to get drvdata from pdev struct NULL pointer dereference is triggered.

Add a NULL check for return values to fix the issue.

We were hitting this issue when one of QUP is disabled.

Fixes 048eb908a1f2 ("soc: qcom-geni-se: Add interconnect support to fix earlycon crash")
---
 drivers/soc/qcom/qcom-geni-se.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/soc/qcom/qcom-geni-se.c +7 -1
index 355d503..6e5fe65 100644
@@ -820,6 +820,7 @@ void geni_remove_earlycon_icc_vote(void)
 	struct geni_wrapper *wrapper;
 	struct device_node *parent;
 	struct device_node *child;
+	struct platform_device *wrapper_pdev;
 
 	if (!earlycon_wrapper)
 		return;
@@ -829,7 +830,12 @@ void geni_remove_earlycon_icc_vote(void)
 	for_each_child_of_node(parent, child) {
 		if (!of_device_is_compatible(child, "qcom,geni-se-qup"))
 			continue;
-		wrapper = platform_get_drvdata(of_find_device_by_node(child));
+
+		wrapper_pdev = of_find_device_by_node(child);
+		if (!wrapper_pdev)
+			continue;
+
+		wrapper = platform_get_drvdata(wrapper_pdev);
 		icc_put(wrapper->to_core.path);
 		wrapper->to_core.path = NULL;
 
Signature · 1 line
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,\na Linux Foundation Collaborative Project
Reviewed-by on v1 1/1
#1 lore raw

Please make sure to cc the linux-arm-msm@vger list for patches of Qualcomm code.

Quoted 1 line · Akash Asthana

pdev struct doesn't exits for the devices whose status are disabled

s/exits/exist/

Quoted 20 lines

from DT node, in such cases NULL is returned from 'of_find_device_by_node' Later when we try to get drvdata from pdev struct NULL pointer dereference is triggered.

Add a NULL check for return values to fix the issue.

We were hitting this issue when one of QUP is disabled.

Fixes 048eb908a1f2 ("soc: qcom-geni-se: Add interconnect support to fix earlycon crash")
---
 drivers/soc/qcom/qcom-geni-se.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/soc/qcom/qcom-geni-se.c +0 -0
index 355d503..6e5fe65 100644

drivers/soc/qcom/qcom-geni-se.c void geni_remove_earlycon_icc_vote(void) · line 823

Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c +1 -0
@@ -820,6 +820,7 @@ void geni_remove_earlycon_icc_vote(void)
 	struct geni_wrapper *wrapper;
 	struct device_node *parent;
 	struct device_node *child;
+	struct platform_device *wrapper_pdev;

nit: since there is no other 'pdev' in this function you could just name it 'pdev', which is less clunky. The variable is only used immediately after it is assigned, so it's clear from the context that it refers to the 'wrapper'.

#2 lore raw

Hi Matthias,

Quoted 2 lines · Matthias Kaehlcke

Please make sure to cc the linux-arm-msm@vger list for patches of Qualcomm code.

Sure.

Quoted 3 lines · Akash Asthana
Quoted 1 line

pdev struct doesn't exits for the devices whose status are disabled

s/exits/exist/

ok

Quoted 16 lines
Quoted 16 lines

from DT node, in such cases NULL is returned from 'of_find_device_by_node' Later when we try to get drvdata from pdev struct NULL pointer dereference is triggered.

Add a NULL check for return values to fix the issue.

We were hitting this issue when one of QUP is disabled.

Fixes 048eb908a1f2 ("soc: qcom-geni-se: Add interconnect support to fix earlycon crash")
---
  drivers/soc/qcom/qcom-geni-se.c | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)
Quoted 13 lines

drivers/soc/qcom/qcom-geni-se.c void geni_remove_earlycon_icc_vote(void) · line 823

Quoted 9 lines
drivers/soc/qcom/qcom-geni-se.c +1 -0
index 355d503..6e5fe65 100644
@@ -820,6 +820,7 @@ void geni_remove_earlycon_icc_vote(void)
  	struct geni_wrapper *wrapper;
  	struct device_node *parent;
  	struct device_node *child;
+	struct platform_device *wrapper_pdev;

nit: since there is no other 'pdev' in this function you could just name it 'pdev', which is less clunky. The variable is only used immediately after it is assigned, so it's clear from the context that it refers to the 'wrapper'.

ok

Thankyou for review!.

regards,

Akash

Quoted 2 lines
Signature · 1 line
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,\na Linux Foundation Collaborative Project
Reviewed-by Tested-by on v1 1/1
#3 lore raw
In reply to Akash Asthana
Quoted 5 lines · Akash Asthana

pdev struct doesn't exits for the devices whose status are disabled from DT node, in such cases NULL is returned from 'of_find_device_by_node' Later when we try to get drvdata from pdev struct NULL pointer dereference is triggered.

Quoted 7 lines

Add a NULL check for return values to fix the issue.

We were hitting this issue when one of QUP is disabled.

Fixes 048eb908a1f2 ("soc: qcom-geni-se: Add interconnect support to fix earlycon crash")

And applied with Matthias suggested rename of wrapper_pdev to pdev.

PS. Please include [email protected] among your recipients for future patches.

Regards,
Bjorn

Quoted 33 lines
---
 drivers/soc/qcom/qcom-geni-se.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/soc/qcom/qcom-geni-se.c +7 -1
index 355d503..6e5fe65 100644
@@ -820,6 +820,7 @@ void geni_remove_earlycon_icc_vote(void)
 	struct geni_wrapper *wrapper;
 	struct device_node *parent;
 	struct device_node *child;
+	struct platform_device *wrapper_pdev;
 
 	if (!earlycon_wrapper)
 		return;
@@ -829,7 +830,12 @@ void geni_remove_earlycon_icc_vote(void)
 	for_each_child_of_node(parent, child) {
 		if (!of_device_is_compatible(child, "qcom,geni-se-qup"))
 			continue;
-		wrapper = platform_get_drvdata(of_find_device_by_node(child));
+
+		wrapper_pdev = of_find_device_by_node(child);
+		if (!wrapper_pdev)
+			continue;
+
+		wrapper = platform_get_drvdata(wrapper_pdev);
 		icc_put(wrapper->to_core.path);
 		wrapper->to_core.path = NULL;
 
Signature · 1 line
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,\na Linux Foundation Collaborative Project