From: Marc Kleine-Budde <mkl@pengutronix.de>
To: "Eric Bénard" <eric@eukrea.com>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH v4 3/6] commands: add i2c commands
Date: Tue, 25 May 2010 11:32:40 +0200 [thread overview]
Message-ID: <4BFB9938.5020001@pengutronix.de> (raw)
In-Reply-To: <4BFB95C3.5090802@eukrea.com>
[-- Attachment #1.1: Type: text/plain, Size: 2569 bytes --]
Hey,
Eric Bénard wrote:
> Le 25/05/2010 11:02, Marc Kleine-Budde a écrit :
>>> + case 'b':
>>> + adapter = i2c_get_adapter(simple_strtoul(optarg, NULL, 0));
>>
>> I'd just save the optarg in a variable...
>>
>>> + break;
>>> + case 'v':
>>> + verbose = 1;
>>> + break;
>>> + }
>>> + }
>>> +
>>> + count = argc - optind;
>>> +
>>> + if ((addr< 0) || (reg< 0) || (count == 0) || (addr> 0x7F))
>>> + return COMMAND_ERROR_USAGE;
>>> +
>>> + if (!adapter)
>>> + adapter = i2c_get_adapter(0);
>>
>> and use it here. Because if you specify an invalid adapter number,
>> adapter 0 will be used silently (if it exists).
>>
> you're right, in fact I should exit in the case 'b' handling if the
> adapter doesn't exist, that will be simpler.
ACK, I'd do that here.....
int adapter_number = 0;
...
case 'b':
adapter_number = simple_strtoul(optarg, NULL, 0);
break;
...
adapter = i2c_get_adapter(adapter_number);
if (!adapter) {
printf("adapter %d not found\n", adapter_number);
return -ENODEV
}
>>> + if (!adapter)
>>> + return -ENODEV;
>>> +
>>> + client.adapter = adapter;
>>> + client.addr = addr;
>>> +
>>> + buf = xmalloc(count);
>>> + for (i = 0; i< count; i++)
>>> + *(buf + i) = (char) simple_strtol(argv[optind+i], NULL, 16);
codingstyle...no space after the cast, but before and after the "+"
(char)simple_strtol(argv[optind + i], NULL, 16);
>>> +
>>> + ret = i2c_write_reg(&client, reg, buf, count);
>>> + if (ret != count)
>>> + goto out;
>>
>> better set a return value indicating an error here...
> ret should already be set by i2c_write_reg so it there is no error, I
> can simply set ret to 0.
ACK
>>
>>> +
>>> + if (verbose) {
>>> + printf("wrote %i bytes starting at reg 0x%02x to i2cdev
>>> 0x%02x on bus %i\n",
>>> + count, reg, addr, adapter->nr);
>>> + for (i = 0; i< count; i++)
>>> + printf("0x%02x ", *(buf + i));
>>> + printf("\n");
>>> + }
>>> +
>>> +out:
>>> + free(buf);
>>> + return 0;
>>
>> ... and return it here.
>
> yes, that should be return ret
>
> Eric
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Industrial Linux Solutions | Phone: +49-231-2826-924 |
Vertretung West/Dortmund | Fax: +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 260 bytes --]
[-- Attachment #2: Type: text/plain, Size: 149 bytes --]
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2010-05-25 9:32 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-25 8:37 [PATCH 1/6] i2c-imx: change log level for No ACK Eric Bénard
2010-05-25 8:37 ` [PATCH v2 2/6] i2c: implement i2c_get_adapter() Eric Bénard
2010-05-25 8:37 ` [PATCH v4 3/6] commands: add i2c commands Eric Bénard
2010-05-25 8:37 ` [PATCH 4/6] eukrea_cpuimx27: add fb support Eric Bénard
2010-05-25 8:37 ` [PATCH 5/6] eukrea_cpuimx27: update env Eric Bénard
2010-05-25 8:37 ` [PATCH 6/6] eukrea_cpuimx27: update defconfig Eric Bénard
2010-05-25 9:02 ` [PATCH v4 3/6] commands: add i2c commands Marc Kleine-Budde
2010-05-25 9:17 ` Eric Bénard
2010-05-25 9:32 ` Marc Kleine-Budde [this message]
2010-05-25 9:43 ` Eric Bénard
2010-05-25 9:47 ` Marc Kleine-Budde
2010-05-25 9:57 ` Eric Bénard
2010-05-25 9:25 ` [PATCH v5] " Eric Bénard
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=4BFB9938.5020001@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=eric@eukrea.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox