[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <a1e701cc-aa4f-4098-95c9-0cb7aaf5b281@lunn.ch>
Date: Wed, 12 Apr 2023 14:43:51 +0200
From: Andrew Lunn <andrew@...n.ch>
To: Matthias Schiffer <matthias.schiffer@...tq-group.com>
Cc: Peter Korsgaard <peter@...sgaard.com>,
Federico Vaga <federico.vaga@...n.ch>,
Wolfram Sang <wsa@...nel.org>, linux-i2c@...r.kernel.org,
linux-kernel@...r.kernel.org, linux@...tq-group.com
Subject: Re: [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
Powered by blists - more mailing lists