[PATCH] regulator: core: Return error in get optional stub

From: Tim Kryger
Date: Thu Apr 17 2014 - 14:55:46 EST


Drivers that call regulator_get_optional are tolerant to the absence of
that regulator. By modifying the value returned from the stub function
to match that seen when a regulator isn't present, callers can wrap the
regulator logic with an IS_ERR based conditional even if they happen to
call regulator_is_supported_voltage. This improves efficiency as well
as eliminates the possibility for a very subtle bug.

Signed-off-by: Tim Kryger <tim.kryger@xxxxxxxxxx>
Reviewed-by: Alex Elder <elder@xxxxxxxxxx>
---

This change was proposed here: https://lkml.org/lkml/2014/4/16/627

include/linux/regulator/consumer.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
index e530681..1a4a8c1 100644
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -258,14 +258,14 @@ regulator_get_exclusive(struct device *dev, const char *id)
static inline struct regulator *__must_check
regulator_get_optional(struct device *dev, const char *id)
{
- return NULL;
+ return ERR_PTR(-ENODEV);
}


static inline struct regulator *__must_check
devm_regulator_get_optional(struct device *dev, const char *id)
{
- return NULL;
+ return ERR_PTR(-ENODEV);
}

static inline void regulator_put(struct regulator *regulator)
--
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/