Simplify code, reduce code size, and attach sysfs attributes to hwmon device.
For this driver, the only attribute created is the name attribute.
Other attributes are still created and removed dynamically as cores
are added or removed.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Jean Delvare <jdelvare@suse.de>
Tested-by: Jean Delvare <jdelvare@suse.de>
static LIST_HEAD(pdev_list);
static DEFINE_MUTEX(pdev_list_mutex);
static LIST_HEAD(pdev_list);
static DEFINE_MUTEX(pdev_list_mutex);
-static ssize_t show_name(struct device *dev,
- struct device_attribute *devattr, char *buf)
-{
- return sprintf(buf, "%s\n", DRVNAME);
-}
-
static ssize_t show_label(struct device *dev,
struct device_attribute *devattr, char *buf)
{
static ssize_t show_label(struct device *dev,
struct device_attribute *devattr, char *buf)
{
return adjust_tjmax(c, id, dev);
}
return adjust_tjmax(c, id, dev);
}
-static int create_name_attr(struct platform_data *pdata,
- struct device *dev)
-{
- sysfs_attr_init(&pdata->name_attr.attr);
- pdata->name_attr.attr.name = "name";
- pdata->name_attr.attr.mode = S_IRUGO;
- pdata->name_attr.show = show_name;
- return device_create_file(dev, &pdata->name_attr);
-}
-
static int create_core_attrs(struct temp_data *tdata, struct device *dev,
int attr_no)
{
static int create_core_attrs(struct temp_data *tdata, struct device *dev,
int attr_no)
{
pdata->core_data[attr_no] = tdata;
/* Create sysfs interfaces */
pdata->core_data[attr_no] = tdata;
/* Create sysfs interfaces */
- err = create_core_attrs(tdata, &pdev->dev, attr_no);
+ err = create_core_attrs(tdata, pdata->hwmon_dev, attr_no);
}
static void coretemp_remove_core(struct platform_data *pdata,
}
static void coretemp_remove_core(struct platform_data *pdata,
- struct device *dev, int indx)
{
struct temp_data *tdata = pdata->core_data[indx];
/* Remove the sysfs attributes */
{
struct temp_data *tdata = pdata->core_data[indx];
/* Remove the sysfs attributes */
- sysfs_remove_group(&dev->kobj, &tdata->attr_group);
+ sysfs_remove_group(&pdata->hwmon_dev->kobj, &tdata->attr_group);
kfree(pdata->core_data[indx]);
pdata->core_data[indx] = NULL;
kfree(pdata->core_data[indx]);
pdata->core_data[indx] = NULL;
{
struct device *dev = &pdev->dev;
struct platform_data *pdata;
{
struct device *dev = &pdev->dev;
struct platform_data *pdata;
/* Initialize the per-package data structures */
pdata = devm_kzalloc(dev, sizeof(struct platform_data), GFP_KERNEL);
if (!pdata)
return -ENOMEM;
/* Initialize the per-package data structures */
pdata = devm_kzalloc(dev, sizeof(struct platform_data), GFP_KERNEL);
if (!pdata)
return -ENOMEM;
- err = create_name_attr(pdata, dev);
- if (err)
- return err;
-
pdata->phys_proc_id = pdev->id;
platform_set_drvdata(pdev, pdata);
pdata->phys_proc_id = pdev->id;
platform_set_drvdata(pdev, pdata);
- pdata->hwmon_dev = hwmon_device_register(dev);
- if (IS_ERR(pdata->hwmon_dev)) {
- err = PTR_ERR(pdata->hwmon_dev);
- dev_err(&pdev->dev, "Class registration failed (%d)\n", err);
- goto exit_name;
- }
- return 0;
-
-exit_name:
- device_remove_file(&pdev->dev, &pdata->name_attr);
- return err;
+ pdata->hwmon_dev = devm_hwmon_device_register_with_groups(dev, DRVNAME,
+ pdata, NULL);
+ return PTR_ERR_OR_ZERO(pdata->hwmon_dev);
}
static int coretemp_remove(struct platform_device *pdev)
}
static int coretemp_remove(struct platform_device *pdev)
for (i = MAX_CORE_DATA - 1; i >= 0; --i)
if (pdata->core_data[i])
for (i = MAX_CORE_DATA - 1; i >= 0; --i)
if (pdata->core_data[i])
- coretemp_remove_core(pdata, &pdev->dev, i);
+ coretemp_remove_core(pdata, i);
- device_remove_file(&pdev->dev, &pdata->name_attr);
- hwmon_device_unregister(pdata->hwmon_dev);
return;
if (pdata->core_data[indx] && pdata->core_data[indx]->cpu == cpu)
return;
if (pdata->core_data[indx] && pdata->core_data[indx]->cpu == cpu)
- coretemp_remove_core(pdata, &pdev->dev, indx);
+ coretemp_remove_core(pdata, indx);
/*
* If a HT sibling of a core is taken offline, but another HT sibling
/*
* If a HT sibling of a core is taken offline, but another HT sibling