Merge tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging

Pull hwmon fixes from Guenter Roeck:
- ltc2945: Don't unecessarily crash kernel on implementation error
- vexpress: Fix 'name' and 'label' attributes

* tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging:
hwmon: (ltc2945) Don't crash the kernel unnecessarily
hwmon: (vexpress) Avoid creating non-existing attributes
hwmon: (vexpress) Use legal hwmon device names

+74 -15
+3 -3
drivers/hwmon/ltc2945.c
··· 1 - /* 2 * Driver for Linear Technology LTC2945 I2C Power Monitor 3 * 4 * Copyright (c) 2014 Guenter Roeck ··· 314 reg = LTC2945_MAX_ADIN_H; 315 break; 316 default: 317 - BUG(); 318 - break; 319 } 320 /* Reset maximum */ 321 ret = regmap_bulk_write(regmap, reg, buf_max, num_regs);
··· 1 + /* 2 * Driver for Linear Technology LTC2945 I2C Power Monitor 3 * 4 * Copyright (c) 2014 Guenter Roeck ··· 314 reg = LTC2945_MAX_ADIN_H; 315 break; 316 default: 317 + WARN_ONCE(1, "Bad register: 0x%x\n", reg); 318 + return -EINVAL; 319 } 320 /* Reset maximum */ 321 ret = regmap_bulk_write(regmap, reg, buf_max, num_regs);
+71 -12
drivers/hwmon/vexpress.c
··· 27 struct vexpress_hwmon_data { 28 struct device *hwmon_dev; 29 struct vexpress_config_func *func; 30 }; 31 32 static ssize_t vexpress_hwmon_name_show(struct device *dev, 33 struct device_attribute *dev_attr, char *buffer) 34 { 35 - const char *compatible = of_get_property(dev->of_node, "compatible", 36 - NULL); 37 38 - return sprintf(buffer, "%s\n", compatible); 39 } 40 41 static ssize_t vexpress_hwmon_label_show(struct device *dev, 42 struct device_attribute *dev_attr, char *buffer) 43 { 44 const char *label = of_get_property(dev->of_node, "label", NULL); 45 - 46 - if (!label) 47 - return -ENOENT; 48 49 return snprintf(buffer, PAGE_SIZE, "%s\n", label); 50 } ··· 81 to_sensor_dev_attr(dev_attr)->index)); 82 } 83 84 static DEVICE_ATTR(name, S_IRUGO, vexpress_hwmon_name_show, NULL); 85 86 #define VEXPRESS_HWMON_ATTRS(_name, _label_attr, _input_attr) \ ··· 105 NULL \ 106 } 107 108 #if !defined(CONFIG_REGULATOR_VEXPRESS) 109 static DEVICE_ATTR(in1_label, S_IRUGO, vexpress_hwmon_label_show, NULL); 110 static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, vexpress_hwmon_u32_show, 111 NULL, 1000); 112 static VEXPRESS_HWMON_ATTRS(volt, in1_label, in1_input); 113 static struct attribute_group vexpress_hwmon_group_volt = { 114 .attrs = vexpress_hwmon_attrs_volt, 115 }; 116 #endif 117 ··· 133 NULL, 1000); 134 static VEXPRESS_HWMON_ATTRS(amp, curr1_label, curr1_input); 135 static struct attribute_group vexpress_hwmon_group_amp = { 136 .attrs = vexpress_hwmon_attrs_amp, 137 }; 138 139 static DEVICE_ATTR(temp1_label, S_IRUGO, vexpress_hwmon_label_show, NULL); ··· 149 NULL, 1000); 150 static VEXPRESS_HWMON_ATTRS(temp, temp1_label, temp1_input); 151 static struct attribute_group vexpress_hwmon_group_temp = { 152 .attrs = vexpress_hwmon_attrs_temp, 153 }; 154 155 static DEVICE_ATTR(power1_label, S_IRUGO, vexpress_hwmon_label_show, NULL); ··· 165 NULL, 1); 166 static VEXPRESS_HWMON_ATTRS(power, power1_label, power1_input); 167 static struct attribute_group vexpress_hwmon_group_power = { 168 .attrs = vexpress_hwmon_attrs_power, 169 }; 170 171 static DEVICE_ATTR(energy1_label, S_IRUGO, vexpress_hwmon_label_show, NULL); ··· 181 NULL, 1); 182 static VEXPRESS_HWMON_ATTRS(energy, energy1_label, energy1_input); 183 static struct attribute_group vexpress_hwmon_group_energy = { 184 .attrs = vexpress_hwmon_attrs_energy, 185 }; 186 187 static struct of_device_id vexpress_hwmon_of_match[] = { 188 #if !defined(CONFIG_REGULATOR_VEXPRESS) 189 { 190 .compatible = "arm,vexpress-volt", 191 - .data = &vexpress_hwmon_group_volt, 192 }, 193 #endif 194 { 195 .compatible = "arm,vexpress-amp", 196 - .data = &vexpress_hwmon_group_amp, 197 }, { 198 .compatible = "arm,vexpress-temp", 199 - .data = &vexpress_hwmon_group_temp, 200 }, { 201 .compatible = "arm,vexpress-power", 202 - .data = &vexpress_hwmon_group_power, 203 }, { 204 .compatible = "arm,vexpress-energy", 205 - .data = &vexpress_hwmon_group_energy, 206 }, 207 {} 208 }; ··· 221 int err; 222 const struct of_device_id *match; 223 struct vexpress_hwmon_data *data; 224 225 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); 226 if (!data) ··· 231 match = of_match_device(vexpress_hwmon_of_match, &pdev->dev); 232 if (!match) 233 return -ENODEV; 234 235 data->func = vexpress_config_func_get_by_dev(&pdev->dev); 236 if (!data->func) 237 return -ENODEV; 238 239 - err = sysfs_create_group(&pdev->dev.kobj, match->data); 240 if (err) 241 goto error; 242
··· 27 struct vexpress_hwmon_data { 28 struct device *hwmon_dev; 29 struct vexpress_config_func *func; 30 + const char *name; 31 }; 32 33 static ssize_t vexpress_hwmon_name_show(struct device *dev, 34 struct device_attribute *dev_attr, char *buffer) 35 { 36 + struct vexpress_hwmon_data *data = dev_get_drvdata(dev); 37 38 + return sprintf(buffer, "%s\n", data->name); 39 } 40 41 static ssize_t vexpress_hwmon_label_show(struct device *dev, 42 struct device_attribute *dev_attr, char *buffer) 43 { 44 const char *label = of_get_property(dev->of_node, "label", NULL); 45 46 return snprintf(buffer, PAGE_SIZE, "%s\n", label); 47 } ··· 84 to_sensor_dev_attr(dev_attr)->index)); 85 } 86 87 + static umode_t vexpress_hwmon_attr_is_visible(struct kobject *kobj, 88 + struct attribute *attr, int index) 89 + { 90 + struct device *dev = kobj_to_dev(kobj); 91 + struct device_attribute *dev_attr = container_of(attr, 92 + struct device_attribute, attr); 93 + 94 + if (dev_attr->show == vexpress_hwmon_label_show && 95 + !of_get_property(dev->of_node, "label", NULL)) 96 + return 0; 97 + 98 + return attr->mode; 99 + } 100 + 101 static DEVICE_ATTR(name, S_IRUGO, vexpress_hwmon_name_show, NULL); 102 103 #define VEXPRESS_HWMON_ATTRS(_name, _label_attr, _input_attr) \ ··· 94 NULL \ 95 } 96 97 + struct vexpress_hwmon_type { 98 + const char *name; 99 + const struct attribute_group **attr_groups; 100 + }; 101 + 102 #if !defined(CONFIG_REGULATOR_VEXPRESS) 103 static DEVICE_ATTR(in1_label, S_IRUGO, vexpress_hwmon_label_show, NULL); 104 static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, vexpress_hwmon_u32_show, 105 NULL, 1000); 106 static VEXPRESS_HWMON_ATTRS(volt, in1_label, in1_input); 107 static struct attribute_group vexpress_hwmon_group_volt = { 108 + .is_visible = vexpress_hwmon_attr_is_visible, 109 .attrs = vexpress_hwmon_attrs_volt, 110 + }; 111 + static struct vexpress_hwmon_type vexpress_hwmon_volt = { 112 + .name = "vexpress_volt", 113 + .attr_groups = (const struct attribute_group *[]) { 114 + &vexpress_hwmon_group_volt, 115 + NULL, 116 + }, 117 }; 118 #endif 119 ··· 109 NULL, 1000); 110 static VEXPRESS_HWMON_ATTRS(amp, curr1_label, curr1_input); 111 static struct attribute_group vexpress_hwmon_group_amp = { 112 + .is_visible = vexpress_hwmon_attr_is_visible, 113 .attrs = vexpress_hwmon_attrs_amp, 114 + }; 115 + static struct vexpress_hwmon_type vexpress_hwmon_amp = { 116 + .name = "vexpress_amp", 117 + .attr_groups = (const struct attribute_group *[]) { 118 + &vexpress_hwmon_group_amp, 119 + NULL 120 + }, 121 }; 122 123 static DEVICE_ATTR(temp1_label, S_IRUGO, vexpress_hwmon_label_show, NULL); ··· 117 NULL, 1000); 118 static VEXPRESS_HWMON_ATTRS(temp, temp1_label, temp1_input); 119 static struct attribute_group vexpress_hwmon_group_temp = { 120 + .is_visible = vexpress_hwmon_attr_is_visible, 121 .attrs = vexpress_hwmon_attrs_temp, 122 + }; 123 + static struct vexpress_hwmon_type vexpress_hwmon_temp = { 124 + .name = "vexpress_temp", 125 + .attr_groups = (const struct attribute_group *[]) { 126 + &vexpress_hwmon_group_temp, 127 + NULL 128 + }, 129 }; 130 131 static DEVICE_ATTR(power1_label, S_IRUGO, vexpress_hwmon_label_show, NULL); ··· 125 NULL, 1); 126 static VEXPRESS_HWMON_ATTRS(power, power1_label, power1_input); 127 static struct attribute_group vexpress_hwmon_group_power = { 128 + .is_visible = vexpress_hwmon_attr_is_visible, 129 .attrs = vexpress_hwmon_attrs_power, 130 + }; 131 + static struct vexpress_hwmon_type vexpress_hwmon_power = { 132 + .name = "vexpress_power", 133 + .attr_groups = (const struct attribute_group *[]) { 134 + &vexpress_hwmon_group_power, 135 + NULL 136 + }, 137 }; 138 139 static DEVICE_ATTR(energy1_label, S_IRUGO, vexpress_hwmon_label_show, NULL); ··· 133 NULL, 1); 134 static VEXPRESS_HWMON_ATTRS(energy, energy1_label, energy1_input); 135 static struct attribute_group vexpress_hwmon_group_energy = { 136 + .is_visible = vexpress_hwmon_attr_is_visible, 137 .attrs = vexpress_hwmon_attrs_energy, 138 + }; 139 + static struct vexpress_hwmon_type vexpress_hwmon_energy = { 140 + .name = "vexpress_energy", 141 + .attr_groups = (const struct attribute_group *[]) { 142 + &vexpress_hwmon_group_energy, 143 + NULL 144 + }, 145 }; 146 147 static struct of_device_id vexpress_hwmon_of_match[] = { 148 #if !defined(CONFIG_REGULATOR_VEXPRESS) 149 { 150 .compatible = "arm,vexpress-volt", 151 + .data = &vexpress_hwmon_volt, 152 }, 153 #endif 154 { 155 .compatible = "arm,vexpress-amp", 156 + .data = &vexpress_hwmon_amp, 157 }, { 158 .compatible = "arm,vexpress-temp", 159 + .data = &vexpress_hwmon_temp, 160 }, { 161 .compatible = "arm,vexpress-power", 162 + .data = &vexpress_hwmon_power, 163 }, { 164 .compatible = "arm,vexpress-energy", 165 + .data = &vexpress_hwmon_energy, 166 }, 167 {} 168 }; ··· 165 int err; 166 const struct of_device_id *match; 167 struct vexpress_hwmon_data *data; 168 + const struct vexpress_hwmon_type *type; 169 170 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); 171 if (!data) ··· 174 match = of_match_device(vexpress_hwmon_of_match, &pdev->dev); 175 if (!match) 176 return -ENODEV; 177 + type = match->data; 178 + data->name = type->name; 179 180 data->func = vexpress_config_func_get_by_dev(&pdev->dev); 181 if (!data->func) 182 return -ENODEV; 183 184 + err = sysfs_create_groups(&pdev->dev.kobj, type->attr_groups); 185 if (err) 186 goto error; 187