All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] soc: qcom: geni: Fix NULL pointer dereference
@ 2020-07-17 14:32 Akash Asthana
  2020-07-17 14:48 ` Matthias Kaehlcke
  2020-07-20 20:12 ` Bjorn Andersson
  0 siblings, 2 replies; 4+ messages in thread
From: Akash Asthana @ 2020-07-17 14:32 UTC (permalink / raw)
  To: bjorn.andersson; +Cc: mka, linux-kernel, saipraka, msavaliy, 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.

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>
Signed-off-by: Akash Asthana <akashast@codeaurora.org>
---
 drivers/soc/qcom/qcom-geni-se.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/soc/qcom/qcom-geni-se.c b/drivers/soc/qcom/qcom-geni-se.c
index 355d503..6e5fe65 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 *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;
 
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,\na Linux Foundation Collaborative Project


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] soc: qcom: geni: Fix NULL pointer dereference
  2020-07-17 14:32 [PATCH] soc: qcom: geni: Fix NULL pointer dereference Akash Asthana
@ 2020-07-17 14:48 ` Matthias Kaehlcke
  2020-07-20  9:01   ` Akash Asthana
  2020-07-20 20:12 ` Bjorn Andersson
  1 sibling, 1 reply; 4+ messages in thread
From: Matthias Kaehlcke @ 2020-07-17 14:48 UTC (permalink / raw)
  To: Akash Asthana; +Cc: bjorn.andersson, linux-kernel, saipraka, msavaliy

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

On Fri, Jul 17, 2020 at 08:02:22PM +0530, Akash Asthana wrote:
> pdev struct doesn't exits for the devices whose status are disabled

s/exits/exist/

> 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>
> Signed-off-by: Akash Asthana <akashast@codeaurora.org>
> ---
>  drivers/soc/qcom/qcom-geni-se.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/soc/qcom/qcom-geni-se.c b/drivers/soc/qcom/qcom-geni-se.c
> index 355d503..6e5fe65 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 *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'.

Reviewed-by: Matthias Kaehlcke <mka@chromium.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] soc: qcom: geni: Fix NULL pointer dereference
  2020-07-17 14:48 ` Matthias Kaehlcke
@ 2020-07-20  9:01   ` Akash Asthana
  0 siblings, 0 replies; 4+ messages in thread
From: Akash Asthana @ 2020-07-20  9:01 UTC (permalink / raw)
  To: Matthias Kaehlcke; +Cc: bjorn.andersson, linux-kernel, saipraka, msavaliy

Hi Matthias,

On 7/17/2020 8:18 PM, Matthias Kaehlcke wrote:
> Please make sure to cc the linux-arm-msm@vger list for patches of
> Qualcomm code.
Sure.
> On Fri, Jul 17, 2020 at 08:02:22PM +0530, Akash Asthana wrote:
>> pdev struct doesn't exits for the devices whose status are disabled
> s/exits/exist/
ok
>
>> 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>
>> Signed-off-by: Akash Asthana <akashast@codeaurora.org>
>> ---
>>   drivers/soc/qcom/qcom-geni-se.c | 8 +++++++-
>>   1 file changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/soc/qcom/qcom-geni-se.c b/drivers/soc/qcom/qcom-geni-se.c
>> index 355d503..6e5fe65 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 *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

>
> Reviewed-by: Matthias Kaehlcke <mka@chromium.org>

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,\na Linux Foundation Collaborative Project


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] soc: qcom: geni: Fix NULL pointer dereference
  2020-07-17 14:32 [PATCH] soc: qcom: geni: Fix NULL pointer dereference Akash Asthana
  2020-07-17 14:48 ` Matthias Kaehlcke
@ 2020-07-20 20:12 ` Bjorn Andersson
  1 sibling, 0 replies; 4+ messages in thread
From: Bjorn Andersson @ 2020-07-20 20:12 UTC (permalink / raw)
  To: Akash Asthana; +Cc: mka, linux-kernel, saipraka, msavaliy

On Fri 17 Jul 07:32 PDT 2020, Akash Asthana wrote:

> 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")
> Reported-by: Sai Prakash Ranjan <saipraka@codeaurora.org>
> Signed-off-by: Akash Asthana <akashast@codeaurora.org>

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Tested-by: Bjorn Andersson <bjorn.andersson@linaro.org>

And applied with Matthias suggested rename of wrapper_pdev to pdev.


PS. Please include linux-arm-msm@vger.kernel.org among your recipients
for future patches.

Regards,
Bjorn

> ---
>  drivers/soc/qcom/qcom-geni-se.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/soc/qcom/qcom-geni-se.c b/drivers/soc/qcom/qcom-geni-se.c
> index 355d503..6e5fe65 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 *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;
>  
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,\na Linux Foundation Collaborative Project
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-07-20 20:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-17 14:32 [PATCH] soc: qcom: geni: Fix NULL pointer dereference Akash Asthana
2020-07-17 14:48 ` Matthias Kaehlcke
2020-07-20  9:01   ` Akash Asthana
2020-07-20 20:12 ` Bjorn Andersson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.