Skip to content

Commit 3701cde

Browse files
Andi Kleengregkh
authored andcommitted
sysdev: Use sysdev_class attribute arrays in node driver
Convert the node driver to sysdev_class attribute arrays. This greatly cleans up the code and remove a lot of code. Saves ~150 bytes of code on x86-64. Signed-off-by: Andi Kleen <ak@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent e1a7e29 commit 3701cde

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

‎drivers/base/node.c‎

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
#include <linux/device.h>
1717
#include <linux/swap.h>
1818

19+
static struct sysdev_class_attribute *node_state_attrs[];
20+
1921
static struct sysdev_class node_class = {
2022
.name = "node",
23+
.attrs = node_state_attrs,
2124
};
2225

2326

@@ -569,29 +572,27 @@ static struct node_attr node_state_attr[] = {
569572
#endif
570573
};
571574

572-
static int node_states_init(void)
573-
{
574-
int i;
575-
int err = 0;
576-
577-
BUILD_BUG_ON(ARRAY_SIZE(node_state_attr) != NR_NODE_STATES);
578-
for (i = 0; i < NR_NODE_STATES; i++) {
579-
int ret;
580-
ret = sysdev_class_create_file(&node_class, &node_state_attr[i].attr);
581-
if (!err)
582-
err = ret;
583-
}
584-
return err;
585-
}
575+
static struct sysdev_class_attribute *node_state_attrs[] = {
576+
&node_state_attr[0].attr,
577+
&node_state_attr[1].attr,
578+
&node_state_attr[2].attr,
579+
&node_state_attr[3].attr,
580+
#ifdef CONFIG_HIGHMEM
581+
&node_state_attr[4].attr,
582+
#endif
583+
NULL
584+
};
586585

587586
#define NODE_CALLBACK_PRI 2 /* lower than SLAB */
588587
static int __init register_node_type(void)
589588
{
590589
int ret;
591590

591+
BUILD_BUG_ON(ARRAY_SIZE(node_state_attr) != NR_NODE_STATES);
592+
BUILD_BUG_ON(ARRAY_SIZE(node_state_attrs)-1 != NR_NODE_STATES);
593+
592594
ret = sysdev_class_register(&node_class);
593595
if (!ret) {
594-
ret = node_states_init();
595596
hotplug_memory_notifier(node_memory_callback,
596597
NODE_CALLBACK_PRI);
597598
}

0 commit comments

Comments
 (0)