hwmon: (ads1015) Drop dynamic attribute group
It is cheaper to handle attributes individually.
---
In my tests, my version saves 14 bytes on the binary driver, plus 96 bytes of alloc'd memory per device (struct ads1015_data size is down from 136 bytes to 40 bytes on x86-64.)
Dirk, I will leave it up to you whether we apply this patch or not. Oh, and by the way, I would appreciate if you could add yourself to MAINTAINERS as the maintainer of the ads1015 driver.
drivers/hwmon/ads1015.c | 50 ++++++++++++++++------------------------------- 1 file changed, 18 insertions(+), 32 deletions(-)
drivers/hwmon/ads1015.c +18 -32
@@ -51,8 +51,6 @@ static const unsigned int fullscale_tablstruct ads1015_data {struct device *hwmon_dev;struct mutex update_lock;/* mutex protect updates */ -struct attribute *attr_table[ADS1015_CONFIG_CHANNELS +1 ]; -struct attribute_group attr_group; };static s32 ads1015_read_reg (struct i2c_client *client,unsigned int reg)
@@ -141,28 +139,15 @@ static ssize_t show_in(struct device *dereturn (res <0 ) ? res :sprintf (buf,"%d\n" , in); } -#define in_reg (offset)\ -static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in,\ - NULL, offset) - -in_reg (0 ); -in_reg (1 ); -in_reg (2 ); -in_reg (3 ); -in_reg (4 ); -in_reg (5 ); -in_reg (6 ); -in_reg (7 ); - -static struct attribute *all_attributes[] = { - &sensor_dev_attr_in0_input.dev_attr.attr, - &sensor_dev_attr_in1_input.dev_attr.attr, - &sensor_dev_attr_in2_input.dev_attr.attr, - &sensor_dev_attr_in3_input.dev_attr.attr, - &sensor_dev_attr_in4_input.dev_attr.attr, - &sensor_dev_attr_in5_input.dev_attr.attr, - &sensor_dev_attr_in6_input.dev_attr.attr, - &sensor_dev_attr_in7_input.dev_attr.attr, +static const struct sensor_device_attribute ads1015_in[] = { +SENSOR_ATTR (in0_input,S_IRUGO , show_in,NULL ,0 ), +SENSOR_ATTR (in1_input,S_IRUGO , show_in,NULL ,1 ), +SENSOR_ATTR (in2_input,S_IRUGO , show_in,NULL ,2 ), +SENSOR_ATTR (in3_input,S_IRUGO , show_in,NULL ,3 ), +SENSOR_ATTR (in4_input,S_IRUGO , show_in,NULL ,4 ), +SENSOR_ATTR (in5_input,S_IRUGO , show_in,NULL ,5 ), +SENSOR_ATTR (in6_input,S_IRUGO , show_in,NULL ,6 ), +SENSOR_ATTR (in7_input,S_IRUGO , show_in,NULL ,7 ), };/*
@@ -172,8 +157,11 @@ static struct attribute *all_attributes[static int ads1015_remove (struct i2c_client *client) {struct ads1015_data *data =i2c_get_clientdata (client); +int k; +hwmon_device_unregister (data->hwmon_dev); -sysfs_remove_group (&client->dev.kobj, &data->attr_group); +for (k =0 ; k <ADS1015_CONFIG_CHANNELS ; ++k) +device_remove_file (&client->dev, &ads1015_in[k].dev_attr);kfree (data);return 0 ; }
@@ -210,7 +198,6 @@ static int ads1015_probe(struct i2c_clieint err;unsigned int exported_channels;unsigned int k; -unsigned int n =0 ; data =kzalloc (sizeof (struct ads1015_data ),GFP_KERNEL );if (!data) {
@@ -222,16 +209,14 @@ static int ads1015_probe(struct i2c_cliemutex_init (&data->update_lock);/* build sysfs attribute group */ - data->attr_group.attrs = data->attr_table; exported_channels =ads1015_get_exported_channels (client);for (k =0 ; k <ADS1015_CONFIG_CHANNELS ; ++k) {if (!(exported_channels & (1 <<k)))continue ; - data->attr_table[n++] = all_attributes[k]; + err =device_create_file (&client->dev, &ads1015_in[k].dev_attr); +if (err) + goto exit_free; } - err =sysfs_create_group (&client->dev.kobj, &data->attr_group); -if (err) - goto exit_free; data->hwmon_dev =hwmon_device_register (&client->dev);if (IS_ERR (data->hwmon_dev)) {
@@ -242,7 +227,8 @@ static int ads1015_probe(struct i2c_cliereturn 0 ; exit_remove: -sysfs_remove_group (&client->dev.kobj, &data->attr_group); +for (k =0 ; k <ADS1015_CONFIG_CHANNELS ; ++k) +device_remove_file (&client->dev, &ads1015_in[k].dev_attr); exit_free:kfree (data); exit:
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 3 lines
Dirk, I will leave it up to you whether we apply this patch or not. Oh, and by the way, I would appreciate if you could add yourself to
MAINTAINERSas the maintainer of the ads1015 driver.
Jean, please apply. It is indeed much simpler than my version and seems to be sufficiently foolproof ;)
Sometimes the obvious is so hard to see ...
I will send a patch for MAINTAINERS.
Cheers
Dirk
------------------------------------------------------------------------------------------------
Messe-Highlights 2011. Wir freuen uns auf Ihren Besuch.
CeBIT 2011
In Hannover - 01.03. bis 05.03.2011 - Halle 12, Stand C50
ATC Global 2011
Amsterdam - 08.03. bis 10.03.2011 - Halle 9, Stand R404
------------------------------------------------------------------------------------------------
Guntermann & Drunck GmbH Systementwicklung
Dortmunder Str. 4a
D-57234 Wilnsdorf - Germany
Tel: +49 (0) 27 39 / 89 01 - 100 Fax: +49 (0) 27 39 / 89 01 - 120
E-Mail: [email protected] - Web: www.gdsys.de
------------------------------------------------------------------------------------------------
Geschaftsfuhrer:
Udo Guntermann - Martin Drunck - Reiner Ruelmann - Klaus Tocke HRB 2884, Amtsgericht Siegen - WEEE-Reg.-Nr. DE30763240 USt.-Id.-Nr. DE 126575222 - Steuer-Nr. 342 / 5835 / 1041
------------------------------------------------------------------------------------------------
DQS-zertifiziert nach ISO 9001:2000
------------------------------------------------------------------------------------------------
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors