On Fri, Mar 26, 2021 at 8:14 AM Viresh Kumar <viresh.ku...@linaro.org> wrote:
> On 25-03-21, 17:16, Arnd Bergmann wrote:
> > On Wed, Mar 24, 2021 at 8:33 AM Viresh Kumar <viresh.ku...@linaro.org> 
> > wrote:

> >
> > It looks like you are not handling endianness conversion here. As far as I
> > can tell, the protocol requires little-endian data, but the code might
> > run on a big-endian CPU.
>
> I hope this is all we are required to do here, right ?
>
> @@ -442,7 +421,7 @@ static void vi2c_handle_ctrl(VuDev *dev, int qidx)
>          out_hdr = elem->out_sg[0].iov_base;
>
>          /* Bit 0 is reserved in virtio spec */
> -        msg.addr = out_hdr->addr >> 1;
> +        msg.addr = le16toh(out_hdr->addr) >> 1;
>
>          /* Read Operation */
>          if (elem->out_num == 1 && elem->in_num == 2) {
> @@ -489,7 +468,7 @@ static void vi2c_handle_ctrl(VuDev *dev, int qidx)
>          in_hdr->status = fail_next ? VIRTIO_I2C_MSG_ERR : vi2c_xfer(dev, 
> &msg);
>          if (in_hdr->status == VIRTIO_I2C_MSG_ERR) {
>              /* We need to fail remaining transfers as well */
> -            fail_next = out_hdr->flags & VIRTIO_I2C_FLAGS_FAIL_NEXT;
> +            fail_next = le32toh(out_hdr->flags) & VIRTIO_I2C_FLAGS_FAIL_NEXT;
>          }
>
> These are the only fields we are passing apart from buf, which goes
> directly to the client device.

I think so, the in_hdr is only one byte long, so it doesn't have an
endianness.

       Arnd

Reply via email to