Re: [PATCH] i2c: ocores: generate stop condition after timeout in polling mode

From: Andrew Lunn
Date: Wed Apr 12 2023 - 08:45:05 EST


Hi Matthias

I also don't have access to the hardware, but the change looks O.K.

> static int ocores_xfer_core(struct ocores_i2c *i2c,
> @@ -387,16 +389,16 @@ static int ocores_xfer_core(struct ocores_i2c *i2c,
> oc_setreg(i2c, OCI2C_DATA, i2c_8bit_addr_from_msg(i2c->msg));
> oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_START);
>
> - if (polling) {
> - ocores_process_polling(i2c);
> - } else {
> + if (polling)
> + ret = ocores_process_polling(i2c);
> + else
> ret = wait_event_timeout(i2c->wait,
> (i2c->state == STATE_ERROR) ||
> - (i2c->state == STATE_DONE), HZ);
> - if (ret == 0) {
> - ocores_process_timeout(i2c);
> - return -ETIMEDOUT;
> - }
> + (i2c->state == STATE_DONE), HZ) ?
> + 0 : -ETIMEDOUT;
> + if (ret) {
> + ocores_process_timeout(i2c);
> + return ret;
> }

The ret == 0 becoming ret is not so obvious. Rather than having the
trinary, do

if (ret == 0)
ret = -ETIMEDOUT;

and then fall into your new if clause. I think that makes it more
obvious that wait_event_timeout() returns 0 on timeout.

Andrew