Skip to contentSkip to conversation

i2c-tools: do not fail opening bus if /dev/i2c

PATCH In review Florian Fainelli 3 participants 3 messages Aug 18, 2010 2 messages not in the archive I2C subsystem host drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c-tools: do not fail opening bus if /dev/i2c

In case /dev/i2c is not a directory, open_i2c_dev will fail opening /dev/i2c/<i2cbus> but only handles the ENOENT errno, while we should also handle ENOTDIR errno because this is the returned error code. The patch attached fixes the issue.

--
Index: tools/i2cbusses.c
=================================--- tools/.svn/text-base/i2cbusses.c.svn-base 2010-08-18 14:22:18.000000000 +0200
+++ /tmp/tempfile.2.tmp 2010-08-18 14:33:12.000000000 +0200
@@ -378,7 +378,7 @@
sprintf(filename, "/dev/i2c/%d", i2cbus);
file = open(filename, O_RDWR);

- if (file < 0 && errno = ENOENT) {
+ if (file < 0 && (errno = ENOENT || errno = ENOTDIR)) {
sprintf(filename, "/dev/i2c-%d", i2cbus); file = open(filename, O_RDWR);
}

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

A message that is not in the archive (sent off-list or not yet received): 201008181433.50995.ffainelli-MmRyKUhfbQ9GWvitb5QawA@public.gmane.org

#2 lore raw

Re: [PATCH] i2c-tools: do not fail opening bus if /dev/i2c is not a directory

Hi Florian,

Quoted 4 lines · Florian Fainelli

In case /dev/i2c is not a directory, open_i2c_dev will fail opening /dev/i2c/<i2cbus> but only handles the ENOENT errno, while we should also handle ENOTDIR errno because this is the returned error code. The patch attached fixes the issue.

This is better discussed on the linux-i2c list. Redirecting...

tmp/tempfile.2.tmp

Quoted 6 lines

--
Index: tools/i2cbusses.c
===================================================================

tmp/tempfile.2.tmp renamed from .svn/text-base/i2cbusses.c.svn-base +0 -0

What a ugly header. How am I supposed to apply this?

tmp/tempfile.2.tmp line 384

Quoted 10 lines
tmp/tempfile.2.tmp renamed from .svn/text-base/i2cbusses.c.svn-base +1 -1
@@ -378,7 +378,7 @@
 	sprintf(filename, "/dev/i2c/%d", i2cbus);
 	file = open(filename, O_RDWR);
 
-	if (file < 0 && errno == ENOENT) {
+	if (file < 0 && (errno == ENOENT || errno == ENOTDIR)) {
 		sprintf(filename, "/dev/i2c-%d", i2cbus);
 		file = open(filename, O_RDWR);
 	}

I've never seen the case where /dev/i2c exists but isn't a directory (which is why that case isn't handled.) How did you get in this situation? It doesn't make much sense IMHO.

That being said, we can certainly apply your patch if it makes you happy, I don't see it as being terribly useful, but it also shouldn't hurt.

Signature · 1 line
Jean Delvare

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

Re: [PATCH] i2c-tools: do not fail opening bus if /dev/i2c is not a directory

Hi Jean,

Quoted 26 lines · ----- "Jean Delvare

Hi Florian,

Quoted 2 lines · Florian Fainelli

In case /dev/i2c is not a directory, open_i2c_dev will fail opening /dev/i2c/<i2cbus> but only handles the ENOENT errno, while we should

also

Quoted 1 line

handle ENOTDIR errno because this is the returned error code. The

patch

Quoted 1 line

attached fixes the issue.

This is better discussed on the linux-i2c list. Redirecting...

Quoted 5 lines

--
Index: tools/i2cbusses.c
===================================================================
--- tools/.svn/text-base/i2cbusses.c.svn-base 2010-08-18

14:22:18.000000000 +0200

Quoted 1 line

+++ /tmp/tempfile.2.tmp 2010-08-18 14:33:12.000000000 +0200

What a ugly header. How am I supposed to apply this?

Quoted 4 lines
(quoted diff) +0 -0
@@ -378,7 +378,7 @@
 	sprintf(filename, "/dev/i2c/%d", i2cbus);
 	file = open(filename, O_RDWR);
 
Quoted 10 lines

Review line 384

Quoted 6 lines
(quoted diff) +1 -1
-	if (file < 0 && errno == ENOENT) {
+	if (file < 0 && (errno == ENOENT || errno == ENOTDIR)) {
 		sprintf(filename, "/dev/i2c-%d", i2cbus);
 		file = open(filename, O_RDWR);
 	}

I've never seen the case where /dev/i2c exists but isn't a directory (which is why that case isn't handled.) How did you get in this situation? It doesn't make much sense IMHO.

Well, I got another driver here living at /dev/i2c which I am slowly migrating, but I would like to have i2cdetect working anyway ;)

Quoted 4 lines

That being said, we can certainly apply your patch if it makes you happy, I don't see it as being terribly useful, but it also shouldn't hurt.

I would be glad if you apply it. Thanks!
--
Florian