From: Ramiro Oliveira <Ramiro.Oliveira@synopsys.com>
To: p.zabel@pengutronix.de, linux-kernel@vger.kernel.org
Cc: laurent.pinchart@ideasonboard.com, CARLOS.PALMINHA@synopsys.com,
Ramiro Oliveira <Ramiro.Oliveira@synopsys.com>
Subject: [PATCH] reset: Make optional functions really optional.
Date: Thu, 15 Dec 2016 18:05:50 +0000 [thread overview]
Message-ID: <58b07c24e1bc263db0d43274b46022c8d8506302.1481822669.git.Ramiro.Oliveira@synopsys.com> (raw)
Up until now optional functions in the reset API were similar to the non
optional.
This patch corrects that, while maintaining compatibility with existing
drivers.
As suggested here: https://lkml.org/lkml/2016/12/14/502
Signed-off-by: Ramiro Oliveira <Ramiro.Oliveira@synopsys.com>
---
drivers/reset/core.c | 21 +++++++++++++++++++--
include/linux/reset.h | 46 ++++++++++++++++++++++++++++++++++++++++++----
2 files changed, 61 insertions(+), 6 deletions(-)
diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index 395dc9c..6150e7c 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -135,9 +135,14 @@ EXPORT_SYMBOL_GPL(devm_reset_controller_register);
* @rstc: reset controller
*
* Calling this on a shared reset controller is an error.
+ *
+ * If it's an optional reset it will return 0.
*/
int reset_control_reset(struct reset_control *rstc)
{
+ if (!rstc)
+ return 0;
+
if (WARN_ON(rstc->shared))
return -EINVAL;
@@ -158,9 +163,14 @@ EXPORT_SYMBOL_GPL(reset_control_reset);
*
* For shared reset controls a driver cannot expect the hw's registers and
* internal state to be reset, but must be prepared for this to happen.
+ *
+ * If it's an optional reset it will return 0.
*/
int reset_control_assert(struct reset_control *rstc)
{
+ if (!rstc)
+ return 0;
+
if (!rstc->rcdev->ops->assert)
return -ENOTSUPP;
@@ -180,10 +190,14 @@ EXPORT_SYMBOL_GPL(reset_control_assert);
* reset_control_deassert - deasserts the reset line
* @rstc: reset controller
*
- * After calling this function, the reset is guaranteed to be deasserted.
+ * After calling this function, the reset is guaranteed to be deasserted, if
+ * it's not optional.
*/
int reset_control_deassert(struct reset_control *rstc)
{
+ if (!rstc)
+ return 0;
+
if (!rstc->rcdev->ops->deassert)
return -ENOTSUPP;
@@ -199,11 +213,14 @@ EXPORT_SYMBOL_GPL(reset_control_deassert);
/**
* reset_control_status - returns a negative errno if not supported, a
* positive value if the reset line is asserted, or zero if the reset
- * line is not asserted.
+ * line is not asserted or if the desc is NULL (optional reset).
* @rstc: reset controller
*/
int reset_control_status(struct reset_control *rstc)
{
+ if (!rstc)
+ return 0;
+
if (rstc->rcdev->ops->status)
return rstc->rcdev->ops->status(rstc->rcdev, rstc->id);
diff --git a/include/linux/reset.h b/include/linux/reset.h
index 5daff15..1af1e62 100644
--- a/include/linux/reset.h
+++ b/include/linux/reset.h
@@ -138,13 +138,33 @@ static inline struct reset_control *reset_control_get_shared(
static inline struct reset_control *reset_control_get_optional_exclusive(
struct device *dev, const char *id)
{
- return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, 0);
+ struct reset_control *desc;
+
+ desc = __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, 0);
+
+ if (IS_ERR(desc)) {
+ if (PTR_ERR(desc) == -ENOENT)
+ return NULL;
+ }
+
+ return desc;
+
}
static inline struct reset_control *reset_control_get_optional_shared(
struct device *dev, const char *id)
{
- return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, 1);
+
+ struct reset_control *desc;
+
+ desc = __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, 1);
+
+ if (IS_ERR(desc)) {
+ if (PTR_ERR(desc) == -ENOENT)
+ return NULL;
+ }
+
+ return desc;
}
/**
@@ -273,13 +293,31 @@ static inline struct reset_control *devm_reset_control_get_shared(
static inline struct reset_control *devm_reset_control_get_optional_exclusive(
struct device *dev, const char *id)
{
- return __devm_reset_control_get(dev, id, 0, 0);
+ struct reset_control *desc;
+
+ desc = __devm_reset_control_get(dev, id, 0, 0);
+
+ if (IS_ERR(desc)) {
+ if (PTR_ERR(desc) == -ENOENT)
+ return NULL;
+ }
+
+ return desc;
}
static inline struct reset_control *devm_reset_control_get_optional_shared(
struct device *dev, const char *id)
{
- return __devm_reset_control_get(dev, id, 0, 1);
+ struct reset_control *desc;
+
+ desc = __devm_reset_control_get(dev, id, 0, 1);
+
+ if (IS_ERR(desc)) {
+ if (PTR_ERR(desc) == -ENOENT)
+ return NULL;
+ }
+
+ return desc;
}
/**
--
2.10.2
next reply other threads:[~2016-12-15 18:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-15 18:05 Ramiro Oliveira [this message]
2016-12-23 10:58 ` [PATCH] reset: Make optional functions really optional Philipp Zabel
2016-12-23 11:23 ` Laurent Pinchart
2016-12-23 12:08 ` Philipp Zabel
2016-12-23 16:41 ` Laurent Pinchart
2016-12-23 16:53 ` Ramiro Oliveira
2016-12-23 17:19 ` Ramiro Oliveira
2016-12-23 17:57 ` Laurent Pinchart
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=58b07c24e1bc263db0d43274b46022c8d8506302.1481822669.git.Ramiro.Oliveira@synopsys.com \
--to=ramiro.oliveira@synopsys.com \
--cc=CARLOS.PALMINHA@synopsys.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=p.zabel@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).