[PATCH 1/2][SRU][OEM-OSP1-B] i2c: nvidia-gpu: refactor master_xfer
AceLan Kao
acelan.kao at canonical.com
Wed Feb 26 09:19:53 UTC 2020
From: Ajay Gupta <ajayg at nvidia.com>
BugLink: https://bugs.launchpad.net/bugs/1864606
Added a local variable "send_stop" to simplify "goto" statements.
The "send_stop" handles below two case
1) When first i2c start fails and so i2c stop is not sent before
exiting
2) When i2c stop failed after all transfers and we do not need to
send another stop before exiting.
Signed-off-by: Ajay Gupta <ajayg at nvidia.com>
Signed-off-by: Wolfram Sang <wsa at the-dreams.de>
(cherry picked from commit cb7302fbe365cd079b7481720daf04e5e1925ac0)
Signed-off-by: AceLan Kao <acelan.kao at canonical.com>
---
drivers/i2c/busses/i2c-nvidia-gpu.c | 28 ++++++++++++++++------------
1 file changed, 16 insertions(+), 12 deletions(-)
diff --git a/drivers/i2c/busses/i2c-nvidia-gpu.c b/drivers/i2c/busses/i2c-nvidia-gpu.c
index 060dcd24e7d0..7e822b038c8b 100644
--- a/drivers/i2c/busses/i2c-nvidia-gpu.c
+++ b/drivers/i2c/busses/i2c-nvidia-gpu.c
@@ -170,6 +170,7 @@ static int gpu_i2c_master_xfer(struct i2c_adapter *adap,
{
struct gpu_i2c_dev *i2cd = i2c_get_adapdata(adap);
int status, status2;
+ bool send_stop = true;
int i, j;
/*
@@ -183,37 +184,40 @@ static int gpu_i2c_master_xfer(struct i2c_adapter *adap,
/* gpu_i2c_read has implicit start */
status = gpu_i2c_read(i2cd, msgs[i].buf, msgs[i].len);
if (status < 0)
- goto stop;
+ goto exit;
} else {
u8 addr = i2c_8bit_addr_from_msg(msgs + i);
status = gpu_i2c_start(i2cd);
if (status < 0) {
if (i == 0)
- return status;
- goto stop;
+ send_stop = false;
+ goto exit;
}
status = gpu_i2c_write(i2cd, addr);
if (status < 0)
- goto stop;
+ goto exit;
for (j = 0; j < msgs[i].len; j++) {
status = gpu_i2c_write(i2cd, msgs[i].buf[j]);
if (status < 0)
- goto stop;
+ goto exit;
}
}
}
+ send_stop = false;
status = gpu_i2c_stop(i2cd);
if (status < 0)
- return status;
-
- return i;
-stop:
- status2 = gpu_i2c_stop(i2cd);
- if (status2 < 0)
- dev_err(i2cd->dev, "i2c stop failed %d\n", status2);
+ goto exit;
+
+ status = i;
+exit:
+ if (send_stop) {
+ status2 = gpu_i2c_stop(i2cd);
+ if (status2 < 0)
+ dev_err(i2cd->dev, "i2c stop failed %d\n", status2);
+ }
return status;
}
--
2.17.1
More information about the kernel-team
mailing list