The reset framework provides devm_reset_control_get_optional()
which can return NULL (not an error case). So all the other reset_ops
should handle NULL gracefully. Prepare the way for a managed reset
API by handling NULL pointers without crashing nor failing.

Signed-off-by: Vignesh Raghavendra <vigne...@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kis...@ti.com>
---
 drivers/reset/reset-uclass.c | 35 ++++++++++++++++++++++++++++++-----
 1 file changed, 30 insertions(+), 5 deletions(-)

diff --git a/drivers/reset/reset-uclass.c b/drivers/reset/reset-uclass.c
index ac89eaf098..18dfe06d1c 100644
--- a/drivers/reset/reset-uclass.c
+++ b/drivers/reset/reset-uclass.c
@@ -162,7 +162,12 @@ int reset_get_by_name(struct udevice *dev, const char 
*name,
 
 int reset_request(struct reset_ctl *reset_ctl)
 {
-       struct reset_ops *ops = reset_dev_ops(reset_ctl->dev);
+       struct reset_ops *ops;
+
+       if (!reset_ctl)
+               return 0;
+
+       ops = reset_dev_ops(reset_ctl->dev);
 
        debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
 
@@ -171,7 +176,12 @@ int reset_request(struct reset_ctl *reset_ctl)
 
 int reset_free(struct reset_ctl *reset_ctl)
 {
-       struct reset_ops *ops = reset_dev_ops(reset_ctl->dev);
+       struct reset_ops *ops;
+
+       if (!reset_ctl)
+               return 0;
+
+       ops = reset_dev_ops(reset_ctl->dev);
 
        debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
 
@@ -180,7 +190,12 @@ int reset_free(struct reset_ctl *reset_ctl)
 
 int reset_assert(struct reset_ctl *reset_ctl)
 {
-       struct reset_ops *ops = reset_dev_ops(reset_ctl->dev);
+       struct reset_ops *ops;
+
+       if (!reset_ctl)
+               return 0;
+
+       ops = reset_dev_ops(reset_ctl->dev);
 
        debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
 
@@ -202,7 +217,12 @@ int reset_assert_bulk(struct reset_ctl_bulk *bulk)
 
 int reset_deassert(struct reset_ctl *reset_ctl)
 {
-       struct reset_ops *ops = reset_dev_ops(reset_ctl->dev);
+       struct reset_ops *ops;
+
+       if (!reset_ctl)
+               return 0;
+
+       ops = reset_dev_ops(reset_ctl->dev);
 
        debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
 
@@ -224,7 +244,12 @@ int reset_deassert_bulk(struct reset_ctl_bulk *bulk)
 
 int reset_status(struct reset_ctl *reset_ctl)
 {
-       struct reset_ops *ops = reset_dev_ops(reset_ctl->dev);
+       struct reset_ops *ops;
+
+       if (!reset_ctl)
+               return 0;
+
+       ops = reset_dev_ops(reset_ctl->dev);
 
        debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
 
-- 
2.17.1

Reply via email to