linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PM: opp: Fix NULL pointer exception on a v2 table combined with v1 opps
@ 2022-04-01 12:03 Krzysztof Kozlowski
  2022-04-04  6:26 ` Viresh Kumar
  0 siblings, 1 reply; 4+ messages in thread
From: Krzysztof Kozlowski @ 2022-04-01 12:03 UTC (permalink / raw)
  To: Viresh Kumar, Nishanth Menon, Stephen Boyd, Dmitry Osipenko,
	linux-pm, linux-kernel
  Cc: Krzysztof Kozlowski

dev_pm_opp_add() adds a v1 OPP.  If the Devicetree contains an OPP v2
table with required-opps, but the driver uses dev_pm_opp_add(), the
table might have required_opp_count!=0 but the opp->required_opps will
be NULL.  This leads to NULL pointer exception, e.g. with ufs-qcom.c
driver and v2 OPP table in DTS:

  Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000
  ...
  Call trace:
   _required_opps_available+0x20/0x80
   _opp_add_v1+0xa8/0x110
   dev_pm_opp_add+0x54/0xcc
   ufshcd_async_scan+0x190/0x31c
   async_run_entry_fn+0x38/0x144

Fixes: cf65948d62c6 ("opp: Filter out OPPs based on availability of a required-OPP")
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/opp/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index 740407252298..d21b7e7e3f9f 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -1760,7 +1760,9 @@ int _opp_add(struct device *dev, struct dev_pm_opp *new_opp,
 	if (lazy_linking_pending(opp_table))
 		return 0;
 
-	_required_opps_available(new_opp, opp_table->required_opp_count);
+	/* No required_opps for v1 bindings OPP */
+	if (new_opp->required_opps)
+		_required_opps_available(new_opp, opp_table->required_opp_count);
 
 	return 0;
 }
-- 
2.32.0


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

* Re: [PATCH] PM: opp: Fix NULL pointer exception on a v2 table combined with v1 opps
  2022-04-01 12:03 [PATCH] PM: opp: Fix NULL pointer exception on a v2 table combined with v1 opps Krzysztof Kozlowski
@ 2022-04-04  6:26 ` Viresh Kumar
  2022-04-04  6:28   ` Krzysztof Kozlowski
  0 siblings, 1 reply; 4+ messages in thread
From: Viresh Kumar @ 2022-04-04  6:26 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Viresh Kumar, Nishanth Menon, Stephen Boyd, Dmitry Osipenko,
	linux-pm, linux-kernel

On 01-04-22, 14:03, Krzysztof Kozlowski wrote:
> dev_pm_opp_add() adds a v1 OPP.  If the Devicetree contains an OPP v2
> table with required-opps, but the driver uses dev_pm_opp_add(), the
> table might have required_opp_count!=0 but the opp->required_opps will
> be NULL.

This use-case isn't supported currently, as either all OPPs should
have required-opp or none. This kind of scenario may end up breaking
at other places later on, as I have designed this stuff with the
above assumption.

-- 
viresh

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

* Re: [PATCH] PM: opp: Fix NULL pointer exception on a v2 table combined with v1 opps
  2022-04-04  6:26 ` Viresh Kumar
@ 2022-04-04  6:28   ` Krzysztof Kozlowski
  2022-04-04  6:31     ` Viresh Kumar
  0 siblings, 1 reply; 4+ messages in thread
From: Krzysztof Kozlowski @ 2022-04-04  6:28 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Viresh Kumar, Nishanth Menon, Stephen Boyd, Dmitry Osipenko,
	linux-pm, linux-kernel

On 04/04/2022 08:26, Viresh Kumar wrote:
> On 01-04-22, 14:03, Krzysztof Kozlowski wrote:
>> dev_pm_opp_add() adds a v1 OPP.  If the Devicetree contains an OPP v2
>> table with required-opps, but the driver uses dev_pm_opp_add(), the
>> table might have required_opp_count!=0 but the opp->required_opps will
>> be NULL.
> 
> This use-case isn't supported currently, as either all OPPs should
> have required-opp or none. This kind of scenario may end up breaking
> at other places later on, as I have designed this stuff with the
> above assumption.

I understand this is not a proper use case, but it is easy to trigger
(UFS driver adds opps manually, DTS also adds one). Maybe you prefer to
handle it differently - exit with ERRNO? Because NULL pointer exception
in case of proper, but unexpected DTB is not a good way to handle it.

Best regards,
Krzysztof

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

* Re: [PATCH] PM: opp: Fix NULL pointer exception on a v2 table combined with v1 opps
  2022-04-04  6:28   ` Krzysztof Kozlowski
@ 2022-04-04  6:31     ` Viresh Kumar
  0 siblings, 0 replies; 4+ messages in thread
From: Viresh Kumar @ 2022-04-04  6:31 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Viresh Kumar, Nishanth Menon, Stephen Boyd, Dmitry Osipenko,
	linux-pm, linux-kernel

On 04-04-22, 08:28, Krzysztof Kozlowski wrote:
> I understand this is not a proper use case, but it is easy to trigger
> (UFS driver adds opps manually, DTS also adds one). Maybe you prefer to
> handle it differently - exit with ERRNO? Because NULL pointer exception
> in case of proper, but unexpected DTB is not a good way to handle it.

Yeah, sure. I agree that we can return a proper error in that case.
Will look forward to that patch :)

-- 
viresh

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

end of thread, other threads:[~2022-04-04  6:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-01 12:03 [PATCH] PM: opp: Fix NULL pointer exception on a v2 table combined with v1 opps Krzysztof Kozlowski
2022-04-04  6:26 ` Viresh Kumar
2022-04-04  6:28   ` Krzysztof Kozlowski
2022-04-04  6:31     ` Viresh Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).