Skip to content

Commit 3c9b8aa

Browse files
tiwaigregkh
authored andcommitted
drivers/base/node: Avoid manual device_create_file() calls
Instead of manual calls of multiple device_create_file() and device_remove_file(), use the static attribute groups assigned to the new device. This also fixes the possible races, too. Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 07afb6a commit 3c9b8aa

1 file changed

Lines changed: 20 additions & 14 deletions

File tree

‎drivers/base/node.c‎

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,25 @@ static ssize_t node_read_distance(struct device *dev,
200200
}
201201
static DEVICE_ATTR(distance, S_IRUGO, node_read_distance, NULL);
202202

203+
static struct attribute *node_dev_attrs[] = {
204+
&dev_attr_cpumap.attr,
205+
&dev_attr_cpulist.attr,
206+
&dev_attr_meminfo.attr,
207+
&dev_attr_numastat.attr,
208+
&dev_attr_distance.attr,
209+
&dev_attr_vmstat.attr,
210+
NULL
211+
};
212+
213+
static struct attribute_group node_dev_attr_group = {
214+
.attrs = node_dev_attrs,
215+
};
216+
217+
static const struct attribute_group *node_dev_attr_groups[] = {
218+
&node_dev_attr_group,
219+
NULL
220+
};
221+
203222
#ifdef CONFIG_HUGETLBFS
204223
/*
205224
* hugetlbfs per node attributes registration interface:
@@ -273,16 +292,10 @@ static int register_node(struct node *node, int num, struct node *parent)
273292
node->dev.id = num;
274293
node->dev.bus = &node_subsys;
275294
node->dev.release = node_device_release;
295+
node->dev.groups = node_dev_attr_groups;
276296
error = device_register(&node->dev);
277297

278298
if (!error){
279-
device_create_file(&node->dev, &dev_attr_cpumap);
280-
device_create_file(&node->dev, &dev_attr_cpulist);
281-
device_create_file(&node->dev, &dev_attr_meminfo);
282-
device_create_file(&node->dev, &dev_attr_numastat);
283-
device_create_file(&node->dev, &dev_attr_distance);
284-
device_create_file(&node->dev, &dev_attr_vmstat);
285-
286299
hugetlb_register_node(node);
287300

288301
compaction_register_node(node);
@@ -299,13 +312,6 @@ static int register_node(struct node *node, int num, struct node *parent)
299312
*/
300313
void unregister_node(struct node *node)
301314
{
302-
device_remove_file(&node->dev, &dev_attr_cpumap);
303-
device_remove_file(&node->dev, &dev_attr_cpulist);
304-
device_remove_file(&node->dev, &dev_attr_meminfo);
305-
device_remove_file(&node->dev, &dev_attr_numastat);
306-
device_remove_file(&node->dev, &dev_attr_distance);
307-
device_remove_file(&node->dev, &dev_attr_vmstat);
308-
309315
hugetlb_unregister_node(node); /* no-op, if memoryless node */
310316

311317
device_unregister(&node->dev);

0 commit comments

Comments
 (0)