Skip to content

Commit cb7302f

Browse files
Ajay GuptaWolfram Sang
authored andcommitted
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>
1 parent 5213d7e commit cb7302f

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

drivers/i2c/busses/i2c-nvidia-gpu.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ static int gpu_i2c_master_xfer(struct i2c_adapter *adap,
169169
{
170170
struct gpu_i2c_dev *i2cd = i2c_get_adapdata(adap);
171171
int status, status2;
172+
bool send_stop = true;
172173
int i, j;
173174

174175
/*
@@ -182,37 +183,40 @@ static int gpu_i2c_master_xfer(struct i2c_adapter *adap,
182183
/* gpu_i2c_read has implicit start */
183184
status = gpu_i2c_read(i2cd, msgs[i].buf, msgs[i].len);
184185
if (status < 0)
185-
goto stop;
186+
goto exit;
186187
} else {
187188
u8 addr = i2c_8bit_addr_from_msg(msgs + i);
188189

189190
status = gpu_i2c_start(i2cd);
190191
if (status < 0) {
191192
if (i == 0)
192-
return status;
193-
goto stop;
193+
send_stop = false;
194+
goto exit;
194195
}
195196

196197
status = gpu_i2c_write(i2cd, addr);
197198
if (status < 0)
198-
goto stop;
199+
goto exit;
199200

200201
for (j = 0; j < msgs[i].len; j++) {
201202
status = gpu_i2c_write(i2cd, msgs[i].buf[j]);
202203
if (status < 0)
203-
goto stop;
204+
goto exit;
204205
}
205206
}
206207
}
208+
send_stop = false;
207209
status = gpu_i2c_stop(i2cd);
208210
if (status < 0)
209-
return status;
210-
211-
return i;
212-
stop:
213-
status2 = gpu_i2c_stop(i2cd);
214-
if (status2 < 0)
215-
dev_err(i2cd->dev, "i2c stop failed %d\n", status2);
211+
goto exit;
212+
213+
status = i;
214+
exit:
215+
if (send_stop) {
216+
status2 = gpu_i2c_stop(i2cd);
217+
if (status2 < 0)
218+
dev_err(i2cd->dev, "i2c stop failed %d\n", status2);
219+
}
216220
return status;
217221
}
218222

0 commit comments

Comments
 (0)