lkml.org 
[lkml]   [2023]   [Apr]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] i2c: ocores: generate stop condition after timeout in polling mode
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

\
 
 \ /
  Last update: 2023-04-12 14:45    [W:0.133 / U:1.444 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site