History

hwmon: (sysfs) Allow drivers to register const attributes

Switch to the __DEVICE_ATTR() macro which can handle callbacks taking both const and non-const attribute structure arguments. Allow the step-wise migration of the drivers. Also use container_of_const() over container_of() to avoid casting away the constness accidentally.

Thomas Weißschuh committed 3 months ago

Commit 87fdc8d1 parent 52fcdd52 files · +10 −10Browse files

Unified · Split

2 files
  1. drivers/hwmon/hwmon.c +3 −3
  2. include/linux/hwmon-sysfs.h +7 −7
drivers/hwmon/hwmon.c+3−3
@@ -341,7 +341,7 @@ static int hwmon_match_device(struct device *dev, const void *data) · 340 unmodified lines
341 return dev->class == &hwmon_class;341 return dev->class == &hwmon_class;
342}342}
343 343
344static ssize_t pec_show(struct device *dev, struct device_attribute *dummy,344static ssize_t pec_show(struct device *dev, const struct device_attribute *dummy,
345 char *buf)345 char *buf)
346{346{
347 struct i2c_client *client = to_i2c_client(dev);347 struct i2c_client *client = to_i2c_client(dev);
@@ -349,7 +349,7 @@ static ssize_t pec_show(struct device *dev, struct device_attribute *dummy, · 1 unmodified line
349 return sysfs_emit(buf, "%d\n", !!(client->flags & I2C_CLIENT_PEC));349 return sysfs_emit(buf, "%d\n", !!(client->flags & I2C_CLIENT_PEC));
350}350}
351 351
352static ssize_t pec_store(struct device *dev, struct device_attribute *devattr,352static ssize_t pec_store(struct device *dev, const struct device_attribute *devattr,
353 const char *buf, size_t count)353 const char *buf, size_t count)
354{354{
355 struct i2c_client *client = to_i2c_client(dev);355 struct i2c_client *client = to_i2c_client(dev);
@@ -390,7 +390,7 @@ put: · 34 unmodified lines
390 return err;390 return err;
391}391}
392 392
393static DEVICE_ATTR_RW(pec);393static const DEVICE_ATTR_RW(pec);
394 394
395static void hwmon_remove_pec(void *dev)395static void hwmon_remove_pec(void *dev)
396{396{
include/linux/hwmon-sysfs.h+7−7
@@ -15,10 +15,10 @@ struct sensor_device_attribute{ · 14 unmodified lines
15 int index;15 int index;
16};16};
17#define to_sensor_dev_attr(_dev_attr) \17#define to_sensor_dev_attr(_dev_attr) \
18 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)18 container_of_const(_dev_attr, struct sensor_device_attribute, dev_attr)
19 19
20#define SENSOR_ATTR(_name, _mode, _show, _store, _index) \20#define SENSOR_ATTR(_name, _mode, _show, _store, _index) \
21 { .dev_attr = __ATTR(_name, _mode, _show, _store), \21 { .dev_attr = __DEVICE_ATTR(_name, _mode, _show, _store), \
22 .index = _index }22 .index = _index }
23 23
24#define SENSOR_ATTR_RO(_name, _func, _index) \24#define SENSOR_ATTR_RO(_name, _func, _index) \
@@ -49,11 +49,11 @@ struct sensor_device_attribute_2 { · 24 unmodified lines
49 u8 nr;49 u8 nr;
50};50};
51#define to_sensor_dev_attr_2(_dev_attr) \51#define to_sensor_dev_attr_2(_dev_attr) \
52 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)52 container_of_const(_dev_attr, struct sensor_device_attribute_2, dev_attr)
53 53
54#define SENSOR_ATTR_2(_name, _mode, _show, _store, _nr, _index) \54#define SENSOR_ATTR_2(_name, _mode, _show, _store, _nr, _index) \
55 { .dev_attr = __ATTR(_name, _mode, _show, _store), \55 { .dev_attr = __DEVICE_ATTR(_name, _mode, _show, _store), \
56 .index = _index, \56 .index = _index, \
57 .nr = _nr }57 .nr = _nr }
58 58
59#define SENSOR_ATTR_2_RO(_name, _func, _nr, _index) \59#define SENSOR_ATTR_2_RO(_name, _func, _nr, _index) \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t