hwmon: (adt7475) Change show functions to return error data correctly
Change update device function to return an error pointer if needed, and report the error to user space. Signed-off-by: Tokunori Ikegami <ikegami@allied-telesis.co.jp> Cc: Guenter Roeck <linux@roeck-us.net> Cc: Chris Packham <chris.packham@alliedtelesis.co.nz> [groeck: Clarified/updated description] Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
parent
702afead45
commit
4afec79f65
@ -325,6 +325,9 @@ static ssize_t show_voltage(struct device *dev, struct device_attribute *attr,
|
|||||||
struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
|
struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
|
||||||
unsigned short val;
|
unsigned short val;
|
||||||
|
|
||||||
|
if (IS_ERR(data))
|
||||||
|
return PTR_ERR(data);
|
||||||
|
|
||||||
switch (sattr->nr) {
|
switch (sattr->nr) {
|
||||||
case ALARM:
|
case ALARM:
|
||||||
return sprintf(buf, "%d\n",
|
return sprintf(buf, "%d\n",
|
||||||
@ -380,6 +383,9 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
|
|||||||
struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
|
struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
|
||||||
int out;
|
int out;
|
||||||
|
|
||||||
|
if (IS_ERR(data))
|
||||||
|
return PTR_ERR(data);
|
||||||
|
|
||||||
switch (sattr->nr) {
|
switch (sattr->nr) {
|
||||||
case HYSTERSIS:
|
case HYSTERSIS:
|
||||||
mutex_lock(&data->lock);
|
mutex_lock(&data->lock);
|
||||||
@ -624,6 +630,9 @@ static ssize_t show_point2(struct device *dev, struct device_attribute *attr,
|
|||||||
struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
|
struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
|
||||||
int out, val;
|
int out, val;
|
||||||
|
|
||||||
|
if (IS_ERR(data))
|
||||||
|
return PTR_ERR(data);
|
||||||
|
|
||||||
mutex_lock(&data->lock);
|
mutex_lock(&data->lock);
|
||||||
out = (data->range[sattr->index] >> 4) & 0x0F;
|
out = (data->range[sattr->index] >> 4) & 0x0F;
|
||||||
val = reg2temp(data, data->temp[AUTOMIN][sattr->index]);
|
val = reg2temp(data, data->temp[AUTOMIN][sattr->index]);
|
||||||
@ -682,6 +691,9 @@ static ssize_t show_tach(struct device *dev, struct device_attribute *attr,
|
|||||||
struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
|
struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
|
||||||
int out;
|
int out;
|
||||||
|
|
||||||
|
if (IS_ERR(data))
|
||||||
|
return PTR_ERR(data);
|
||||||
|
|
||||||
if (sattr->nr == ALARM)
|
if (sattr->nr == ALARM)
|
||||||
out = (data->alarms >> (sattr->index + 10)) & 1;
|
out = (data->alarms >> (sattr->index + 10)) & 1;
|
||||||
else
|
else
|
||||||
@ -719,6 +731,9 @@ static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
|
|||||||
struct adt7475_data *data = adt7475_update_device(dev);
|
struct adt7475_data *data = adt7475_update_device(dev);
|
||||||
struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
|
struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
|
||||||
|
|
||||||
|
if (IS_ERR(data))
|
||||||
|
return PTR_ERR(data);
|
||||||
|
|
||||||
return sprintf(buf, "%d\n", data->pwm[sattr->nr][sattr->index]);
|
return sprintf(buf, "%d\n", data->pwm[sattr->nr][sattr->index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -728,6 +743,9 @@ static ssize_t show_pwmchan(struct device *dev, struct device_attribute *attr,
|
|||||||
struct adt7475_data *data = adt7475_update_device(dev);
|
struct adt7475_data *data = adt7475_update_device(dev);
|
||||||
struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
|
struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
|
||||||
|
|
||||||
|
if (IS_ERR(data))
|
||||||
|
return PTR_ERR(data);
|
||||||
|
|
||||||
return sprintf(buf, "%d\n", data->pwmchan[sattr->index]);
|
return sprintf(buf, "%d\n", data->pwmchan[sattr->index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -737,6 +755,9 @@ static ssize_t show_pwmctrl(struct device *dev, struct device_attribute *attr,
|
|||||||
struct adt7475_data *data = adt7475_update_device(dev);
|
struct adt7475_data *data = adt7475_update_device(dev);
|
||||||
struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
|
struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
|
||||||
|
|
||||||
|
if (IS_ERR(data))
|
||||||
|
return PTR_ERR(data);
|
||||||
|
|
||||||
return sprintf(buf, "%d\n", data->pwmctl[sattr->index]);
|
return sprintf(buf, "%d\n", data->pwmctl[sattr->index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -944,6 +965,9 @@ static ssize_t show_pwmfreq(struct device *dev, struct device_attribute *attr,
|
|||||||
int i = clamp_val(data->range[sattr->index] & 0xf, 0,
|
int i = clamp_val(data->range[sattr->index] & 0xf, 0,
|
||||||
ARRAY_SIZE(pwmfreq_table) - 1);
|
ARRAY_SIZE(pwmfreq_table) - 1);
|
||||||
|
|
||||||
|
if (IS_ERR(data))
|
||||||
|
return PTR_ERR(data);
|
||||||
|
|
||||||
return sprintf(buf, "%d\n", pwmfreq_table[i]);
|
return sprintf(buf, "%d\n", pwmfreq_table[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1034,6 +1058,10 @@ static ssize_t cpu0_vid_show(struct device *dev,
|
|||||||
struct device_attribute *devattr, char *buf)
|
struct device_attribute *devattr, char *buf)
|
||||||
{
|
{
|
||||||
struct adt7475_data *data = adt7475_update_device(dev);
|
struct adt7475_data *data = adt7475_update_device(dev);
|
||||||
|
|
||||||
|
if (IS_ERR(data))
|
||||||
|
return PTR_ERR(data);
|
||||||
|
|
||||||
return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
|
return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1677,7 +1705,9 @@ static int adt7475_probe(struct i2c_client *client,
|
|||||||
(data->bypass_attn & (1 << 4)) ? " in4" : "");
|
(data->bypass_attn & (1 << 4)) ? " in4" : "");
|
||||||
|
|
||||||
/* Limits and settings, should never change update more than once */
|
/* Limits and settings, should never change update more than once */
|
||||||
adt7475_update_limits(client);
|
ret = adt7475_update_limits(client);
|
||||||
|
if (ret)
|
||||||
|
goto eremove;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -1876,13 +1906,19 @@ static struct adt7475_data *adt7475_update_device(struct device *dev)
|
|||||||
{
|
{
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
struct i2c_client *client = to_i2c_client(dev);
|
||||||
struct adt7475_data *data = i2c_get_clientdata(client);
|
struct adt7475_data *data = i2c_get_clientdata(client);
|
||||||
|
int ret;
|
||||||
|
|
||||||
mutex_lock(&data->lock);
|
mutex_lock(&data->lock);
|
||||||
|
|
||||||
/* Measurement values update every 2 seconds */
|
/* Measurement values update every 2 seconds */
|
||||||
if (time_after(jiffies, data->measure_updated + HZ * 2) ||
|
if (time_after(jiffies, data->measure_updated + HZ * 2) ||
|
||||||
!data->valid) {
|
!data->valid) {
|
||||||
adt7475_update_measure(dev);
|
ret = adt7475_update_measure(dev);
|
||||||
|
if (ret) {
|
||||||
|
data->valid = false;
|
||||||
|
mutex_unlock(&data->lock);
|
||||||
|
return ERR_PTR(ret);
|
||||||
|
}
|
||||||
data->measure_updated = jiffies;
|
data->measure_updated = jiffies;
|
||||||
data->valid = true;
|
data->valid = true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user