Changeset 5093

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

Add support for drivers that place the hwmon attributes in the hwmon
class device directory rather than directly in the device directory.
The latter is what all drivers do at the moment, but in the long run
the former is preferred as it prevents attribute name collisions.

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

    r5092 r5093  
    66  libsensors: No longer depend on libsysfs (#2262) 
    77              Don't guess the bus type from the device ID format (#2240) 
     8              Add support for attributes in the hwmon class device (#2260) 
    89  Makefile: No warnings about ld configuration for staged installations 
    910  pwmconfig: Really hide errors on sysfs writes 
  • lm-sensors/branches/lm-sensors-3.0.0/lib/sysfs.c

    r5092 r5093  
    455455} 
    456456 
    457 /* returns: 0 if successful, !0 otherwise */ 
    458 static int sensors_read_one_sysfs_chip(const char *dev_path, const char *dev_name) 
     457/* returns: number of devices added (0 or 1) if successful, <0 otherwise */ 
     458static int sensors_read_one_sysfs_chip(const char *dev_path, 
     459                                       const char *dev_name, 
     460                                       const char *hwmon_path) 
    459461{ 
    460462        int domain, bus, slot, fn; 
     
    468470 
    469471        /* ignore any device without name attribute */ 
    470         if (!(entry.chip.prefix = sysfs_read_attr(dev_path, "name"))) 
     472        if (!(entry.chip.prefix = sysfs_read_attr(hwmon_path, "name"))) 
    471473                return 0; 
    472474 
    473         entry.chip.path = strdup(dev_path); 
     475        entry.chip.path = strdup(hwmon_path); 
    474476        if (!entry.chip.path) 
    475477                sensors_fatal_error(__FUNCTION__, "out of memory"); 
     
    543545        } 
    544546 
    545         if (sensors_read_dynamic_chip(&entry, dev_path) < 0) 
     547        if (sensors_read_dynamic_chip(&entry, hwmon_path) < 0) 
    546548                goto exit_free; 
    547549        if (!entry.subfeature) { /* No subfeature, discard chip */ 
     
    551553        sensors_add_proc_chips(&entry); 
    552554 
    553         return 0; 
     555        return 1; 
    554556 
    555557exit_free: 
     
    559561} 
    560562 
     563static int sensors_add_hwmon_device_compat(const char *path, 
     564                                           const char *dev_name) 
     565{ 
     566        int err; 
     567 
     568        err = sensors_read_one_sysfs_chip(path, dev_name, path); 
     569        if (err < 0) 
     570                return err; 
     571        return 0; 
     572} 
     573 
    561574/* returns 0 if successful, !0 otherwise */ 
    562575static int sensors_read_sysfs_chips_compat(void) 
     
    564577        int ret; 
    565578 
    566         ret = sysfs_foreach_busdev("i2c", sensors_read_one_sysfs_chip); 
     579        ret = sysfs_foreach_busdev("i2c", sensors_add_hwmon_device_compat); 
    567580        if (ret && ret != ENOENT) 
    568581                return -SENSORS_ERR_KERNEL; 
     
    574587{ 
    575588        char linkpath[NAME_MAX]; 
    576         char device[NAME_MAX]; 
    577         int dev_len; 
     589        char device[NAME_MAX], *device_p; 
     590        int dev_len, err; 
    578591        (void)classdev; /* hide warning */ 
    579592 
     
    583596                return -SENSORS_ERR_KERNEL; 
    584597        device[dev_len] = '\0'; 
    585  
    586         return sensors_read_one_sysfs_chip(linkpath, strrchr(device, '/') + 1); 
     598        device_p = strrchr(device, '/') + 1; 
     599 
     600        /* The attributes we want might be those of the hwmon class device, 
     601           or those of the device itself. */ 
     602        err = sensors_read_one_sysfs_chip(linkpath, device_p, path); 
     603        if (err == 0) 
     604                err = sensors_read_one_sysfs_chip(linkpath, device_p, linkpath); 
     605        if (err < 0) 
     606                return err; 
     607        return 0; 
    587608} 
    588609