mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: "Eric Bénard" <eric@eukrea.com>
To: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH v4 3/6] commands: add i2c commands
Date: Tue, 25 May 2010 11:17:55 +0200	[thread overview]
Message-ID: <4BFB95C3.5090802@eukrea.com> (raw)
In-Reply-To: <4BFB9224.9030507@pengutronix.de>

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.

>> +	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);
>> +
>> +	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.
>
>> +
>> +	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

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

  reply	other threads:[~2010-05-25  9:18 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 [this message]
2010-05-25  9:32         ` Marc Kleine-Budde
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=4BFB95C3.5090802@eukrea.com \
    --to=eric@eukrea.com \
    --cc=barebox@lists.infradead.org \
    --cc=mkl@pengutronix.de \
    /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