Changeset 5092

Show
Ignore:
Timestamp:
01/05/08 13:31:55 (6 years ago)
Author:
khali
Message:

Get the device type from the subsystem symlink, rather than
guessing it from how the device identifier looks like. For kernels
<= 2.6.17, we use the bus symlink instead. For kernels <= 2.6.11,
neither symlink exist so we fallback to the old type guessing
approach. It doesn't really matter as all hwmon devices were
i2c devices back then.

Location:
lm-sensors/branches/lm-sensors-3.0.0
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/branches/lm-sensors-3.0.0/CHANGES

    r5090 r5092  
    44SVN 
    55  documentation: Update the application writing guidelines 
    6   libsensors: No longer depend on libsysfs 
     6  libsensors: No longer depend on libsysfs (#2262) 
     7              Don't guess the bus type from the device ID format (#2240) 
    78  Makefile: No warnings about ld configuration for staged installations 
    89  pwmconfig: Really hide errors on sysfs writes 
  • lm-sensors/branches/lm-sensors-3.0.0/lib/sysfs.c

    r5075 r5092  
    462462        char *bus_attr; 
    463463        char bus_path[NAME_MAX]; 
     464        char linkpath[NAME_MAX]; 
     465        char subsys_path[NAME_MAX], *subsys; 
     466        int sub_len; 
    464467        sensors_chip_features entry; 
    465468 
     
    472475                sensors_fatal_error(__FUNCTION__, "out of memory"); 
    473476 
    474         if (sscanf(dev_name, "%hd-%x", &entry.chip.bus.nr, &entry.chip.addr) == 2) { 
     477        /* Find bus type */ 
     478        snprintf(linkpath, NAME_MAX, "%s/subsystem", dev_path); 
     479        sub_len = readlink(linkpath, subsys_path, NAME_MAX - 1); 
     480        if (sub_len < 0 && errno == ENOENT) { 
     481                /* Fallback to "bus" link for kernels <= 2.6.17 */ 
     482                snprintf(linkpath, NAME_MAX, "%s/bus", dev_path); 
     483                sub_len = readlink(linkpath, subsys_path, NAME_MAX - 1); 
     484        } 
     485        if (sub_len < 0) { 
     486                /* Older kernels (<= 2.6.11) have neither the subsystem 
     487                   symlink nor the bus symlink */ 
     488                if (errno == ENOENT) 
     489                        subsys = NULL; 
     490                else 
     491                        goto exit_free; 
     492        } else { 
     493                subsys_path[sub_len] = '\0'; 
     494                subsys = strrchr(subsys_path, '/') + 1; 
     495        } 
     496 
     497        if ((!subsys || !strcmp(subsys, "i2c")) && 
     498            sscanf(dev_name, "%hd-%x", &entry.chip.bus.nr, 
     499                   &entry.chip.addr) == 2) { 
    475500                /* find out if legacy ISA or not */ 
    476501                if (entry.chip.bus.nr == 9191) { 
     
    492517                        } 
    493518                } 
    494         } else if (sscanf(dev_name, "spi%hd.%d", &entry.chip.bus.nr, 
    495                           &entry.chip.addr) == 2) { 
     519        } else 
     520        if ((!subsys || !strcmp(subsys, "spi")) && 
     521            sscanf(dev_name, "spi%hd.%d", &entry.chip.bus.nr, 
     522                   &entry.chip.addr) == 2) { 
    496523                /* SPI */ 
    497524                entry.chip.bus.type = SENSORS_BUS_TYPE_SPI; 
    498         } else if (sscanf(dev_name, "%*[a-z0-9_].%d", &entry.chip.addr) == 1) { 
     525        } else 
     526        if ((!subsys || !strcmp(subsys, "platform"))) { 
    499527                /* must be new ISA (platform driver) */ 
     528                if (sscanf(dev_name, "%*[a-z0-9_].%d", &entry.chip.addr) != 1) 
     529                        entry.chip.addr = 0; 
    500530                entry.chip.bus.type = SENSORS_BUS_TYPE_ISA; 
    501531                entry.chip.bus.nr = 0; 
    502         } else if (sscanf(dev_name, "%x:%x:%x.%x", &domain, &bus, &slot, &fn) == 4) { 
     532        } else 
     533        if ((!subsys || !strcmp(subsys, "pci")) && 
     534            sscanf(dev_name, "%x:%x:%x.%x", &domain, &bus, &slot, &fn) == 4) { 
    503535                /* PCI */ 
    504536                entry.chip.addr = (domain << 16) + (bus << 8) + (slot << 3) + fn; 
     
    506538                entry.chip.bus.nr = 0; 
    507539        } else { 
    508                 /* platform device with no id? */ 
    509                 entry.chip.bus.type = SENSORS_BUS_TYPE_ISA; 
    510                 entry.chip.bus.nr = 0; 
    511                 entry.chip.addr = 0; 
     540                /* Ignore unknown device */ 
     541                err = 0; 
     542                goto exit_free; 
    512543        } 
    513544