hwmon: add new hwmon-core interface
PATCH 1/2 hwmon: add new hwmon-core interface
This adds a new hwmon-core interface to centralize sysfs handling and enable cooperation with other in-kernel drivers.
v3:
- checkpatch clean
v4:
- more flexible interface to allow different capabilities for every sensor and holes in sensor numbering
- corrected a few oversights
- split out vid and vrm handling as separate feature
- support 2d attributes for trip point and treshold handling
--- drivers/hwmon/Makefile | 1 + drivers/hwmon/hwmon-core.c | 511 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/hwmon-core.h | 229 ++++++++++++++++++++ 3 files changed, 741 insertions(+), 0 deletions(-) create mode 100644 drivers/hwmon/hwmon-core.c create mode 100644 include/linux/hwmon-core.h
drivers/hwmon/Makefile +1 -0
@@ -3,6 +3,7 @@ # obj-$(CONFIG_HWMON) += hwmon.o +obj-$(CONFIG_HWMON) += hwmon-core.o obj-$(CONFIG_HWMON_VID) += hwmon-vid.o # APCI drivers
drivers/hwmon/hwmon-core.c new file +508 -0
508 lines not on this page · raw message
include/linux/hwmon-core.h new file +229 -0
229 lines not on this page · raw message
Signature · 7 lines
1.7.7.3 _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Hi Lucas,
Quoted 6 lines · Lucas Stach
This adds a new hwmon-core interface to centralize sysfs handling and enable cooperation with other in-kernel drivers.
v3:
- checkpatch clean
Quoted 8 lines
v4:
- more flexible interface to allow different capabilities for every sensor and holes in sensor numbering
- corrected a few oversights
- split out vid and vrm handling as separate feature
- support 2d attributes for trip point and treshold handlingSigned-off-by Lucas Stach <[email protected]>
Couple of high level comments:
inX numbering starts with 0, not 1. You'll have to take that into account.
You can not determine based on the attribute type or name that or if a write function exists or not. This really depends on the driver. So there has to be a means to set file permissions per driver and per attribute. Returning -EINVAL in the set function in that case is not an option; the write capability has to be reflected in file permissions. Note that some attributes may have dynamic permissions using is_visible from struct attribute_group.
You'll have to describe the API somewhere, including expected return codes from access functions. You should not use -EINVAL if an attempt is made to access an unsupported attribute type; maybe -EOPNOTSUPP.
It is not a good idea to mandate that all access functions always exist. If there is no text read function, or if there is no set function, a driver should not have to provide a dummy one. Otherwise, most drivers would have to provide dummy text read functions just to return -E<Something>, and many drivers would have to provide dummy set functions for the same reason. It should be up to the core code to determine if access functions exist or not, and set permissions accordingly.
I don't fully understand the need for an use of enum entry_count. Please elaborate.
Number of memory allocations in the adt7475 driver initialization is a bit excessive. Looks like the overall amount of code is now less, but initialization code is way more complex than it used to be. This makes driver development more complex, not less complex.
In your sample driver, you have created race conditions by calling hwmon_device_register() early. The call to hwmon_device_register() must be the last call in the probe function, after everything else is done. Not sure if that is a new requirement, but it is definitely not correct. Besides, you have introduced some errors there - if the subsequent sysfs_create_file() fails, you bail out, but you don't call hwmon_device_unregister() (or hwmon_destroy_sysfs, for that matter). Besides, it doesn't make sense to try to delete the file you just failed to create. And during unregistration, you actually free all mmeory prior to calling hwmon_device_unregister(). That will cause some nice crashes ;). That will require some cleanup work.
Coding style:
- Some unnecessary ().
- Watch for Chapter 7 violations.
Thanks,
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 15 lines · Lucas Stach
This adds a new hwmon-core interface to centralize sysfs handling and enable cooperation with other in-kernel drivers.
v3:
- checkpatch cleanv4:
- more flexible interface to allow different capabilities for every sensor and holes in sensor numbering
- corrected a few oversights
- split out vid and vrm handling as separate feature
- support 2d attributes for trip point and treshold handlingSigned-off-by Lucas Stach <[email protected]>---
[ ... ]
drivers/hwmon/hwmon-core.c line 414
Quoted 9 lines
drivers/hwmon/hwmon-core.c new file +9
-0+ + hw_dev_attr->sensor_dev.dev_attr.attr.mode = mode; +if (mode &&S_IRUGO ) { +if (type = value) + hw_dev_attr->sensor_dev.dev_attr.show = &get_num; +else + hw_dev_attr->sensor_dev.dev_attr.show = &get_text; + } +if (mode &&S_IWUGO )
This and "mode && SIRUGO" look wrong and don't make much sense. Guess you mean & ?
[ ... ]
include/linux/hwmon-core.h line 222
Quoted 13 lines
include/linux/hwmon-core.h new file +13
-0+ +struct hwmon_device_instance { +struct hwmon_device_caps caps; +int (*get_numeric_attr) (struct device *hw_device, +enum hwmon_feature feature,u32 subfeature,u8 index, +u8 nr,int *value); +int (*set_numeric_attr) (struct device *hw_device, +enum hwmon_feature feature,u32 subfeature,u8 index, +u8 nr,int value); +int (*get_text_attr) (struct device *hw_device, +enum hwmon_feature feature,u32 subfeature,u8 index, +char *buf); +struct list_head sysfs_node;
Looks like sysfs_node is used internally by the core code, and not by the driver. If so, it should not be exported.
Regarding inst_data, I think it would be better to keep the current approach with a local data structure, and reference hwinst from it. So you would have
data->hw_inst = hw_inst; i2c_set_clientdata(client, data); and data = i2c_get_clientdata(client); hw_inst = data->hw_inst;
To avoid the many mallocs in the probe function, maybe it would be possible to pass the various parameters to hwmon_create_sysfs() and have it return a pointer to hw_inst. Just an idea.
Thanks,
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors