diff mbox series

[V2] soc: qcom: geni: Fix NULL pointer dereference

Message ID 1595237762-6776-1-git-send-email-akashast@codeaurora.org (mailing list archive)
State New, archived
Headers show
Series [V2] soc: qcom: geni: Fix NULL pointer dereference | expand

Commit Message

Akash Asthana July 20, 2020, 9:36 a.m. UTC
pdev struct doesn't exists 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")
Reported-by: Sai Prakash Ranjan <saipraka@codeaurora.org>
Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
Signed-off-by: Akash Asthana <akashast@codeaurora.org>
---
Changes in V2:
 - Change variable name 'wrapper_pdev' to 'pdev.

 drivers/soc/qcom/qcom-geni-se.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Sai Prakash Ranjan July 20, 2020, 9:42 a.m. UTC | #1
On 2020-07-20 15:06, Akash Asthana wrote:
> pdev struct doesn't exists 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")
> Reported-by: Sai Prakash Ranjan <saipraka@codeaurora.org>
> Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
> Signed-off-by: Akash Asthana <akashast@codeaurora.org>

Nit: my codeaurora mail address is <saiprakash.ranjan@codeaurora.org>.
I don't think you have to resend for this small change, hopefully 
maintainers
are ok to fix this when applying.

Reported-by: Sai Prakash Ranjan <saiprakash.ranjan@codeaurora.org>
Tested-by: Sai Prakash Ranjan <saiprakash.ranjan@codeaurora.org>

-Sai
diff mbox series

Patch

diff --git a/drivers/soc/qcom/qcom-geni-se.c b/drivers/soc/qcom/qcom-geni-se.c
index 355d503..996f20c 100644
--- a/drivers/soc/qcom/qcom-geni-se.c
+++ b/drivers/soc/qcom/qcom-geni-se.c
@@ -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 *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));
+
+		pdev = of_find_device_by_node(child);
+		if (!pdev)
+			continue;
+
+		wrapper = platform_get_drvdata(pdev);
 		icc_put(wrapper->to_core.path);
 		wrapper->to_core.path = NULL;