aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/coretemp.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/coretemp.c')
-rw-r--r--drivers/hwmon/coretemp.c85
1 files changed, 23 insertions, 62 deletions
diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
index bbb0b0d463f7..6d02e3b06375 100644
--- a/drivers/hwmon/coretemp.c
+++ b/drivers/hwmon/coretemp.c
@@ -94,6 +94,8 @@ struct temp_data {
94 bool valid; 94 bool valid;
95 struct sensor_device_attribute sd_attrs[TOTAL_ATTRS]; 95 struct sensor_device_attribute sd_attrs[TOTAL_ATTRS];
96 char attr_name[TOTAL_ATTRS][CORETEMP_NAME_LENGTH]; 96 char attr_name[TOTAL_ATTRS][CORETEMP_NAME_LENGTH];
97 struct attribute *attrs[TOTAL_ATTRS + 1];
98 struct attribute_group attr_group;
97 struct mutex update_lock; 99 struct mutex update_lock;
98}; 100};
99 101
@@ -114,12 +116,6 @@ struct pdev_entry {
114static LIST_HEAD(pdev_list); 116static LIST_HEAD(pdev_list);
115static DEFINE_MUTEX(pdev_list_mutex); 117static DEFINE_MUTEX(pdev_list_mutex);
116 118
117static ssize_t show_name(struct device *dev,
118 struct device_attribute *devattr, char *buf)
119{
120 return sprintf(buf, "%s\n", DRVNAME);
121}
122
123static ssize_t show_label(struct device *dev, 119static ssize_t show_label(struct device *dev,
124 struct device_attribute *devattr, char *buf) 120 struct device_attribute *devattr, char *buf)
125{ 121{
@@ -393,20 +389,10 @@ static int get_tjmax(struct cpuinfo_x86 *c, u32 id, struct device *dev)
393 return adjust_tjmax(c, id, dev); 389 return adjust_tjmax(c, id, dev);
394} 390}
395 391
396static int create_name_attr(struct platform_data *pdata,
397 struct device *dev)
398{
399 sysfs_attr_init(&pdata->name_attr.attr);
400 pdata->name_attr.attr.name = "name";
401 pdata->name_attr.attr.mode = S_IRUGO;
402 pdata->name_attr.show = show_name;
403 return device_create_file(dev, &pdata->name_attr);
404}
405
406static int create_core_attrs(struct temp_data *tdata, struct device *dev, 392static int create_core_attrs(struct temp_data *tdata, struct device *dev,
407 int attr_no) 393 int attr_no)
408{ 394{
409 int err, i; 395 int i;
410 static ssize_t (*const rd_ptr[TOTAL_ATTRS]) (struct device *dev, 396 static ssize_t (*const rd_ptr[TOTAL_ATTRS]) (struct device *dev,
411 struct device_attribute *devattr, char *buf) = { 397 struct device_attribute *devattr, char *buf) = {
412 show_label, show_crit_alarm, show_temp, show_tjmax, 398 show_label, show_crit_alarm, show_temp, show_tjmax,
@@ -424,16 +410,10 @@ static int create_core_attrs(struct temp_data *tdata, struct device *dev,
424 tdata->sd_attrs[i].dev_attr.attr.mode = S_IRUGO; 410 tdata->sd_attrs[i].dev_attr.attr.mode = S_IRUGO;
425 tdata->sd_attrs[i].dev_attr.show = rd_ptr[i]; 411 tdata->sd_attrs[i].dev_attr.show = rd_ptr[i];
426 tdata->sd_attrs[i].index = attr_no; 412 tdata->sd_attrs[i].index = attr_no;
427 err = device_create_file(dev, &tdata->sd_attrs[i].dev_attr); 413 tdata->attrs[i] = &tdata->sd_attrs[i].dev_attr.attr;
428 if (err)
429 goto exit_free;
430 } 414 }
431 return 0; 415 tdata->attr_group.attrs = tdata->attrs;
432 416 return sysfs_create_group(&dev->kobj, &tdata->attr_group);
433exit_free:
434 while (--i >= 0)
435 device_remove_file(dev, &tdata->sd_attrs[i].dev_attr);
436 return err;
437} 417}
438 418
439 419
@@ -548,7 +528,7 @@ static int create_core_data(struct platform_device *pdev, unsigned int cpu,
548 pdata->core_data[attr_no] = tdata; 528 pdata->core_data[attr_no] = tdata;
549 529
550 /* Create sysfs interfaces */ 530 /* Create sysfs interfaces */
551 err = create_core_attrs(tdata, &pdev->dev, attr_no); 531 err = create_core_attrs(tdata, pdata->hwmon_dev, attr_no);
552 if (err) 532 if (err)
553 goto exit_free; 533 goto exit_free;
554 534
@@ -573,14 +553,12 @@ static void coretemp_add_core(unsigned int cpu, int pkg_flag)
573} 553}
574 554
575static void coretemp_remove_core(struct platform_data *pdata, 555static void coretemp_remove_core(struct platform_data *pdata,
576 struct device *dev, int indx) 556 int indx)
577{ 557{
578 int i;
579 struct temp_data *tdata = pdata->core_data[indx]; 558 struct temp_data *tdata = pdata->core_data[indx];
580 559
581 /* Remove the sysfs attributes */ 560 /* Remove the sysfs attributes */
582 for (i = 0; i < tdata->attr_size; i++) 561 sysfs_remove_group(&pdata->hwmon_dev->kobj, &tdata->attr_group);
583 device_remove_file(dev, &tdata->sd_attrs[i].dev_attr);
584 562
585 kfree(pdata->core_data[indx]); 563 kfree(pdata->core_data[indx]);
586 pdata->core_data[indx] = NULL; 564 pdata->core_data[indx] = NULL;
@@ -588,34 +566,20 @@ static void coretemp_remove_core(struct platform_data *pdata,
588 566
589static int coretemp_probe(struct platform_device *pdev) 567static int coretemp_probe(struct platform_device *pdev)
590{ 568{
569 struct device *dev = &pdev->dev;
591 struct platform_data *pdata; 570 struct platform_data *pdata;
592 int err;
593 571
594 /* Initialize the per-package data structures */ 572 /* Initialize the per-package data structures */
595 pdata = kzalloc(sizeof(struct platform_data), GFP_KERNEL); 573 pdata = devm_kzalloc(dev, sizeof(struct platform_data), GFP_KERNEL);
596 if (!pdata) 574 if (!pdata)
597 return -ENOMEM; 575 return -ENOMEM;
598 576
599 err = create_name_attr(pdata, &pdev->dev);
600 if (err)
601 goto exit_free;
602
603 pdata->phys_proc_id = pdev->id; 577 pdata->phys_proc_id = pdev->id;
604 platform_set_drvdata(pdev, pdata); 578 platform_set_drvdata(pdev, pdata);
605 579
606 pdata->hwmon_dev = hwmon_device_register(&pdev->dev); 580 pdata->hwmon_dev = devm_hwmon_device_register_with_groups(dev, DRVNAME,
607 if (IS_ERR(pdata->hwmon_dev)) { 581 pdata, NULL);
608 err = PTR_ERR(pdata->hwmon_dev); 582 return PTR_ERR_OR_ZERO(pdata->hwmon_dev);
609 dev_err(&pdev->dev, "Class registration failed (%d)\n", err);
610 goto exit_name;
611 }
612 return 0;
613
614exit_name:
615 device_remove_file(&pdev->dev, &pdata->name_attr);
616exit_free:
617 kfree(pdata);
618 return err;
619} 583}
620 584
621static int coretemp_remove(struct platform_device *pdev) 585static int coretemp_remove(struct platform_device *pdev)
@@ -625,11 +589,8 @@ static int coretemp_remove(struct platform_device *pdev)
625 589
626 for (i = MAX_CORE_DATA - 1; i >= 0; --i) 590 for (i = MAX_CORE_DATA - 1; i >= 0; --i)
627 if (pdata->core_data[i]) 591 if (pdata->core_data[i])
628 coretemp_remove_core(pdata, &pdev->dev, i); 592 coretemp_remove_core(pdata, i);
629 593
630 device_remove_file(&pdev->dev, &pdata->name_attr);
631 hwmon_device_unregister(pdata->hwmon_dev);
632 kfree(pdata);
633 return 0; 594 return 0;
634} 595}
635 596
@@ -777,7 +738,7 @@ static void put_core_offline(unsigned int cpu)
777 return; 738 return;
778 739
779 if (pdata->core_data[indx] && pdata->core_data[indx]->cpu == cpu) 740 if (pdata->core_data[indx] && pdata->core_data[indx]->cpu == cpu)
780 coretemp_remove_core(pdata, &pdev->dev, indx); 741 coretemp_remove_core(pdata, indx);
781 742
782 /* 743 /*
783 * If a HT sibling of a core is taken offline, but another HT sibling 744 * If a HT sibling of a core is taken offline, but another HT sibling
@@ -849,20 +810,20 @@ static int __init coretemp_init(void)
849 if (err) 810 if (err)
850 goto exit; 811 goto exit;
851 812
852 get_online_cpus(); 813 cpu_notifier_register_begin();
853 for_each_online_cpu(i) 814 for_each_online_cpu(i)
854 get_core_online(i); 815 get_core_online(i);
855 816
856#ifndef CONFIG_HOTPLUG_CPU 817#ifndef CONFIG_HOTPLUG_CPU
857 if (list_empty(&pdev_list)) { 818 if (list_empty(&pdev_list)) {
858 put_online_cpus(); 819 cpu_notifier_register_done();
859 err = -ENODEV; 820 err = -ENODEV;
860 goto exit_driver_unreg; 821 goto exit_driver_unreg;
861 } 822 }
862#endif 823#endif
863 824
864 register_hotcpu_notifier(&coretemp_cpu_notifier); 825 __register_hotcpu_notifier(&coretemp_cpu_notifier);
865 put_online_cpus(); 826 cpu_notifier_register_done();
866 return 0; 827 return 0;
867 828
868#ifndef CONFIG_HOTPLUG_CPU 829#ifndef CONFIG_HOTPLUG_CPU
@@ -877,8 +838,8 @@ static void __exit coretemp_exit(void)
877{ 838{
878 struct pdev_entry *p, *n; 839 struct pdev_entry *p, *n;
879 840
880 get_online_cpus(); 841 cpu_notifier_register_begin();
881 unregister_hotcpu_notifier(&coretemp_cpu_notifier); 842 __unregister_hotcpu_notifier(&coretemp_cpu_notifier);
882 mutex_lock(&pdev_list_mutex); 843 mutex_lock(&pdev_list_mutex);
883 list_for_each_entry_safe(p, n, &pdev_list, list) { 844 list_for_each_entry_safe(p, n, &pdev_list, list) {
884 platform_device_unregister(p->pdev); 845 platform_device_unregister(p->pdev);
@@ -886,7 +847,7 @@ static void __exit coretemp_exit(void)
886 kfree(p); 847 kfree(p);
887 } 848 }
888 mutex_unlock(&pdev_list_mutex); 849 mutex_unlock(&pdev_list_mutex);
889 put_online_cpus(); 850 cpu_notifier_register_done();
890 platform_driver_unregister(&coretemp_driver); 851 platform_driver_unregister(&coretemp_driver);
891} 852}
892 853