[PATCH 2/2] drm/nouveau/hwmon: Convert to use devm_hwmon_device_register_with_groups
Simplify the code and resolve race conditions seen because attribute files are created after hwmon device registration, and removed before hwmon device removal. Signed-off-by: Guenter Roeck --- Compile tested only; unfortunately I don't have the the necessary hardware. drivers/gpu/drm/nouveau/nouveau_hwmon.c | 243 +++ drivers/gpu/drm/nouveau/nouveau_hwmon.h | 11 -- 2 files changed, 84 insertions(+), 170 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_hwmon.c b/drivers/gpu/drm/nouveau/nouveau_hwmon.c index 38a4db5..d4144b8 100644 --- a/drivers/gpu/drm/nouveau/nouveau_hwmon.c +++ b/drivers/gpu/drm/nouveau/nouveau_hwmon.c @@ -42,9 +42,7 @@ static ssize_t nouveau_hwmon_show_temp(struct device *d, struct device_attribute *a, char *buf) { - struct drm_device *dev = dev_get_drvdata(d); - struct nouveau_drm *drm = nouveau_drm(dev); - struct nouveau_therm *therm = nouveau_therm(drm->device); + struct nouveau_therm *therm = dev_get_drvdata(d); int temp = therm->temp_get(therm); if (temp < 0) @@ -68,9 +66,7 @@ static ssize_t nouveau_hwmon_temp1_auto_point1_temp(struct device *d, struct device_attribute *a, char *buf) { - struct drm_device *dev = dev_get_drvdata(d); - struct nouveau_drm *drm = nouveau_drm(dev); - struct nouveau_therm *therm = nouveau_therm(drm->device); + struct nouveau_therm *therm = dev_get_drvdata(d); return snprintf(buf, PAGE_SIZE, "%d\n", therm->attr_get(therm, NOUVEAU_THERM_ATTR_THRS_FAN_BOOST) * 1000); @@ -80,9 +76,7 @@ nouveau_hwmon_set_temp1_auto_point1_temp(struct device *d, struct device_attribute *a, const char *buf, size_t count) { - struct drm_device *dev = dev_get_drvdata(d); - struct nouveau_drm *drm = nouveau_drm(dev); - struct nouveau_therm *therm = nouveau_therm(drm->device); + struct nouveau_therm *therm = dev_get_drvdata(d); long value; if (kstrtol(buf, 10, ) == -EINVAL) @@ -101,9 +95,7 @@ static ssize_t nouveau_hwmon_temp1_auto_point1_temp_hyst(struct device *d, struct device_attribute *a, char *buf) { - struct drm_device *dev = dev_get_drvdata(d); - struct nouveau_drm *drm = nouveau_drm(dev); - struct nouveau_therm *therm = nouveau_therm(drm->device); + struct nouveau_therm *therm = dev_get_drvdata(d); return snprintf(buf, PAGE_SIZE, "%d\n", therm->attr_get(therm, NOUVEAU_THERM_ATTR_THRS_FAN_BOOST_HYST) * 1000); @@ -113,9 +105,7 @@ nouveau_hwmon_set_temp1_auto_point1_temp_hyst(struct device *d, struct device_attribute *a, const char *buf, size_t count) { - struct drm_device *dev = dev_get_drvdata(d); - struct nouveau_drm *drm = nouveau_drm(dev); - struct nouveau_therm *therm = nouveau_therm(drm->device); + struct nouveau_therm *therm = dev_get_drvdata(d); long value; if (kstrtol(buf, 10, ) == -EINVAL) @@ -133,9 +123,7 @@ static SENSOR_DEVICE_ATTR(temp1_auto_point1_temp_hyst, S_IRUGO | S_IWUSR, static ssize_t nouveau_hwmon_max_temp(struct device *d, struct device_attribute *a, char *buf) { - struct drm_device *dev = dev_get_drvdata(d); - struct nouveau_drm *drm = nouveau_drm(dev); - struct nouveau_therm *therm = nouveau_therm(drm->device); + struct nouveau_therm *therm = dev_get_drvdata(d); return snprintf(buf, PAGE_SIZE, "%d\n", therm->attr_get(therm, NOUVEAU_THERM_ATTR_THRS_DOWN_CLK) * 1000); @@ -144,9 +132,7 @@ static ssize_t nouveau_hwmon_set_max_temp(struct device *d, struct device_attribute *a, const char *buf, size_t count) { - struct drm_device *dev = dev_get_drvdata(d); - struct nouveau_drm *drm = nouveau_drm(dev); - struct nouveau_therm *therm = nouveau_therm(drm->device); + struct nouveau_therm *therm = dev_get_drvdata(d); long value; if (kstrtol(buf, 10, ) == -EINVAL) @@ -164,9 +150,7 @@ static ssize_t nouveau_hwmon_max_temp_hyst(struct device *d, struct device_attribute *a, char *buf) { - struct drm_device *dev = dev_get_drvdata(d); - struct nouveau_drm *drm = nouveau_drm(dev); - struct nouveau_therm *therm = nouveau_therm(drm->device); + struct nouveau_therm *therm = dev_get_drvdata(d); return snprintf(buf, PAGE_SIZE, "%d\n", therm->attr_get(therm, NOUVEAU_THERM_ATTR_THRS_DOWN_CLK_HYST) * 1000); @@ -175,9 +159,7 @@ static ssize_t nouveau_hwmon_set_max_temp_hyst(struct device *d, struct device_attribute *a, const char *buf, size_t count) { - struct drm_device *dev =
[PATCH 2/2] drm/nouveau/hwmon: Convert to use devm_hwmon_device_register_with_groups
Simplify the code and resolve race conditions seen because attribute files are created after hwmon device registration, and removed before hwmon device removal. Signed-off-by: Guenter Roeck li...@roeck-us.net --- Compile tested only; unfortunately I don't have the the necessary hardware. drivers/gpu/drm/nouveau/nouveau_hwmon.c | 243 +++ drivers/gpu/drm/nouveau/nouveau_hwmon.h | 11 -- 2 files changed, 84 insertions(+), 170 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_hwmon.c b/drivers/gpu/drm/nouveau/nouveau_hwmon.c index 38a4db5..d4144b8 100644 --- a/drivers/gpu/drm/nouveau/nouveau_hwmon.c +++ b/drivers/gpu/drm/nouveau/nouveau_hwmon.c @@ -42,9 +42,7 @@ static ssize_t nouveau_hwmon_show_temp(struct device *d, struct device_attribute *a, char *buf) { - struct drm_device *dev = dev_get_drvdata(d); - struct nouveau_drm *drm = nouveau_drm(dev); - struct nouveau_therm *therm = nouveau_therm(drm-device); + struct nouveau_therm *therm = dev_get_drvdata(d); int temp = therm-temp_get(therm); if (temp 0) @@ -68,9 +66,7 @@ static ssize_t nouveau_hwmon_temp1_auto_point1_temp(struct device *d, struct device_attribute *a, char *buf) { - struct drm_device *dev = dev_get_drvdata(d); - struct nouveau_drm *drm = nouveau_drm(dev); - struct nouveau_therm *therm = nouveau_therm(drm-device); + struct nouveau_therm *therm = dev_get_drvdata(d); return snprintf(buf, PAGE_SIZE, %d\n, therm-attr_get(therm, NOUVEAU_THERM_ATTR_THRS_FAN_BOOST) * 1000); @@ -80,9 +76,7 @@ nouveau_hwmon_set_temp1_auto_point1_temp(struct device *d, struct device_attribute *a, const char *buf, size_t count) { - struct drm_device *dev = dev_get_drvdata(d); - struct nouveau_drm *drm = nouveau_drm(dev); - struct nouveau_therm *therm = nouveau_therm(drm-device); + struct nouveau_therm *therm = dev_get_drvdata(d); long value; if (kstrtol(buf, 10, value) == -EINVAL) @@ -101,9 +95,7 @@ static ssize_t nouveau_hwmon_temp1_auto_point1_temp_hyst(struct device *d, struct device_attribute *a, char *buf) { - struct drm_device *dev = dev_get_drvdata(d); - struct nouveau_drm *drm = nouveau_drm(dev); - struct nouveau_therm *therm = nouveau_therm(drm-device); + struct nouveau_therm *therm = dev_get_drvdata(d); return snprintf(buf, PAGE_SIZE, %d\n, therm-attr_get(therm, NOUVEAU_THERM_ATTR_THRS_FAN_BOOST_HYST) * 1000); @@ -113,9 +105,7 @@ nouveau_hwmon_set_temp1_auto_point1_temp_hyst(struct device *d, struct device_attribute *a, const char *buf, size_t count) { - struct drm_device *dev = dev_get_drvdata(d); - struct nouveau_drm *drm = nouveau_drm(dev); - struct nouveau_therm *therm = nouveau_therm(drm-device); + struct nouveau_therm *therm = dev_get_drvdata(d); long value; if (kstrtol(buf, 10, value) == -EINVAL) @@ -133,9 +123,7 @@ static SENSOR_DEVICE_ATTR(temp1_auto_point1_temp_hyst, S_IRUGO | S_IWUSR, static ssize_t nouveau_hwmon_max_temp(struct device *d, struct device_attribute *a, char *buf) { - struct drm_device *dev = dev_get_drvdata(d); - struct nouveau_drm *drm = nouveau_drm(dev); - struct nouveau_therm *therm = nouveau_therm(drm-device); + struct nouveau_therm *therm = dev_get_drvdata(d); return snprintf(buf, PAGE_SIZE, %d\n, therm-attr_get(therm, NOUVEAU_THERM_ATTR_THRS_DOWN_CLK) * 1000); @@ -144,9 +132,7 @@ static ssize_t nouveau_hwmon_set_max_temp(struct device *d, struct device_attribute *a, const char *buf, size_t count) { - struct drm_device *dev = dev_get_drvdata(d); - struct nouveau_drm *drm = nouveau_drm(dev); - struct nouveau_therm *therm = nouveau_therm(drm-device); + struct nouveau_therm *therm = dev_get_drvdata(d); long value; if (kstrtol(buf, 10, value) == -EINVAL) @@ -164,9 +150,7 @@ static ssize_t nouveau_hwmon_max_temp_hyst(struct device *d, struct device_attribute *a, char *buf) { - struct drm_device *dev = dev_get_drvdata(d); - struct nouveau_drm *drm = nouveau_drm(dev); - struct nouveau_therm *therm = nouveau_therm(drm-device); + struct nouveau_therm *therm = dev_get_drvdata(d); return snprintf(buf, PAGE_SIZE, %d\n, therm-attr_get(therm, NOUVEAU_THERM_ATTR_THRS_DOWN_CLK_HYST) * 1000); @@ -175,9 +159,7 @@ static ssize_t nouveau_hwmon_set_max_temp_hyst(struct device *d, struct device_attribute *a, const char *buf, size_t count) { - struct drm_device *dev =