mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Aleksander Morgado <aleksander@aleksander.es>
To: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Barebox List <barebox@lists.infradead.org>
Subject: Re: [PATCH 1/4] ratp: implement i2c read/write support
Date: Wed, 12 Sep 2018 11:25:09 +0200	[thread overview]
Message-ID: <CAAP7ucL34qTVQn+E=7GBiQ2kxEHyWFJsNeF4BVo=zP+x9HMh_A@mail.gmail.com> (raw)
In-Reply-To: <CAHQ1cqF3RA-EQ_NTtQtZgi+oJwGoCrTzG88O_=y3A5kYz4ueUQ@mail.gmail.com>

Hey Andrey,

Thanks for the review :) see some comments below.

>> +       /* Don't read anything on error or if 0 bytes were requested */
>> +       if (size > 0) {
>> +               adapter = i2c_get_adapter(i2c_read_req->bus);
>> +               if (!adapter) {
>> +                       printf("ratp i2c read ignored: i2c bus %u not found\n", i2c_read_req->bus);
>> +                       ret = -ENODEV;
>> +                       goto out;
>> +               }
>> +
>> +               client.adapter = adapter;
>> +               client.addr = i2c_read_req->addr;
>> +
>> +               if (i2c_read_req->flags & I2C_FLAG_MASTER_MODE) {
>> +                       ret = i2c_master_recv(&client, i2c_read_rsp->buffer, size);
>> +               } else {
>> +                       ret = i2c_read_reg(&client, reg | wide, i2c_read_rsp->buffer, size);
>> +               }
>> +               if (ret != size) {
>> +                       printf("ratp i2c read ignored: not all bytes read (%u < %u)\n", ret, size);
>> +                       ret = -EIO;
>> +                       goto out;
>> +               }
>> +               ret = 0;
>> +       }
>> +
>> +out:
>> +       if (ret != 0) {
>> +               i2c_read_rsp->data_size = 0;
>> +               i2c_read_rsp->errno = cpu_to_be32(ret);
>> +               i2c_read_rsp_len = sizeof(*i2c_read_rsp);
>> +       } else {
>> +               i2c_read_rsp->data_size = cpu_to_be16(size);
>> +               i2c_read_rsp->errno = 0;
>> +       }
>> +
>
> It looks like you can move:
>
> i2c_read_rsp->data_size = cpu_to_be16(size);
> i2c_read_rsp->errno = cpu_to_be32(ret);
>
> outside of if since it should work as intended for both cases (size is
> 0 if ret != 0).
>

Don't think I can do that. In the if (size > 0) {} just a bit above,
size is not modified but ret may become an error. We do want to make
sure 0 is returned as size when there is an error, so cannot move it
outside the if() as you suggest here.

-- 
Aleksander
https://aleksander.es

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2018-09-12  9:25 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-21 15:19 RATP i2c and GPIO support Aleksander Morgado
2018-08-21 15:19 ` [PATCH 1/4] ratp: implement i2c read/write support Aleksander Morgado
2018-08-21 19:38   ` Andrey Smirnov
2018-09-12  9:25     ` Aleksander Morgado [this message]
2018-08-22  7:46   ` Sascha Hauer
2018-08-23 20:54     ` Aleksander Morgado
2018-08-27  9:09       ` Sascha Hauer
2018-08-21 15:19 ` [PATCH 2/4] bbremote: " Aleksander Morgado
2018-08-21 15:20 ` [PATCH 3/4] ratp: implement support for GPIO commands Aleksander Morgado
2018-08-21 20:18   ` Andrey Smirnov
2018-08-22  7:52   ` Sascha Hauer
2018-08-21 15:20 ` [PATCH 4/4] bbremote: implement support for GPIO operations Aleksander Morgado

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='CAAP7ucL34qTVQn+E=7GBiQ2kxEHyWFJsNeF4BVo=zP+x9HMh_A@mail.gmail.com' \
    --to=aleksander@aleksander.es \
    --cc=andrew.smirnov@gmail.com \
    --cc=barebox@lists.infradead.org \
    /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