Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (fam15h_power) Make actual power reporting conditional

power1_input should only be reported for Fam15h, Models 00h-0fh
So, introduce a is_visible function to take care of this.

As suggested by Guenter here:
http://marc.info/?l=linux-kernel&m=141038145616437&w=2

Suggested-by: Guenter Roeck <linux@roeck-us.net>
Fixes: 22e32f4f5777 ('x86,AMD: Power driver support for AMD's family 16h processors')
Signed-off-by: Aravind Gopalakrishnan <Aravind.Gopalakrishnan@amd.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by

Aravind Gopalakrishnan and committed by
Guenter Roeck
961a2378 9e82bf01

+17 -1
+17 -1
drivers/hwmon/fam15h_power.c
··· 93 93 } 94 94 static DEVICE_ATTR(power1_crit, S_IRUGO, show_power_crit, NULL); 95 95 96 + static umode_t fam15h_power_is_visible(struct kobject *kobj, 97 + struct attribute *attr, 98 + int index) 99 + { 100 + /* power1_input is only reported for Fam15h, Models 00h-0fh */ 101 + if (attr == &dev_attr_power1_input.attr && 102 + (boot_cpu_data.x86 != 0x15 || boot_cpu_data.x86_model > 0xf)) 103 + return 0; 104 + 105 + return attr->mode; 106 + } 107 + 96 108 static struct attribute *fam15h_power_attrs[] = { 97 109 &dev_attr_power1_input.attr, 98 110 &dev_attr_power1_crit.attr, 99 111 NULL 100 112 }; 101 113 102 - ATTRIBUTE_GROUPS(fam15h_power); 114 + static const struct attribute_group fam15h_power_group = { 115 + .attrs = fam15h_power_attrs, 116 + .is_visible = fam15h_power_is_visible, 117 + }; 118 + __ATTRIBUTE_GROUPS(fam15h_power); 103 119 104 120 static bool fam15h_power_is_internal_node0(struct pci_dev *f4) 105 121 {