Skip to contentSkip to conversation

PM / OPP: Fix NULL pointer dereference crash when disabling OPPs

PATCH Applied Jon Hunter 8 participants 18 messages Feb 11, 2016 – Feb 16, 2016 2 messages not in the archive

Subsystems (5)
lore
Share & tools
lore

Jon Hunter

author maintainer
#0 lore raw

PATCH 1/1 PM / OPP: Fix NULL pointer dereference crash when disabling OPPs

Commit 7d34d56ef334 ("PM / OPP: Disable OPPs that aren't supported by the regulator") disables OPPs that are not supported by the regulator. This is causes a crash on Tegra124 Jetson TK1 when using the DFLL clock source for the CPU. The DFLL manages the voltage itself and so there is no regulator specified for the OPPs and so we get a crash when we try to dereference the regulator pointer. Fix this by checking to see if the regulator IS_ERR_OR_NULL before dereferencing it.

Fixes 7d34d56ef334 ("PM / OPP: Disable OPPs that aren't supported by the

regulator")

---
 drivers/base/power/opp/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/power/opp/core.c +1 -1
index ab711c2c3e00..d7cd4e265766 100644
@@ -975,7 +975,7 @@ static bool _opp_supported_by_regulators(struct dev_pm_opp *opp,
 {
 	struct regulator *reg = dev_opp->regulator;
 
-	if (!IS_ERR(reg) &&
+	if (!IS_ERR_OR_NULL(reg) &&
 	    !regulator_is_supported_voltage(reg, opp->u_volt_min,
 					    opp->u_volt_max)) {
 		pr_warn("%s: OPP minuV: %lu maxuV: %lu, not supported by regulator\n",
Signature · 1 line
2.1.4
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Jon Hunter

Commit 7d34d56ef334 ("PM / OPP: Disable OPPs that aren't supported by the regulator") disables OPPs that are not supported by the regulator. This is causes a crash on Tegra124 Jetson TK1 when using the DFLL clock source for the CPU. The DFLL manages the voltage itself and so there is no regulator specified for the OPPs and so we get a crash when we try to dereference the regulator pointer. Fix this by checking to see if the regulator IS_ERR_OR_NULL before dereferencing it.

Quoted 7 lines
Fixes 7d34d56ef334 ("PM / OPP: Disable OPPs that aren't supported by the

regulator")

---
 drivers/base/power/opp/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Sorry about that :(

Signature · 1 line
viresh
maintainer Applied
#2 lore raw
Quoted 12 lines · Viresh Kumar
Quoted 11 lines · Jon Hunter

Commit 7d34d56ef334 ("PM / OPP: Disable OPPs that aren't supported by the regulator") disables OPPs that are not supported by the regulator. This is causes a crash on Tegra124 Jetson TK1 when using the DFLL clock source for the CPU. The DFLL manages the voltage itself and so there is no regulator specified for the OPPs and so we get a crash when we try to dereference the regulator pointer. Fix this by checking to see if the regulator IS_ERR_OR_NULL before dereferencing it.

Fixes 7d34d56ef334 ("PM / OPP: Disable OPPs that aren't supported by the

regulator")

Quoted 8 lines
Quoted 4 lines
---
 drivers/base/power/opp/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Sorry about that :(

Applied, thanks!

Rafael

A message that is not in the archive (sent off-list or not yet received): 1455189959-27944-1-git-send-email-jonathanh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org

#4 lore raw

PATCH 1/1 PM / OPP: Fix NULL pointer dereference crash when setting the OPP

Commit 6a0712f6f199 ("PM / OPP: Add dev_pm_opp_set_rate()") causes a crash on Tegra124 Jetson TK1 when using the DFLL clock source for the CPU. The DFLL manages the voltage itself and so there is no regulator specified for the OPPs and so we get a crash when we try to dereference the regulator pointer. Fix this by checking to see if the regulator IS_ERR_OR_NULL before dereferencing it.

Fixes 6a0712f6f199 ("PM / OPP: Add dev_pm_opp_set_rate()")

---

I am not sure why I did not catch this instance of the bug last week when I submitted the patch to fix the NULL pointer dereference in _opp_supported_by_regulators(). May be I forgot to go back and test on HEAD after bisecting? Anyway, both this fix and the one from last week are necessary to get the kernel booting again on Tegra124 Jetson TK1.

 drivers/base/power/opp/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/power/opp/core.c +1 -1
index d7cd4e265766..82ad5ae72427 100644
@@ -564,7 +564,7 @@ static int _set_opp_voltage(struct device *dev, struct regulator *reg,
 	int ret;
 
 	/* Regulator not available for device */
-	if (IS_ERR(reg)) {
+	if (IS_ERR_OR_NULL(reg)) {
 		dev_dbg(dev, "%s: regulator not available: %ld\n", __func__,
 			PTR_ERR(reg));
 		return 0;
Signature · 1 line
2.1.4

A message that is not in the archive (sent off-list or not yet received): 1455544758-7718-1-git-send-email-jonathanh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org

#6 lore raw

Re: [PATCH] PM / OPP: Fix NULL pointer dereference crash when setting the OPP

Quoted 10 lines · Jon Hunter

Commit 6a0712f6f199 ("PM / OPP: Add dev_pm_opp_set_rate()") causes a crash on Tegra124 Jetson TK1 when using the DFLL clock source for the CPU. The DFLL manages the voltage itself and so there is no regulator specified for the OPPs and so we get a crash when we try to dereference the regulator pointer. Fix this by checking to see if the regulator IS_ERR_OR_NULL before dereferencing it.

Fixes 6a0712f6f199 ("PM / OPP: Add dev_pm_opp_set_rate()")
Quoted 8 lines

---

I am not sure why I did not catch this instance of the bug last week when I submitted the patch to fix the NULL pointer dereference in _opp_supported_by_regulators(). May be I forgot to go back and test on HEAD after bisecting? Anyway, both this fix and the one from last week are necessary to get the kernel booting again on Tegra124 Jetson TK1.

I want to fix it a bit differently, will send out in a different mail to make it easy for Rafael to apply it.

Signature · 1 line
viresh
#7 lore raw

PATCH 1/1 PM / OPP: Initialize regulator pointer to an error value

In reply to Jon Hunter

We are currently required to do two checks for regulator pointer:
IS_ERR() and IS_NULL().

And multiple instances are reported, about both of these not being used consistently and so resulting in crashes.

Fix that by initializing regulator pointer with an error value and checking it only against an error.

This makes code consistent and efficient.

---
 drivers/base/power/opp/core.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/base/power/opp/core.c +9 -6
index d7cd4e265766..146b6197d598 100644
@@ -257,7 +257,7 @@ unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev)
 	}
 
 	reg = dev_opp->regulator;
-	if (IS_ERR_OR_NULL(reg)) {
+	if (IS_ERR(reg)) {
 		/* Regulator may not be required for device */
 		if (reg)
 			dev_err(dev, "%s: Invalid regulator (%ld)\n", __func__,
@@ -798,6 +798,9 @@ static struct device_opp *_add_device_opp(struct device *dev)
 		of_node_put(np);
 	}
 
+	/* Set regulator to a non-NULL error value */
+	dev_opp->regulator = ERR_PTR(-EFAULT);
+
 	/* Find clk for the device */
 	dev_opp->clk = clk_get(dev, NULL);
 	if (IS_ERR(dev_opp->clk)) {
@@ -845,7 +848,7 @@ static void _remove_device_opp(struct device_opp *dev_opp)
 	if (dev_opp->prop_name)
 		return;
 
-	if (!IS_ERR_OR_NULL(dev_opp->regulator))
+	if (!IS_ERR(dev_opp->regulator))
 		return;
 
 	/* Release clk */
@@ -975,7 +978,7 @@ static bool _opp_supported_by_regulators(struct dev_pm_opp *opp,
 {
 	struct regulator *reg = dev_opp->regulator;
 
-	if (!IS_ERR_OR_NULL(reg) &&
+	if (!IS_ERR(reg) &&
 	    !regulator_is_supported_voltage(reg, opp->u_volt_min,
 					    opp->u_volt_max)) {
 		pr_warn("%s: OPP minuV: %lu maxuV: %lu, not supported by regulator\n",
@@ -1435,7 +1438,7 @@ int dev_pm_opp_set_regulator(struct device *dev, const char *name)
 	}
 
 	/* Already have a regulator set */
-	if (WARN_ON(!IS_ERR_OR_NULL(dev_opp->regulator))) {
+	if (WARN_ON(!IS_ERR(dev_opp->regulator))) {
 		ret = -EBUSY;
 		goto err;
 	}
@@ -1486,7 +1489,7 @@ void dev_pm_opp_put_regulator(struct device *dev)
 		goto unlock;
 	}
 
-	if (IS_ERR_OR_NULL(dev_opp->regulator)) {
+	if (IS_ERR(dev_opp->regulator)) {
 		dev_err(dev, "%s: Doesn't have regulator set\n", __func__);
 		goto unlock;
 	}
@@ -1495,7 +1498,7 @@ void dev_pm_opp_put_regulator(struct device *dev)
 	WARN_ON(!list_empty(&dev_opp->opp_list));
 
 	regulator_put(dev_opp->regulator);
-	dev_opp->regulator = ERR_PTR(-EINVAL);
+	dev_opp->regulator = ERR_PTR(-EFAULT);
 
 	/* Try freeing device_opp if this was the last blocking resource */
 	_remove_device_opp(dev_opp);
Signature · 1 line
2.7.1.410.g6faf27b
author maintainer Tested-by on v1 1/1
#8 lore raw

Re: [PATCH] PM / OPP: Initialize regulator pointer to an error value

Quoted 6 lines · Viresh Kumar

We are currently required to do two checks for regulator pointer:
IS_ERR() and IS_NULL().

And multiple instances are reported, about both of these not being used consistently and so resulting in crashes.

Quoted 7 lines

Fix that by initializing regulator pointer with an error value and checking it only against an error.

This makes code consistent and efficient.

Thanks
Jon

#9 lore raw

Re: [PATCH] PM / OPP: Initialize regulator pointer to an error value

Quoted 11 lines · Jon Hunter
Quoted 9 lines · Viresh Kumar

We are currently required to do two checks for regulator pointer:
IS_ERR() and IS_NULL().

And multiple instances are reported, about both of these not being used consistently and so resulting in crashes.

Fix that by initializing regulator pointer with an error value and checking it only against an error.

Quoted 6 lines
Quoted 4 lines

This makes code consistent and efficient.

Thanks a lot Jon.

Signature · 1 line
viresh
#10 lore raw

Re: [PATCH] PM / OPP: Initialize regulator pointer to an error value

In reply to Viresh Kumar
Quoted 10 lines · On Monday 15 February 2016 21:56:42 Viresh Kumar wrote:

We are currently required to do two checks for regulator pointer:
IS_ERR() and IS_NULL().

And multiple instances are reported, about both of these not being used consistently and so resulting in crashes.

Fix that by initializing regulator pointer with an error value and checking it only against an error.

This makes code consistent and efficient.

There is usually something else wrong if you have to check for both. Why exactly do you need to check for both IS_ERR and NULL?

Quoted 14 lines
drivers/base/power/opp/core.c +1 -1
index d7cd4e265766..146b6197d598 100644
@@ -257,7 +257,7 @@ unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev)
 	}
 
 	reg = dev_opp->regulator;
-	if (IS_ERR_OR_NULL(reg)) {
+	if (IS_ERR(reg)) {
 		/* Regulator may not be required for device */
 		if (reg)
 			dev_err(dev, "%s: Invalid regulator (%ld)\n", __func__,

drivers/base/power/opp/core.c static struct device_opp *_add_device_opp(struct device *dev) · line 806

Quoted 9 lines
drivers/base/power/opp/core.c +3 -0
@@ -798,6 +798,9 @@ static struct device_opp *_add_device_opp(struct device *dev)
 		of_node_put(np);
 	}
 
+	/* Set regulator to a non-NULL error value */
+	dev_opp->regulator = ERR_PTR(-EFAULT);
+
 	/* Find clk for the device */
 	dev_opp->clk = clk_get(dev, NULL);
 	if (IS_ERR(dev_opp->clk)) {

-EFAULT has a very specific meaning (accessing an invalid pointer from user space), I don't think you want that one.

Arnd

#11 lore raw

Re: [PATCH] PM / OPP: Initialize regulator pointer to an error value

Quoted 32 lines · Arnd Bergmann
Quoted 10 lines · On Monday 15 February 2016 21:56:42 Viresh Kumar wrote:

We are currently required to do two checks for regulator pointer:
IS_ERR() and IS_NULL().

And multiple instances are reported, about both of these not being used consistently and so resulting in crashes.

Fix that by initializing regulator pointer with an error value and checking it only against an error.

This makes code consistent and efficient.

There is usually something else wrong if you have to check for both. Why exactly do you need to check for both IS_ERR and NULL?

Quoted 17 lines
drivers/base/power/opp/core.c +1 -1
index d7cd4e265766..146b6197d598 100644
@@ -257,7 +257,7 @@ unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev)
      }
 
      reg = dev_opp->regulator;
-     if (IS_ERR_OR_NULL(reg)) {
+     if (IS_ERR(reg)) {
              /* Regulator may not be required for device */
              if (reg)
                      dev_err(dev, "%s: Invalid regulator (%ld)\n", __func__,
@@ -798,6 +798,9 @@ static struct device_opp *_add_device_opp(struct device *dev)
              of_node_put(np);
      }
 
Quoted 9 lines

drivers/base/power/opp/core.c static struct device_opp *_add_device_opp(struct device *dev) · line 806

Quoted 6 lines
drivers/base/power/opp/core.c +3 -0
+     /* Set regulator to a non-NULL error value */
+     dev_opp->regulator = ERR_PTR(-EFAULT);
+
      /* Find clk for the device */
      dev_opp->clk = clk_get(dev, NULL);
      if (IS_ERR(dev_opp->clk)) {

-EFAULT has a very specific meaning (accessing an invalid pointer from user space), I don't think you want that one.

Yeah, agreed.

That should be something like -ENXIO IMO.

Thanks,
Rafael

#12 lore raw

Re: [PATCH] PM / OPP: Initialize regulator pointer to an error value

Quoted 1 line · Rafael J. Wysocki

That should be something like -ENXIO IMO.

Thanks for modifying and applying the patch :)

Signature · 1 line
viresh
#13 lore raw

Re: [PATCH] PM / OPP: Initialize regulator pointer to an error value

Quoted 4 lines · Viresh Kumar
Quoted 1 line · Rafael J. Wysocki

That should be something like -ENXIO IMO.

Thanks for modifying and applying the patch :)

Well, you're welcome.

I wanted it to be fixed in the tomorrow's linux-next so people can boot their systems again.

Thanks,
Rafael

#14 lore raw

Re: [PATCH] PM / OPP: Initialize regulator pointer to an error value

In reply to Arnd Bergmann

Cc'ing Mark as well.

Quoted 2 lines · Arnd Bergmann

There is usually something else wrong if you have to check for both. Why exactly do you need to check for both IS_ERR and NULL?

And here is the reasoning behind it:
- It is normally said that 'NULL' is a valid clk. The same is applicable to regulators as well, right? At least, that is what below says:

commit 4a511de96d69 ("cpufreq: cpufreq-cpu0: NULL is a valid regulator")

- And so I left the regulator pointer to NULL in OPP core.
- But then I realized that its not safe to call many regulator core APIs with NULL regulator, as those caused the crashes reported by multiple people now.
- clk APIs guarantee that they return early when NULL clk is passed to them.
- Do we need to do the same for regulator core as well ?

- And so I initialized the pointer to an error value now, as initializing it to NULL (possibly a valid regulator, in theory) isn't the right thing to do.

Quoted 17 lines
Quoted 17 lines
drivers/base/power/opp/core.c +1 -1
index d7cd4e265766..146b6197d598 100644
@@ -257,7 +257,7 @@ unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev)
 	}
 
 	reg = dev_opp->regulator;
-	if (IS_ERR_OR_NULL(reg)) {
+	if (IS_ERR(reg)) {
 		/* Regulator may not be required for device */
 		if (reg)
 			dev_err(dev, "%s: Invalid regulator (%ld)\n", __func__,
@@ -798,6 +798,9 @@ static struct device_opp *_add_device_opp(struct device *dev)
 		of_node_put(np);
 	}
 
Quoted 9 lines

drivers/base/power/opp/core.c static struct device_opp *_add_device_opp(struct device *dev) · line 806

Quoted 6 lines
drivers/base/power/opp/core.c +3 -0
+	/* Set regulator to a non-NULL error value */
+	dev_opp->regulator = ERR_PTR(-EFAULT);
+
 	/* Find clk for the device */
 	dev_opp->clk = clk_get(dev, NULL);
 	if (IS_ERR(dev_opp->clk)) {

-EFAULT has a very specific meaning (accessing an invalid pointer from user space), I don't think you want that one.

Sorry, wasn't aware of those requirements. What Rafael suggested is the right thing to do then.

Signature · 1 line
viresh
#15 lore raw

Re: [PATCH] PM / OPP: Initialize regulator pointer to an error value

Quoted 7 lines · Viresh Kumar

- And so I left the regulator pointer to NULL in OPP core.
- But then I realized that its not safe to call many regulator core APIs with NULL regulator, as those caused the crashes reported by multiple people now.
- clk APIs guarantee that they return early when NULL clk is passed to them.
- Do we need to do the same for regulator core as well ?

No, NULL is explicitly not something you can substitute in, essentially all the users are just not bothering to implement error checking and we don't want to encourage that. The set of use cases where we legitimately have optional supplies is very small, much smaller than clocks, because it makes the electrical engineering a lot harder.

#16 lore raw

Re: [PATCH] PM / OPP: Initialize regulator pointer to an error value

Quoted 10 lines · On Tuesday 16 February 2016 01:56:16 Mark Brown wrote:
Quoted 7 lines · Viresh Kumar

- And so I left the regulator pointer to NULL in OPP core.
- But then I realized that its not safe to call many regulator core APIs with NULL regulator, as those caused the crashes reported by multiple people now.
- clk APIs guarantee that they return early when NULL clk is passed to them.
- Do we need to do the same for regulator core as well ?

Quoted 6 lines

No, NULL is explicitly not something you can substitute in, essentially all the users are just not bothering to implement error checking and we don't want to encourage that. The set of use cases where we legitimately have optional supplies is very small, much smaller than clocks, because it makes the electrical engineering a lot harder.

I must have misinterpreted the idea behind that API as well then.

Quoted 1 line

From this function definition:

/*
* Make sure client drivers will still build on systems with no software
* controllable voltage or current regulators.
*/
static inline struct regulator *__must_check regulator_get(struct device *dev,
const char *id)
{
/* Nothing except the stubbed out regulator API should be
* looking at the value except to check if it is an error
* value. Drivers are free to handle NULL specifically by
* skipping all regulator API calls, but they don't have to.
* Drivers which don't, should make sure they properly handle
* corner cases of the API, such as regulator_get_voltage()
* returning 0.
*/
return NULL;
}

my reading was that the expected behavior in any driver was:

* call regulator_get()
* if IS_ERR(), fail device probe function, never use invalid pointer other than PTR_ERR()
* if NULL, and regulator is required, fail probe so we never use the regulator
* if NULL, and regulators are optional, continue with the NULL value.
* drivers never look into the regulator pointer, and only pass it into regulator APIs which can cope with the NULL value when CONFIG_REGULATOR is disabled.

That would be similar to what we have for clocks. Which part of my interpretation is wrong?

Arnd

#17 lore raw

Re: [PATCH] PM / OPP: Initialize regulator pointer to an error value

Quoted 12 lines · Arnd Bergmann
Quoted 5 lines · On Tuesday 16 February 2016 01:56:16 Mark Brown wrote:

No, NULL is explicitly not something you can substitute in, essentially all the users are just not bothering to implement error checking and we don't want to encourage that. The set of use cases where we legitimately have optional supplies is very small, much smaller than clocks, because it makes the electrical engineering a lot harder.

I must have misinterpreted the idea behind that API as well then.

From this function definition:

Quoted 13 lines

static inline struct regulator *__must_check regulator_get(struct device *dev,
const char *id)
{
/* Nothing except the stubbed out regulator API should be
* looking at the value except to check if it is an error
* value. Drivers are free to handle NULL specifically by
* skipping all regulator API calls, but they don't have to.
* Drivers which don't, should make sure they properly handle
* corner cases of the API, such as regulator_get_voltage()
* returning 0.
*/
return NULL;
}

This is the stubbed regulator API which is only ever used with the stub regulator API, it uses NULL to give a non-error pointer it can return to well written callers so they don't know they are running with the stubs. We are explicitly using NULL because callers should treat it as a valid regulator.

Quoted 7 lines

my reading was that the expected behavior in any driver was:

* call regulator_get()
* if IS_ERR(), fail device probe function, never use invalid pointer other than PTR_ERR()
* if NULL, and regulator is required, fail probe so we never use the regulator

No, drivers should never look at the value of the pointer other than to check it for error. If there is a problem of any kind an error will be returned.

Quoted 2 lines

* if NULL, and regulators are optional, continue with the NULL value.

No, we always return an error pointer if we fail to get a regulator. The difference with optional regulators is in how we handle the situation where we have full constraints and a regulator is not mapped in, normally we assume there must be one with no software control but we need to work around buggy bindings as the device would be non-functional without power.

Quoted 6 lines

* drivers never look into the regulator pointer, and only pass it into regulator APIs which can cope with the NULL value when CONFIG_REGULATOR is disabled.

That would be similar to what we have for clocks. Which part of my interpretation is wrong?

See above.

#18 lore raw

Re: [PATCH] PM / OPP: Initialize regulator pointer to an error value

Quoted 27 lines · On Tuesday 16 February 2016 13:11:08 Mark Brown wrote:
Quoted 12 lines · Arnd Bergmann
Quoted 5 lines · On Tuesday 16 February 2016 01:56:16 Mark Brown wrote:

No, NULL is explicitly not something you can substitute in, essentially all the users are just not bothering to implement error checking and we don't want to encourage that. The set of use cases where we legitimately have optional supplies is very small, much smaller than clocks, because it makes the electrical engineering a lot harder.

I must have misinterpreted the idea behind that API as well then.

From this function definition:

Quoted 13 lines

static inline struct regulator *__must_check regulator_get(struct device *dev,
const char *id)
{
/* Nothing except the stubbed out regulator API should be
* looking at the value except to check if it is an error
* value. Drivers are free to handle NULL specifically by
* skipping all regulator API calls, but they don't have to.
* Drivers which don't, should make sure they properly handle
* corner cases of the API, such as regulator_get_voltage()
* returning 0.
*/
return NULL;
}

Quoted 5 lines

This is the stubbed regulator API which is only ever used with the stub regulator API, it uses NULL to give a non-error pointer it can return to well written callers so they don't know they are running with the stubs. We are explicitly using NULL because callers should treat it as a valid regulator.

Right, that is what I understood.

Quoted 15 lines
Quoted 7 lines

my reading was that the expected behavior in any driver was:

* call regulator_get()
* if IS_ERR(), fail device probe function, never use invalid pointer other than PTR_ERR()
* if NULL, and regulator is required, fail probe so we never use the regulator

No, drivers should never look at the value of the pointer other than to check it for error. If there is a problem of any kind an error will be returned.

Quoted 2 lines

* if NULL, and regulators are optional, continue with the NULL value.

Quoted 6 lines

No, we always return an error pointer if we fail to get a regulator. The difference with optional regulators is in how we handle the situation where we have full constraints and a regulator is not mapped in, normally we assume there must be one with no software control but we need to work around buggy bindings as the device would be non-functional without power.

Sorry, I should not have said "optional" here, which has a specific meaning in the API. I meant a driver that can work with either CONFIG_REGULATOR enabled or disabled (which is something slightly different).

I guess a driver needing to know whether regulators are built-in should check 'if (IS_ENABLED(CONFIG_REGULATOR))' rather than checking the return code for NULL.

Arnd

#19 lore raw

Re: [PATCH] PM / OPP: Initialize regulator pointer to an error value

Quoted 9 lines · Arnd Bergmann
Quoted 6 lines · On Tuesday 16 February 2016 13:11:08 Mark Brown wrote:

No, we always return an error pointer if we fail to get a regulator. The difference with optional regulators is in how we handle the situation where we have full constraints and a regulator is not mapped in, normally we assume there must be one with no software control but we need to work around buggy bindings as the device would be non-functional without power.

Quoted 4 lines

Sorry, I should not have said "optional" here, which has a specific meaning in the API. I meant a driver that can work with either CONFIG_REGULATOR enabled or disabled (which is something slightly different).

Ah, right!

Quoted 3 lines

I guess a driver needing to know whether regulators are built-in should check 'if (IS_ENABLED(CONFIG_REGULATOR))' rather than checking the return code for NULL.

Yes, that's the expected interface here if anyone does need to check although for most users it's expected that the stubs will be sufficient and they don't need to check at all.