2020-09-08 22:45:21

by Dmitry Osipenko

[permalink] [raw]
Subject: [PATCH v7 28/34] i2c: tegra: Consolidate error handling in tegra_i2c_xfer_msg()

Consolidate error handling in tegra_i2c_xfer_msg() into a common code
path in order to make code cleaner.

Reviewed-by: Michał Mirosław <[email protected]>
Signed-off-by: Dmitry Osipenko <[email protected]>
---
drivers/i2c/busses/i2c-tegra.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index fe672cfebe12..ac40c87f1c21 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -1293,8 +1293,8 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,

if (!time_left && !completion_done(&i2c_dev->dma_complete)) {
dev_err(i2c_dev->dev, "DMA transfer timeout\n");
- tegra_i2c_init(i2c_dev);
- return -ETIMEDOUT;
+ err = -ETIMEDOUT;
+ goto reset_hardware;
}

if (i2c_dev->msg_read && i2c_dev->msg_err == I2C_ERR_NONE) {
@@ -1314,8 +1314,8 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,

if (time_left == 0) {
dev_err(i2c_dev->dev, "i2c transfer timed out\n");
- tegra_i2c_init(i2c_dev);
- return -ETIMEDOUT;
+ err = -ETIMEDOUT;
+ goto reset_hardware;
}

dev_dbg(i2c_dev->dev, "transfer complete: %lu %d %d\n",
@@ -1329,6 +1329,11 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,
return err;

return 0;
+
+reset_hardware:
+ tegra_i2c_init(i2c_dev);
+
+ return err;
}

static int tegra_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],
--
2.27.0


2020-09-17 12:17:26

by Thierry Reding

[permalink] [raw]
Subject: Re: [PATCH v7 28/34] i2c: tegra: Consolidate error handling in tegra_i2c_xfer_msg()

On Wed, Sep 09, 2020 at 01:40:00AM +0300, Dmitry Osipenko wrote:
> Consolidate error handling in tegra_i2c_xfer_msg() into a common code
> path in order to make code cleaner.
>
> Reviewed-by: Michał Mirosław <[email protected]>
> Signed-off-by: Dmitry Osipenko <[email protected]>
> ---
> drivers/i2c/busses/i2c-tegra.c | 13 +++++++++----
> 1 file changed, 9 insertions(+), 4 deletions(-)

I'm really not sure this is cleaner. You've got a net positive diffstat
and you add goto. That's not always bad, but in this case there is no
need for any complicated error unwinding, so I don't think this is any
better than the previous code.

Thierry


Attachments:
(No filename) (669.00 B)
signature.asc (849.00 B)
Download all attachments

2020-09-21 10:22:17

by Thierry Reding

[permalink] [raw]
Subject: Re: [PATCH v7 28/34] i2c: tegra: Consolidate error handling in tegra_i2c_xfer_msg()

On Wed, 09 Sep 2020 01:40:00 +0300, Dmitry Osipenko wrote:
> Consolidate error handling in tegra_i2c_xfer_msg() into a common code
> path in order to make code cleaner.
>
> Reviewed-by: Michał Mirosław <[email protected]>
> Signed-off-by: Dmitry Osipenko <[email protected]>
> ---
> drivers/i2c/busses/i2c-tegra.c | 13 +++++++++----
> 1 file changed, 9 insertions(+), 4 deletions(-)

Tested-by: Thierry Reding <[email protected]>