i2c: nvidia-gpu: refactor master_xfer

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@nvidia.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
This commit is contained in:
Ajay Gupta 2019-06-07 09:34:19 -07:00 committed by Wolfram Sang
parent 5213d7efc8
commit cb7302fbe3

View File

@ -169,6 +169,7 @@ static int gpu_i2c_master_xfer(struct i2c_adapter *adap,
{ {
struct gpu_i2c_dev *i2cd = i2c_get_adapdata(adap); struct gpu_i2c_dev *i2cd = i2c_get_adapdata(adap);
int status, status2; int status, status2;
bool send_stop = true;
int i, j; int i, j;
/* /*
@ -182,37 +183,40 @@ static int gpu_i2c_master_xfer(struct i2c_adapter *adap,
/* gpu_i2c_read has implicit start */ /* gpu_i2c_read has implicit start */
status = gpu_i2c_read(i2cd, msgs[i].buf, msgs[i].len); status = gpu_i2c_read(i2cd, msgs[i].buf, msgs[i].len);
if (status < 0) if (status < 0)
goto stop; goto exit;
} else { } else {
u8 addr = i2c_8bit_addr_from_msg(msgs + i); u8 addr = i2c_8bit_addr_from_msg(msgs + i);
status = gpu_i2c_start(i2cd); status = gpu_i2c_start(i2cd);
if (status < 0) { if (status < 0) {
if (i == 0) if (i == 0)
return status; send_stop = false;
goto stop; goto exit;
} }
status = gpu_i2c_write(i2cd, addr); status = gpu_i2c_write(i2cd, addr);
if (status < 0) if (status < 0)
goto stop; goto exit;
for (j = 0; j < msgs[i].len; j++) { for (j = 0; j < msgs[i].len; j++) {
status = gpu_i2c_write(i2cd, msgs[i].buf[j]); status = gpu_i2c_write(i2cd, msgs[i].buf[j]);
if (status < 0) if (status < 0)
goto stop; goto exit;
} }
} }
} }
send_stop = false;
status = gpu_i2c_stop(i2cd); status = gpu_i2c_stop(i2cd);
if (status < 0) if (status < 0)
return status; goto exit;
return i; status = i;
stop: exit:
status2 = gpu_i2c_stop(i2cd); if (send_stop) {
if (status2 < 0) status2 = gpu_i2c_stop(i2cd);
dev_err(i2cd->dev, "i2c stop failed %d\n", status2); if (status2 < 0)
dev_err(i2cd->dev, "i2c stop failed %d\n", status2);
}
return status; return status;
} }