mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-28 00:35:00 -04:00
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. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Link: https://lore.kernel.org/r/20260806-sysfs-const-attr-hwmon-v2-3-22fee8b85509@weissschuh.net [groeck: Squashed 'hwmon: (core) Constify PEC device attribute'] Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
committed by
Guenter Roeck
parent
52fcdd5639
commit
87fdc8d7bb
@@ -341,7 +341,7 @@ static int hwmon_match_device(struct device *dev, const void *data)
|
||||
return dev->class == &hwmon_class;
|
||||
}
|
||||
|
||||
static ssize_t pec_show(struct device *dev, struct device_attribute *dummy,
|
||||
static ssize_t pec_show(struct device *dev, const struct device_attribute *dummy,
|
||||
char *buf)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
@@ -349,7 +349,7 @@ static ssize_t pec_show(struct device *dev, struct device_attribute *dummy,
|
||||
return sysfs_emit(buf, "%d\n", !!(client->flags & I2C_CLIENT_PEC));
|
||||
}
|
||||
|
||||
static ssize_t pec_store(struct device *dev, struct device_attribute *devattr,
|
||||
static ssize_t pec_store(struct device *dev, const struct device_attribute *devattr,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
@@ -390,7 +390,7 @@ static ssize_t pec_store(struct device *dev, struct device_attribute *devattr,
|
||||
return err;
|
||||
}
|
||||
|
||||
static DEVICE_ATTR_RW(pec);
|
||||
static const DEVICE_ATTR_RW(pec);
|
||||
|
||||
static void hwmon_remove_pec(void *dev)
|
||||
{
|
||||
|
||||
@@ -15,10 +15,10 @@ struct sensor_device_attribute{
|
||||
int index;
|
||||
};
|
||||
#define to_sensor_dev_attr(_dev_attr) \
|
||||
container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
|
||||
container_of_const(_dev_attr, struct sensor_device_attribute, dev_attr)
|
||||
|
||||
#define SENSOR_ATTR(_name, _mode, _show, _store, _index) \
|
||||
{ .dev_attr = __ATTR(_name, _mode, _show, _store), \
|
||||
#define SENSOR_ATTR(_name, _mode, _show, _store, _index) \
|
||||
{ .dev_attr = __DEVICE_ATTR(_name, _mode, _show, _store), \
|
||||
.index = _index }
|
||||
|
||||
#define SENSOR_ATTR_RO(_name, _func, _index) \
|
||||
@@ -49,11 +49,11 @@ struct sensor_device_attribute_2 {
|
||||
u8 nr;
|
||||
};
|
||||
#define to_sensor_dev_attr_2(_dev_attr) \
|
||||
container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
|
||||
container_of_const(_dev_attr, struct sensor_device_attribute_2, dev_attr)
|
||||
|
||||
#define SENSOR_ATTR_2(_name, _mode, _show, _store, _nr, _index) \
|
||||
{ .dev_attr = __ATTR(_name, _mode, _show, _store), \
|
||||
.index = _index, \
|
||||
#define SENSOR_ATTR_2(_name, _mode, _show, _store, _nr, _index) \
|
||||
{ .dev_attr = __DEVICE_ATTR(_name, _mode, _show, _store), \
|
||||
.index = _index, \
|
||||
.nr = _nr }
|
||||
|
||||
#define SENSOR_ATTR_2_RO(_name, _func, _nr, _index) \
|
||||
|
||||
Reference in New Issue
Block a user