From: Andy Shevchenko <andy@kernel.org>
To: Binbin Zhou <zhoubinbin@loongson.cn>
Cc: Wolfram Sang <wsa@kernel.org>,
Wolfram Sang <wsa+renesas@sang-engineering.com>,
Mika Westerberg <mika.westerberg@linux.intel.com>,
linux-i2c@vger.kernel.org, loongarch@lists.linux.dev,
devicetree@vger.kernel.org, Huacai Chen <chenhuacai@loongson.cn>,
WANG Xuerui <kernel@xen0n.name>, Arnd Bergmann <arnd@arndb.de>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Jianmin Lv <lvjianmin@loongson.cn>
Subject: Re: [PATCH V8 3/4] i2c: ls2x: Add driver for Loongson-2K/LS7A I2C controller
Date: Tue, 27 Dec 2022 23:57:17 +0200 [thread overview]
Message-ID: <Y6tqPenv3NBEl9qD@smile.fi.intel.com> (raw)
In-Reply-To: <9d3e4997519fd9ecebae6fd241148cc22d3fe04f.1671688961.git.zhoubinbin@loongson.cn>
On Fri, Dec 23, 2022 at 05:00:51PM +0800, Binbin Zhou wrote:
> This I2C module is integrated into the Loongson-2K SoCs and Loongson
> LS7A bridge chip.
...
> +static int ls2x_i2c_xfer_one(struct ls2x_i2c_priv *priv,
> + struct i2c_msg *msg, bool stop)
> +{
> + int ret;
> + bool is_read = msg->flags & I2C_M_RD;
> +
> + /* Contains steps to send start condition and address */
> + ret = ls2x_i2c_start(priv, msg);
> + if (!ret) {
> + if (is_read)
> + ret = ls2x_i2c_rx(priv, msg->buf, msg->len);
> + else
> + ret = ls2x_i2c_tx(priv, msg->buf, msg->len);
> +
> + if (!ret && stop)
> + ret = ls2x_i2c_stop(priv);
> + }
> +
> + if (ret == -ENXIO)
> + ls2x_i2c_stop(priv);
> + else if (ret < 0)
> + ls2x_i2c_init(priv);
> +
> + return ret;
> +}
Still this code is odd from reader's perspective. It's in particular not clear
if the stop can be called twice in a row. I recommend to split it to two
functions and then do something like
_read_one()
{
ret = start();
if (ret)
goto _stop; // Do we really need this?
ret = rx();
if (ret)
goto _stop; // Do we need this?
/* By setting this call the stop */
if (stop)
ret = -ENXIO;
out_send_stop:
if (ret == ...)
return _stop();
// I don't like above, so this error checking/setting parts
// also can be rethought and refactored accordingly
return ret;
}
if (is_read)
ret = _read_one();
else
ret = _write_one();
if (ret)
_init();
return ret;
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2022-12-27 21:57 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-23 9:00 [PATCH V8 0/4] i2c: ls2x: Add support for the Loongson-2K/LS7A I2C controller Binbin Zhou
2022-12-23 9:00 ` [PATCH V8 1/4] i2c: gpio: Add support on ACPI-based system Binbin Zhou
2022-12-23 9:00 ` [PATCH V8 2/4] dt-bindings: i2c: add Loongson LS2X I2C controller Binbin Zhou
2022-12-23 9:00 ` [PATCH V8 3/4] i2c: ls2x: Add driver for Loongson-2K/LS7A " Binbin Zhou
2022-12-27 21:57 ` Andy Shevchenko [this message]
2022-12-29 7:31 ` Binbin Zhou
2022-12-29 9:20 ` Andy Shevchenko
2022-12-29 9:23 ` Andy Shevchenko
2022-12-30 1:46 ` Binbin Zhou
2022-12-30 8:26 ` Andy Shevchenko
2022-12-30 8:49 ` Binbin Zhou
2022-12-23 9:01 ` [PATCH V8 4/4] LoongArch: Enable LS2X I2C in loongson3_defconfig Binbin Zhou
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y6tqPenv3NBEl9qD@smile.fi.intel.com \
--to=andy@kernel.org \
--cc=arnd@arndb.de \
--cc=chenhuacai@loongson.cn \
--cc=devicetree@vger.kernel.org \
--cc=kernel@xen0n.name \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-i2c@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=lvjianmin@loongson.cn \
--cc=mika.westerberg@linux.intel.com \
--cc=robh+dt@kernel.org \
--cc=wsa+renesas@sang-engineering.com \
--cc=wsa@kernel.org \
--cc=zhoubinbin@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox