MIPS: Loongson: Use hwmon_device_register_with_groups() to register hwmon
[ Upstream commit abae018a03821be2b65c01ebe2bef06fd7d85a4c ]
Calling hwmon_device_register_with_info() with NULL dev and/or chip
information parameters is an ABI abuse and not a real conversion to
the new API. Also, the code creates sysfs attributes _after_ creating
the hwmon device, which is racy and unsupported to start with. On top
of that, the removal code tries to remove the name attribute which is
owned by the hwmon core.
Use hwmon_device_register_with_groups() to register the hwmon device
instead.
In the future, the hwmon subsystem will reject calls to
hwmon_device_register_with_info with NULL dev or chip/info parameters.
Without this patch, the hwmon device will fail to register.
Fixes: f59dc51191
("MIPS: Loongson: Fix boot warning about hwmon_device_register()")
Cc: Zhi Li <lizhi01@loongson.cn>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
ec5ded7acb
commit
8e49773a75
@@ -55,55 +55,6 @@ out:
|
|||||||
static int nr_packages;
|
static int nr_packages;
|
||||||
static struct device *cpu_hwmon_dev;
|
static struct device *cpu_hwmon_dev;
|
||||||
|
|
||||||
static SENSOR_DEVICE_ATTR(name, 0444, NULL, NULL, 0);
|
|
||||||
|
|
||||||
static struct attribute *cpu_hwmon_attributes[] = {
|
|
||||||
&sensor_dev_attr_name.dev_attr.attr,
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Hwmon device attribute group */
|
|
||||||
static struct attribute_group cpu_hwmon_attribute_group = {
|
|
||||||
.attrs = cpu_hwmon_attributes,
|
|
||||||
};
|
|
||||||
|
|
||||||
static ssize_t get_cpu_temp(struct device *dev,
|
|
||||||
struct device_attribute *attr, char *buf);
|
|
||||||
static ssize_t cpu_temp_label(struct device *dev,
|
|
||||||
struct device_attribute *attr, char *buf);
|
|
||||||
|
|
||||||
static SENSOR_DEVICE_ATTR(temp1_input, 0444, get_cpu_temp, NULL, 1);
|
|
||||||
static SENSOR_DEVICE_ATTR(temp1_label, 0444, cpu_temp_label, NULL, 1);
|
|
||||||
static SENSOR_DEVICE_ATTR(temp2_input, 0444, get_cpu_temp, NULL, 2);
|
|
||||||
static SENSOR_DEVICE_ATTR(temp2_label, 0444, cpu_temp_label, NULL, 2);
|
|
||||||
static SENSOR_DEVICE_ATTR(temp3_input, 0444, get_cpu_temp, NULL, 3);
|
|
||||||
static SENSOR_DEVICE_ATTR(temp3_label, 0444, cpu_temp_label, NULL, 3);
|
|
||||||
static SENSOR_DEVICE_ATTR(temp4_input, 0444, get_cpu_temp, NULL, 4);
|
|
||||||
static SENSOR_DEVICE_ATTR(temp4_label, 0444, cpu_temp_label, NULL, 4);
|
|
||||||
|
|
||||||
static const struct attribute *hwmon_cputemp[4][3] = {
|
|
||||||
{
|
|
||||||
&sensor_dev_attr_temp1_input.dev_attr.attr,
|
|
||||||
&sensor_dev_attr_temp1_label.dev_attr.attr,
|
|
||||||
NULL
|
|
||||||
},
|
|
||||||
{
|
|
||||||
&sensor_dev_attr_temp2_input.dev_attr.attr,
|
|
||||||
&sensor_dev_attr_temp2_label.dev_attr.attr,
|
|
||||||
NULL
|
|
||||||
},
|
|
||||||
{
|
|
||||||
&sensor_dev_attr_temp3_input.dev_attr.attr,
|
|
||||||
&sensor_dev_attr_temp3_label.dev_attr.attr,
|
|
||||||
NULL
|
|
||||||
},
|
|
||||||
{
|
|
||||||
&sensor_dev_attr_temp4_input.dev_attr.attr,
|
|
||||||
&sensor_dev_attr_temp4_label.dev_attr.attr,
|
|
||||||
NULL
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static ssize_t cpu_temp_label(struct device *dev,
|
static ssize_t cpu_temp_label(struct device *dev,
|
||||||
struct device_attribute *attr, char *buf)
|
struct device_attribute *attr, char *buf)
|
||||||
{
|
{
|
||||||
@@ -121,23 +72,46 @@ static ssize_t get_cpu_temp(struct device *dev,
|
|||||||
return sprintf(buf, "%d\n", value);
|
return sprintf(buf, "%d\n", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int create_sysfs_cputemp_files(struct kobject *kobj)
|
static SENSOR_DEVICE_ATTR(temp1_input, 0444, get_cpu_temp, NULL, 1);
|
||||||
|
static SENSOR_DEVICE_ATTR(temp1_label, 0444, cpu_temp_label, NULL, 1);
|
||||||
|
static SENSOR_DEVICE_ATTR(temp2_input, 0444, get_cpu_temp, NULL, 2);
|
||||||
|
static SENSOR_DEVICE_ATTR(temp2_label, 0444, cpu_temp_label, NULL, 2);
|
||||||
|
static SENSOR_DEVICE_ATTR(temp3_input, 0444, get_cpu_temp, NULL, 3);
|
||||||
|
static SENSOR_DEVICE_ATTR(temp3_label, 0444, cpu_temp_label, NULL, 3);
|
||||||
|
static SENSOR_DEVICE_ATTR(temp4_input, 0444, get_cpu_temp, NULL, 4);
|
||||||
|
static SENSOR_DEVICE_ATTR(temp4_label, 0444, cpu_temp_label, NULL, 4);
|
||||||
|
|
||||||
|
static struct attribute *cpu_hwmon_attributes[] = {
|
||||||
|
&sensor_dev_attr_temp1_input.dev_attr.attr,
|
||||||
|
&sensor_dev_attr_temp1_label.dev_attr.attr,
|
||||||
|
&sensor_dev_attr_temp2_input.dev_attr.attr,
|
||||||
|
&sensor_dev_attr_temp2_label.dev_attr.attr,
|
||||||
|
&sensor_dev_attr_temp3_input.dev_attr.attr,
|
||||||
|
&sensor_dev_attr_temp3_label.dev_attr.attr,
|
||||||
|
&sensor_dev_attr_temp4_input.dev_attr.attr,
|
||||||
|
&sensor_dev_attr_temp4_label.dev_attr.attr,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
static umode_t cpu_hwmon_is_visible(struct kobject *kobj,
|
||||||
|
struct attribute *attr, int i)
|
||||||
{
|
{
|
||||||
int i, ret = 0;
|
int id = i / 2;
|
||||||
|
|
||||||
for (i = 0; i < nr_packages; i++)
|
if (id < nr_packages)
|
||||||
ret = sysfs_create_files(kobj, hwmon_cputemp[i]);
|
return attr->mode;
|
||||||
|
return 0;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void remove_sysfs_cputemp_files(struct kobject *kobj)
|
static struct attribute_group cpu_hwmon_group = {
|
||||||
{
|
.attrs = cpu_hwmon_attributes,
|
||||||
int i;
|
.is_visible = cpu_hwmon_is_visible,
|
||||||
|
};
|
||||||
|
|
||||||
for (i = 0; i < nr_packages; i++)
|
static const struct attribute_group *cpu_hwmon_groups[] = {
|
||||||
sysfs_remove_files(kobj, hwmon_cputemp[i]);
|
&cpu_hwmon_group,
|
||||||
}
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
#define CPU_THERMAL_THRESHOLD 90000
|
#define CPU_THERMAL_THRESHOLD 90000
|
||||||
static struct delayed_work thermal_work;
|
static struct delayed_work thermal_work;
|
||||||
@@ -159,50 +133,31 @@ static void do_thermal_timer(struct work_struct *work)
|
|||||||
|
|
||||||
static int __init loongson_hwmon_init(void)
|
static int __init loongson_hwmon_init(void)
|
||||||
{
|
{
|
||||||
int ret;
|
|
||||||
|
|
||||||
pr_info("Loongson Hwmon Enter...\n");
|
pr_info("Loongson Hwmon Enter...\n");
|
||||||
|
|
||||||
if (cpu_has_csr())
|
if (cpu_has_csr())
|
||||||
csr_temp_enable = csr_readl(LOONGSON_CSR_FEATURES) &
|
csr_temp_enable = csr_readl(LOONGSON_CSR_FEATURES) &
|
||||||
LOONGSON_CSRF_TEMP;
|
LOONGSON_CSRF_TEMP;
|
||||||
|
|
||||||
cpu_hwmon_dev = hwmon_device_register_with_info(NULL, "cpu_hwmon", NULL, NULL, NULL);
|
|
||||||
if (IS_ERR(cpu_hwmon_dev)) {
|
|
||||||
ret = PTR_ERR(cpu_hwmon_dev);
|
|
||||||
pr_err("hwmon_device_register fail!\n");
|
|
||||||
goto fail_hwmon_device_register;
|
|
||||||
}
|
|
||||||
|
|
||||||
nr_packages = loongson_sysconf.nr_cpus /
|
nr_packages = loongson_sysconf.nr_cpus /
|
||||||
loongson_sysconf.cores_per_package;
|
loongson_sysconf.cores_per_package;
|
||||||
|
|
||||||
ret = create_sysfs_cputemp_files(&cpu_hwmon_dev->kobj);
|
cpu_hwmon_dev = hwmon_device_register_with_groups(NULL, "cpu_hwmon",
|
||||||
if (ret) {
|
NULL, cpu_hwmon_groups);
|
||||||
pr_err("fail to create cpu temperature interface!\n");
|
if (IS_ERR(cpu_hwmon_dev)) {
|
||||||
goto fail_create_sysfs_cputemp_files;
|
pr_err("hwmon_device_register fail!\n");
|
||||||
|
return PTR_ERR(cpu_hwmon_dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
INIT_DEFERRABLE_WORK(&thermal_work, do_thermal_timer);
|
INIT_DEFERRABLE_WORK(&thermal_work, do_thermal_timer);
|
||||||
schedule_delayed_work(&thermal_work, msecs_to_jiffies(20000));
|
schedule_delayed_work(&thermal_work, msecs_to_jiffies(20000));
|
||||||
|
|
||||||
return ret;
|
return 0;
|
||||||
|
|
||||||
fail_create_sysfs_cputemp_files:
|
|
||||||
sysfs_remove_group(&cpu_hwmon_dev->kobj,
|
|
||||||
&cpu_hwmon_attribute_group);
|
|
||||||
hwmon_device_unregister(cpu_hwmon_dev);
|
|
||||||
|
|
||||||
fail_hwmon_device_register:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __exit loongson_hwmon_exit(void)
|
static void __exit loongson_hwmon_exit(void)
|
||||||
{
|
{
|
||||||
cancel_delayed_work_sync(&thermal_work);
|
cancel_delayed_work_sync(&thermal_work);
|
||||||
remove_sysfs_cputemp_files(&cpu_hwmon_dev->kobj);
|
|
||||||
sysfs_remove_group(&cpu_hwmon_dev->kobj,
|
|
||||||
&cpu_hwmon_attribute_group);
|
|
||||||
hwmon_device_unregister(cpu_hwmon_dev);
|
hwmon_device_unregister(cpu_hwmon_dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user