[RFC][PATCHv2] new applets: i2c-tools

Xabier Oneca -- xOneca xoneca at gmail.com
Thu Dec 11 23:09:55 UTC 2014


Hello,
2014-12-11 23:41 GMT+01:00 tito <farmatito at tiscali.it>:
> On Thursday 11 December 2014 21:50:56 walter harms wrote:
>>
>> Am 11.12.2014 16:36, schrieb Bartosz Golaszewski:
[...]
>> > +/* Opens the device file associated with given i2c bus. */
>> > +static int i2c_dev_open(int i2cbus)
>> > +{
>> > +   char filename[32];
>> > +   int fd;
>> > +
>> > +   snprintf(filename, sizeof(filename), "/dev/i2c-%d", i2cbus);
>> > +   fd = open_or_warn(filename, O_RDWR);
>>
>> now user of "/dev/i2c/%d" get warning here even when the next open works.
>> I do not think that this was you intention.
>>
>> /* having one open is more easy :) */
>>
>> just my 2 cents,
>>  wh
>
> Hi,
> I think that this is better than having an error message like this:
>
> f (fd < 0)
>              bb_perror_msg_and_die("Could not open file: /dev/i2c-%d or /dev/i2c/%d", i2cbus, i2cbus);
>
> and not knowing exactly which device you was not able to open.
>
> Ciao,
> Tito
>
>> > +   if (fd < 0 && errno == ENOENT) {
>> > +           snprintf(filename, sizeof(filename), "/dev/i2c/%d", i2cbus);
>> > +           fd = xopen(filename, O_RDWR);
>> > +   }
[...]

If you mistype 'i2cbus' parameter in the command line, you will have
both a warning and an error opening two devices, which can be
misleading.

Why would you even try to open the old-style device in a new kernel,
or a new-style dev in an old one? I think this can be avoided with the
usual '#if LINUX_VERSION ...', be it with preprocessor instructions,
or with a plain 'if ... else' statement.

Cheers,

Xabier Oneca_,,_


More information about the busybox mailing list