Skip to content

Commit 78cebd0

Browse files
pawelmollgroeck
authored andcommitted
hwmon: vexpress: Use devm helper for hwmon device registration
Use devm_hwmon_device_register_with_groups instead of the old-style manual attributes and hwmon device registration. Also, unroll the attribute group macros for better code readability. Signed-off-by: Pawel Moll <pawel.moll@arm.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent 8dea1b4 commit 78cebd0

File tree

1 file changed

+28
-54
lines changed

1 file changed

+28
-54
lines changed

drivers/hwmon/vexpress.c

Lines changed: 28 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,8 @@
2727
struct vexpress_hwmon_data {
2828
struct device *hwmon_dev;
2929
struct regmap *reg;
30-
const char *name;
3130
};
3231

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-
4132
static ssize_t vexpress_hwmon_label_show(struct device *dev,
4233
struct device_attribute *dev_attr, char *buffer)
4334
{
@@ -95,16 +86,6 @@ static umode_t vexpress_hwmon_attr_is_visible(struct kobject *kobj,
9586
return attr->mode;
9687
}
9788

98-
static DEVICE_ATTR(name, S_IRUGO, vexpress_hwmon_name_show, NULL);
99-
100-
#define VEXPRESS_HWMON_ATTRS(_name, _label_attr, _input_attr) \
101-
struct attribute *vexpress_hwmon_attrs_##_name[] = { \
102-
&dev_attr_name.attr, \
103-
&dev_attr_##_label_attr.attr, \
104-
&sensor_dev_attr_##_input_attr.dev_attr.attr, \
105-
NULL \
106-
}
107-
10889
struct vexpress_hwmon_type {
10990
const char *name;
11091
const struct attribute_group **attr_groups;
@@ -114,7 +95,11 @@ struct vexpress_hwmon_type {
11495
static DEVICE_ATTR(in1_label, S_IRUGO, vexpress_hwmon_label_show, NULL);
11596
static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, vexpress_hwmon_u32_show,
11697
NULL, 1000);
117-
static VEXPRESS_HWMON_ATTRS(volt, in1_label, in1_input);
98+
static struct attribute *vexpress_hwmon_attrs_volt[] = {
99+
&dev_attr_in1_label.attr,
100+
&sensor_dev_attr_in1_input.dev_attr.attr,
101+
NULL
102+
};
118103
static struct attribute_group vexpress_hwmon_group_volt = {
119104
.is_visible = vexpress_hwmon_attr_is_visible,
120105
.attrs = vexpress_hwmon_attrs_volt,
@@ -131,7 +116,11 @@ static struct vexpress_hwmon_type vexpress_hwmon_volt = {
131116
static DEVICE_ATTR(curr1_label, S_IRUGO, vexpress_hwmon_label_show, NULL);
132117
static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, vexpress_hwmon_u32_show,
133118
NULL, 1000);
134-
static VEXPRESS_HWMON_ATTRS(amp, curr1_label, curr1_input);
119+
static struct attribute *vexpress_hwmon_attrs_amp[] = {
120+
&dev_attr_curr1_label.attr,
121+
&sensor_dev_attr_curr1_input.dev_attr.attr,
122+
NULL
123+
};
135124
static struct attribute_group vexpress_hwmon_group_amp = {
136125
.is_visible = vexpress_hwmon_attr_is_visible,
137126
.attrs = vexpress_hwmon_attrs_amp,
@@ -147,7 +136,11 @@ static struct vexpress_hwmon_type vexpress_hwmon_amp = {
147136
static DEVICE_ATTR(temp1_label, S_IRUGO, vexpress_hwmon_label_show, NULL);
148137
static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, vexpress_hwmon_u32_show,
149138
NULL, 1000);
150-
static VEXPRESS_HWMON_ATTRS(temp, temp1_label, temp1_input);
139+
static struct attribute *vexpress_hwmon_attrs_temp[] = {
140+
&dev_attr_temp1_label.attr,
141+
&sensor_dev_attr_temp1_input.dev_attr.attr,
142+
NULL
143+
};
151144
static struct attribute_group vexpress_hwmon_group_temp = {
152145
.is_visible = vexpress_hwmon_attr_is_visible,
153146
.attrs = vexpress_hwmon_attrs_temp,
@@ -163,7 +156,11 @@ static struct vexpress_hwmon_type vexpress_hwmon_temp = {
163156
static DEVICE_ATTR(power1_label, S_IRUGO, vexpress_hwmon_label_show, NULL);
164157
static SENSOR_DEVICE_ATTR(power1_input, S_IRUGO, vexpress_hwmon_u32_show,
165158
NULL, 1);
166-
static VEXPRESS_HWMON_ATTRS(power, power1_label, power1_input);
159+
static struct attribute *vexpress_hwmon_attrs_power[] = {
160+
&dev_attr_power1_label.attr,
161+
&sensor_dev_attr_power1_input.dev_attr.attr,
162+
NULL
163+
};
167164
static struct attribute_group vexpress_hwmon_group_power = {
168165
.is_visible = vexpress_hwmon_attr_is_visible,
169166
.attrs = vexpress_hwmon_attrs_power,
@@ -179,7 +176,11 @@ static struct vexpress_hwmon_type vexpress_hwmon_power = {
179176
static DEVICE_ATTR(energy1_label, S_IRUGO, vexpress_hwmon_label_show, NULL);
180177
static SENSOR_DEVICE_ATTR(energy1_input, S_IRUGO, vexpress_hwmon_u64_show,
181178
NULL, 1);
182-
static VEXPRESS_HWMON_ATTRS(energy, energy1_label, energy1_input);
179+
static struct attribute *vexpress_hwmon_attrs_energy[] = {
180+
&dev_attr_energy1_label.attr,
181+
&sensor_dev_attr_energy1_input.dev_attr.attr,
182+
NULL
183+
};
183184
static struct attribute_group vexpress_hwmon_group_energy = {
184185
.is_visible = vexpress_hwmon_attr_is_visible,
185186
.attrs = vexpress_hwmon_attrs_energy,
@@ -218,7 +219,6 @@ MODULE_DEVICE_TABLE(of, vexpress_hwmon_of_match);
218219

219220
static int vexpress_hwmon_probe(struct platform_device *pdev)
220221
{
221-
int err;
222222
const struct of_device_id *match;
223223
struct vexpress_hwmon_data *data;
224224
const struct vexpress_hwmon_type *type;
@@ -232,45 +232,19 @@ static int vexpress_hwmon_probe(struct platform_device *pdev)
232232
if (!match)
233233
return -ENODEV;
234234
type = match->data;
235-
data->name = type->name;
236235

237236
data->reg = devm_regmap_init_vexpress_config(&pdev->dev);
238237
if (IS_ERR(data->reg))
239238
return PTR_ERR(data->reg);
240239

241-
err = sysfs_create_groups(&pdev->dev.kobj, type->attr_groups);
242-
if (err)
243-
goto error;
244-
245-
data->hwmon_dev = hwmon_device_register(&pdev->dev);
246-
if (IS_ERR(data->hwmon_dev)) {
247-
err = PTR_ERR(data->hwmon_dev);
248-
goto error;
249-
}
250-
251-
return 0;
252-
253-
error:
254-
sysfs_remove_group(&pdev->dev.kobj, match->data);
255-
return err;
256-
}
257-
258-
static int vexpress_hwmon_remove(struct platform_device *pdev)
259-
{
260-
struct vexpress_hwmon_data *data = platform_get_drvdata(pdev);
261-
const struct of_device_id *match;
262-
263-
hwmon_device_unregister(data->hwmon_dev);
264-
265-
match = of_match_device(vexpress_hwmon_of_match, &pdev->dev);
266-
sysfs_remove_group(&pdev->dev.kobj, match->data);
240+
data->hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev,
241+
type->name, data, type->attr_groups);
267242

268-
return 0;
243+
return PTR_ERR_OR_ZERO(data->hwmon_dev);
269244
}
270245

271246
static struct platform_driver vexpress_hwmon_driver = {
272247
.probe = vexpress_hwmon_probe,
273-
.remove = vexpress_hwmon_remove,
274248
.driver = {
275249
.name = DRVNAME,
276250
.owner = THIS_MODULE,

0 commit comments

Comments
 (0)