From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Jie Deng <jie.deng@intel.com>
Cc: linux-i2c@vger.kernel.org,
virtualization@lists.linux-foundation.org,
linux-kernel@vger.kernel.org, wsa@kernel.org,
wsa+renesas@sang-engineering.com, mst@redhat.com, arnd@arndb.de,
jasowang@redhat.com, yu1.wang@intel.com, shuo.a.liu@intel.com,
conghui.chen@intel.com, viresh.kumar@linaro.org,
stefanha@redhat.com
Subject: Re: [PATCH v12] i2c: virtio: add a virtio i2c frontend driver
Date: Fri, 2 Jul 2021 12:58:18 +0300 [thread overview]
Message-ID: <YN7jOm68fUL4UA2Q@smile.fi.intel.com> (raw)
In-Reply-To: <f229cd761048bc143f88f33a3437bdbf891c39fd.1625214435.git.jie.deng@intel.com>
On Fri, Jul 02, 2021 at 04:46:47PM +0800, Jie Deng wrote:
> Add an I2C bus driver for virtio para-virtualization.
>
> The controller can be emulated by the backend driver in
> any device model software by following the virtio protocol.
>
> The device specification can be found on
> https://lists.oasis-open.org/archives/virtio-comment/202101/msg00008.html.
>
> By following the specification, people may implement different
> backend drivers to emulate different controllers according to
> their needs.
...
> +static int virtio_i2c_complete_reqs(struct virtqueue *vq,
> + struct virtio_i2c_req *reqs,
> + struct i2c_msg *msgs, int nr,
> + bool fail)
> +{
> + struct virtio_i2c_req *req;
> + bool failed = fail;
> + unsigned int len;
> + int i, j = 0;
> +
> + for (i = 0; i < nr; i++) {
> + /* Detach the ith request from the vq */
> + req = virtqueue_get_buf(vq, &len);
> +
> + /*
> + * Condition (req && req == &reqs[i]) should always meet since
> + * we have total nr requests in the vq.
> + */
> + if (!failed && (WARN_ON(!(req && req == &reqs[i])) ||
> + (req->in_hdr.status != VIRTIO_I2C_MSG_OK)))
> + failed = true;
...and after failed is true, we are continuing the loop, why?
> + i2c_put_dma_safe_msg_buf(reqs[i].buf, &msgs[i], !failed);
> + if (!failed)
> + ++j;
Besides better to read j++ the j itself can be renamed to something more
verbose.
> + }
> + return (fail ? -ETIMEDOUT : j);
Redundant parentheses.
> +}
...
> + ret = virtio_i2c_send_reqs(vq, reqs, msgs, num);
> + if (ret != num) {
> + virtio_i2c_complete_reqs(vq, reqs, msgs, ret, true);
Below you check the returned code, here is not.
> + ret = 0;
> + goto err_free;
> + }
> +
> + reinit_completion(&vi->completion);
> + virtqueue_kick(vq);
> +
> + time_left = wait_for_completion_timeout(&vi->completion, adap->timeout);
> + if (!time_left)
> + dev_err(&adap->dev, "virtio i2c backend timeout.\n");
> +
> + ret = virtio_i2c_complete_reqs(vq, reqs, msgs, num, !time_left);
> +
> +err_free:
> + kfree(reqs);
> + return ret;
> +++ b/include/uapi/linux/virtio_i2c.h
> +#include <linux/types.h>
> +
> +/* The bit 0 of the @virtio_i2c_out_hdr.@flags, used to group the requests */
> +#define VIRTIO_I2C_FLAGS_FAIL_NEXT BIT(0)
It's _BITUL() or so from linux/const.h.
https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/const.h#L28
You may not use internal definitions in UAPI headers.
--
With Best Regards,
Andy Shevchenko
WARNING: multiple messages have this Message-ID (diff)
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Jie Deng <jie.deng@intel.com>
Cc: yu1.wang@intel.com, arnd@arndb.de, mst@redhat.com,
viresh.kumar@linaro.org, linux-kernel@vger.kernel.org,
virtualization@lists.linux-foundation.org, wsa@kernel.org,
wsa+renesas@sang-engineering.com, linux-i2c@vger.kernel.org,
stefanha@redhat.com, shuo.a.liu@intel.com,
conghui.chen@intel.com
Subject: Re: [PATCH v12] i2c: virtio: add a virtio i2c frontend driver
Date: Fri, 2 Jul 2021 12:58:18 +0300 [thread overview]
Message-ID: <YN7jOm68fUL4UA2Q@smile.fi.intel.com> (raw)
In-Reply-To: <f229cd761048bc143f88f33a3437bdbf891c39fd.1625214435.git.jie.deng@intel.com>
On Fri, Jul 02, 2021 at 04:46:47PM +0800, Jie Deng wrote:
> Add an I2C bus driver for virtio para-virtualization.
>
> The controller can be emulated by the backend driver in
> any device model software by following the virtio protocol.
>
> The device specification can be found on
> https://lists.oasis-open.org/archives/virtio-comment/202101/msg00008.html.
>
> By following the specification, people may implement different
> backend drivers to emulate different controllers according to
> their needs.
...
> +static int virtio_i2c_complete_reqs(struct virtqueue *vq,
> + struct virtio_i2c_req *reqs,
> + struct i2c_msg *msgs, int nr,
> + bool fail)
> +{
> + struct virtio_i2c_req *req;
> + bool failed = fail;
> + unsigned int len;
> + int i, j = 0;
> +
> + for (i = 0; i < nr; i++) {
> + /* Detach the ith request from the vq */
> + req = virtqueue_get_buf(vq, &len);
> +
> + /*
> + * Condition (req && req == &reqs[i]) should always meet since
> + * we have total nr requests in the vq.
> + */
> + if (!failed && (WARN_ON(!(req && req == &reqs[i])) ||
> + (req->in_hdr.status != VIRTIO_I2C_MSG_OK)))
> + failed = true;
...and after failed is true, we are continuing the loop, why?
> + i2c_put_dma_safe_msg_buf(reqs[i].buf, &msgs[i], !failed);
> + if (!failed)
> + ++j;
Besides better to read j++ the j itself can be renamed to something more
verbose.
> + }
> + return (fail ? -ETIMEDOUT : j);
Redundant parentheses.
> +}
...
> + ret = virtio_i2c_send_reqs(vq, reqs, msgs, num);
> + if (ret != num) {
> + virtio_i2c_complete_reqs(vq, reqs, msgs, ret, true);
Below you check the returned code, here is not.
> + ret = 0;
> + goto err_free;
> + }
> +
> + reinit_completion(&vi->completion);
> + virtqueue_kick(vq);
> +
> + time_left = wait_for_completion_timeout(&vi->completion, adap->timeout);
> + if (!time_left)
> + dev_err(&adap->dev, "virtio i2c backend timeout.\n");
> +
> + ret = virtio_i2c_complete_reqs(vq, reqs, msgs, num, !time_left);
> +
> +err_free:
> + kfree(reqs);
> + return ret;
> +++ b/include/uapi/linux/virtio_i2c.h
> +#include <linux/types.h>
> +
> +/* The bit 0 of the @virtio_i2c_out_hdr.@flags, used to group the requests */
> +#define VIRTIO_I2C_FLAGS_FAIL_NEXT BIT(0)
It's _BITUL() or so from linux/const.h.
https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/const.h#L28
You may not use internal definitions in UAPI headers.
--
With Best Regards,
Andy Shevchenko
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
next prev parent reply other threads:[~2021-07-02 9:58 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-02 8:46 [PATCH v12] i2c: virtio: add a virtio i2c frontend driver Jie Deng
2021-07-02 8:46 ` Jie Deng
2021-07-02 9:58 ` Andy Shevchenko [this message]
2021-07-02 9:58 ` Andy Shevchenko
2021-07-02 23:01 ` Wolfram Sang
2021-07-05 2:43 ` Viresh Kumar
2021-07-05 2:43 ` Viresh Kumar
2021-07-05 3:01 ` Jie Deng
2021-07-05 3:01 ` Jie Deng
2021-07-05 6:21 ` Jie Deng
2021-07-05 6:21 ` Jie Deng
2021-07-05 6:31 ` Viresh Kumar
2021-07-05 6:31 ` Viresh Kumar
2021-07-05 3:46 ` Jie Deng
2021-07-05 3:46 ` Jie Deng
2021-07-05 2:40 ` Viresh Kumar
2021-07-05 2:40 ` Viresh Kumar
2021-07-05 3:45 ` Jie Deng
2021-07-05 3:45 ` Jie Deng
2021-07-05 4:38 ` Viresh Kumar
2021-07-05 4:38 ` Viresh Kumar
2021-07-05 6:22 ` Jie Deng
2021-07-05 6:22 ` Jie Deng
2021-07-05 6:30 ` Viresh Kumar
2021-07-05 6:30 ` Viresh Kumar
2021-07-05 7:13 ` Jie Deng
2021-07-05 7:13 ` Jie Deng
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=YN7jOm68fUL4UA2Q@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=arnd@arndb.de \
--cc=conghui.chen@intel.com \
--cc=jasowang@redhat.com \
--cc=jie.deng@intel.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=shuo.a.liu@intel.com \
--cc=stefanha@redhat.com \
--cc=viresh.kumar@linaro.org \
--cc=virtualization@lists.linux-foundation.org \
--cc=wsa+renesas@sang-engineering.com \
--cc=wsa@kernel.org \
--cc=yu1.wang@intel.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.