From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kishon Vijay Abraham I Date: Tue, 4 May 2021 16:11:38 +0530 Subject: [PATCH v3 03/20] drivers: reset: Handle gracefully NULL pointers In-Reply-To: <20210504104155.19222-1-kishon@ti.com> References: <20210504104155.19222-1-kishon@ti.com> Message-ID: <20210504104155.19222-4-kishon@ti.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 Signed-off-by: Kishon Vijay Abraham I --- 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