hwmon.c (7f3cc8f897634b7e2d79bc2b7105e9ae6eaf4ac2) | hwmon.c (e1c9d6d61ddf3f34f14d3de51d6eea68683b5841) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * hwmon.c - part of lm_sensors, Linux kernel modules for hardware monitoring 4 * 5 * This file defines the sysfs class "hwmon", for use by sensors drivers. 6 * 7 * Copyright (C) 2005 Mark M. Hoffman <mhoffman@lightlink.com> 8 */ --- 4 unchanged lines hidden (view full) --- 13#include <linux/device.h> 14#include <linux/err.h> 15#include <linux/gfp.h> 16#include <linux/hwmon.h> 17#include <linux/idr.h> 18#include <linux/list.h> 19#include <linux/module.h> 20#include <linux/pci.h> | 1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * hwmon.c - part of lm_sensors, Linux kernel modules for hardware monitoring 4 * 5 * This file defines the sysfs class "hwmon", for use by sensors drivers. 6 * 7 * Copyright (C) 2005 Mark M. Hoffman <mhoffman@lightlink.com> 8 */ --- 4 unchanged lines hidden (view full) --- 13#include <linux/device.h> 14#include <linux/err.h> 15#include <linux/gfp.h> 16#include <linux/hwmon.h> 17#include <linux/idr.h> 18#include <linux/list.h> 19#include <linux/module.h> 20#include <linux/pci.h> |
21#include <linux/property.h> |
|
21#include <linux/slab.h> 22#include <linux/string.h> 23#include <linux/thermal.h> 24 25#define CREATE_TRACE_POINTS 26#include <trace/events/hwmon.h> 27 28#define HWMON_ID_PREFIX "hwmon" 29#define HWMON_ID_FORMAT HWMON_ID_PREFIX "%d" 30 31struct hwmon_device { 32 const char *name; | 22#include <linux/slab.h> 23#include <linux/string.h> 24#include <linux/thermal.h> 25 26#define CREATE_TRACE_POINTS 27#include <trace/events/hwmon.h> 28 29#define HWMON_ID_PREFIX "hwmon" 30#define HWMON_ID_FORMAT HWMON_ID_PREFIX "%d" 31 32struct hwmon_device { 33 const char *name; |
34 const char *label; |
|
33 struct device dev; 34 const struct hwmon_chip_info *chip; 35 struct list_head tzdata; 36 struct attribute_group group; 37 const struct attribute_group **groups; 38}; 39 40#define to_hwmon_device(d) container_of(d, struct hwmon_device, dev) --- 25 unchanged lines hidden (view full) --- 66 67static ssize_t 68name_show(struct device *dev, struct device_attribute *attr, char *buf) 69{ 70 return sprintf(buf, "%s\n", to_hwmon_device(dev)->name); 71} 72static DEVICE_ATTR_RO(name); 73 | 35 struct device dev; 36 const struct hwmon_chip_info *chip; 37 struct list_head tzdata; 38 struct attribute_group group; 39 const struct attribute_group **groups; 40}; 41 42#define to_hwmon_device(d) container_of(d, struct hwmon_device, dev) --- 25 unchanged lines hidden (view full) --- 68 69static ssize_t 70name_show(struct device *dev, struct device_attribute *attr, char *buf) 71{ 72 return sprintf(buf, "%s\n", to_hwmon_device(dev)->name); 73} 74static DEVICE_ATTR_RO(name); 75 |
76static ssize_t 77label_show(struct device *dev, struct device_attribute *attr, char *buf) 78{ 79 return sysfs_emit(buf, "%s\n", to_hwmon_device(dev)->label); 80} 81static DEVICE_ATTR_RO(label); 82 |
|
74static struct attribute *hwmon_dev_attrs[] = { 75 &dev_attr_name.attr, | 83static struct attribute *hwmon_dev_attrs[] = { 84 &dev_attr_name.attr, |
85 &dev_attr_label.attr, |
|
76 NULL 77}; 78 | 86 NULL 87}; 88 |
79static umode_t hwmon_dev_name_is_visible(struct kobject *kobj, | 89static umode_t hwmon_dev_attr_is_visible(struct kobject *kobj, |
80 struct attribute *attr, int n) 81{ 82 struct device *dev = kobj_to_dev(kobj); | 90 struct attribute *attr, int n) 91{ 92 struct device *dev = kobj_to_dev(kobj); |
93 struct hwmon_device *hdev = to_hwmon_device(dev); |
|
83 | 94 |
84 if (to_hwmon_device(dev)->name == NULL) | 95 if (attr == &dev_attr_name.attr && hdev->name == NULL) |
85 return 0; 86 | 96 return 0; 97 |
98 if (attr == &dev_attr_label.attr && hdev->label == NULL) 99 return 0; 100 |
|
87 return attr->mode; 88} 89 90static const struct attribute_group hwmon_dev_attr_group = { 91 .attrs = hwmon_dev_attrs, | 101 return attr->mode; 102} 103 104static const struct attribute_group hwmon_dev_attr_group = { 105 .attrs = hwmon_dev_attrs, |
92 .is_visible = hwmon_dev_name_is_visible, | 106 .is_visible = hwmon_dev_attr_is_visible, |
93}; 94 95static const struct attribute_group *hwmon_dev_attr_groups[] = { 96 &hwmon_dev_attr_group, 97 NULL 98}; 99 100static void hwmon_free_attrs(struct attribute **attrs) --- 11 unchanged lines hidden (view full) --- 112 113static void hwmon_dev_release(struct device *dev) 114{ 115 struct hwmon_device *hwdev = to_hwmon_device(dev); 116 117 if (hwdev->group.attrs) 118 hwmon_free_attrs(hwdev->group.attrs); 119 kfree(hwdev->groups); | 107}; 108 109static const struct attribute_group *hwmon_dev_attr_groups[] = { 110 &hwmon_dev_attr_group, 111 NULL 112}; 113 114static void hwmon_free_attrs(struct attribute **attrs) --- 11 unchanged lines hidden (view full) --- 126 127static void hwmon_dev_release(struct device *dev) 128{ 129 struct hwmon_device *hwdev = to_hwmon_device(dev); 130 131 if (hwdev->group.attrs) 132 hwmon_free_attrs(hwdev->group.attrs); 133 kfree(hwdev->groups); |
134 kfree(hwdev->label); |
|
120 kfree(hwdev); 121} 122 123static struct class hwmon_class = { 124 .name = "hwmon", 125 .owner = THIS_MODULE, 126 .dev_groups = hwmon_dev_attr_groups, 127 .dev_release = hwmon_dev_release, --- 605 unchanged lines hidden (view full) --- 733} 734 735static struct device * 736__hwmon_device_register(struct device *dev, const char *name, void *drvdata, 737 const struct hwmon_chip_info *chip, 738 const struct attribute_group **groups) 739{ 740 struct hwmon_device *hwdev; | 135 kfree(hwdev); 136} 137 138static struct class hwmon_class = { 139 .name = "hwmon", 140 .owner = THIS_MODULE, 141 .dev_groups = hwmon_dev_attr_groups, 142 .dev_release = hwmon_dev_release, --- 605 unchanged lines hidden (view full) --- 748} 749 750static struct device * 751__hwmon_device_register(struct device *dev, const char *name, void *drvdata, 752 const struct hwmon_chip_info *chip, 753 const struct attribute_group **groups) 754{ 755 struct hwmon_device *hwdev; |
756 const char *label; |
|
741 struct device *hdev; 742 int i, err, id; 743 744 /* Complain about invalid characters in hwmon name attribute */ 745 if (name && (!strlen(name) || strpbrk(name, "-* \t\n"))) 746 dev_warn(dev, 747 "hwmon: '%s' is not a valid name attribute, please fix\n", 748 name); --- 39 unchanged lines hidden (view full) --- 788 hwdev->groups[ngroups++] = groups[i]; 789 } 790 791 hdev->groups = hwdev->groups; 792 } else { 793 hdev->groups = groups; 794 } 795 | 757 struct device *hdev; 758 int i, err, id; 759 760 /* Complain about invalid characters in hwmon name attribute */ 761 if (name && (!strlen(name) || strpbrk(name, "-* \t\n"))) 762 dev_warn(dev, 763 "hwmon: '%s' is not a valid name attribute, please fix\n", 764 name); --- 39 unchanged lines hidden (view full) --- 804 hwdev->groups[ngroups++] = groups[i]; 805 } 806 807 hdev->groups = hwdev->groups; 808 } else { 809 hdev->groups = groups; 810 } 811 |
812 if (device_property_present(dev, "label")) { 813 err = device_property_read_string(dev, "label", &label); 814 if (err < 0) 815 goto free_hwmon; 816 817 hwdev->label = kstrdup(label, GFP_KERNEL); 818 if (hwdev->label == NULL) { 819 err = -ENOMEM; 820 goto free_hwmon; 821 } 822 } 823 |
|
796 hwdev->name = name; 797 hdev->class = &hwmon_class; 798 hdev->parent = dev; 799 hdev->of_node = dev ? dev->of_node : NULL; 800 hwdev->chip = chip; 801 dev_set_drvdata(hdev, drvdata); 802 dev_set_name(hdev, HWMON_ID_FORMAT, id); 803 err = device_register(hdev); --- 281 unchanged lines hidden --- | 824 hwdev->name = name; 825 hdev->class = &hwmon_class; 826 hdev->parent = dev; 827 hdev->of_node = dev ? dev->of_node : NULL; 828 hwdev->chip = chip; 829 dev_set_drvdata(hdev, drvdata); 830 dev_set_name(hdev, HWMON_ID_FORMAT, id); 831 err = device_register(hdev); --- 281 unchanged lines hidden --- |