Skip to content

Commit b15f562

Browse files
Andi Kleengregkh
authored andcommitted
sysdev: Convert node driver class attributes to be data driven
Using the new attribute argument convert the node driver class attributes to carry the node state. Then use a shared function to do what a lot of individual functions did before. Signed-off-by: Andi Kleen <ak@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent c9be0a3 commit b15f562

1 file changed

Lines changed: 18 additions & 47 deletions

File tree

‎drivers/base/node.c‎

Lines changed: 18 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -544,69 +544,40 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
544544
return n;
545545
}
546546

547-
static ssize_t print_nodes_possible(struct sysdev_class *class,
548-
struct sysdev_class_attribute *attr, char *buf)
549-
{
550-
return print_nodes_state(N_POSSIBLE, buf);
551-
}
552-
553-
static ssize_t print_nodes_online(struct sysdev_class *class,
554-
struct sysdev_class_attribute *attr,
555-
char *buf)
556-
{
557-
return print_nodes_state(N_ONLINE, buf);
558-
}
559-
560-
static ssize_t print_nodes_has_normal_memory(struct sysdev_class *class,
561-
struct sysdev_class_attribute *attr,
562-
char *buf)
563-
{
564-
return print_nodes_state(N_NORMAL_MEMORY, buf);
565-
}
566-
567-
static ssize_t print_nodes_has_cpu(struct sysdev_class *class,
568-
struct sysdev_class_attribute *attr,
569-
char *buf)
570-
{
571-
return print_nodes_state(N_CPU, buf);
572-
}
573-
574-
static SYSDEV_CLASS_ATTR(possible, 0444, print_nodes_possible, NULL);
575-
static SYSDEV_CLASS_ATTR(online, 0444, print_nodes_online, NULL);
576-
static SYSDEV_CLASS_ATTR(has_normal_memory, 0444, print_nodes_has_normal_memory,
577-
NULL);
578-
static SYSDEV_CLASS_ATTR(has_cpu, 0444, print_nodes_has_cpu, NULL);
547+
struct node_attr {
548+
struct sysdev_class_attribute attr;
549+
enum node_states state;
550+
};
579551

580-
#ifdef CONFIG_HIGHMEM
581-
static ssize_t print_nodes_has_high_memory(struct sysdev_class *class,
582-
struct sysdev_class_attribute *attr,
583-
char *buf)
552+
static ssize_t show_node_state(struct sysdev_class *class,
553+
struct sysdev_class_attribute *attr, char *buf)
584554
{
585-
return print_nodes_state(N_HIGH_MEMORY, buf);
555+
struct node_attr *na = container_of(attr, struct node_attr, attr);
556+
return print_nodes_state(na->state, buf);
586557
}
587558

588-
static SYSDEV_CLASS_ATTR(has_high_memory, 0444, print_nodes_has_high_memory,
589-
NULL);
590-
#endif
559+
#define _NODE_ATTR(name, state) \
560+
{ _SYSDEV_CLASS_ATTR(name, 0444, show_node_state, NULL), state }
591561

592-
struct sysdev_class_attribute *node_state_attr[] = {
593-
&attr_possible,
594-
&attr_online,
595-
&attr_has_normal_memory,
562+
static struct node_attr node_state_attr[] = {
563+
_NODE_ATTR(possible, N_POSSIBLE),
564+
_NODE_ATTR(online, N_ONLINE),
565+
_NODE_ATTR(has_normal_memory, N_NORMAL_MEMORY),
566+
_NODE_ATTR(has_cpu, N_CPU),
596567
#ifdef CONFIG_HIGHMEM
597-
&attr_has_high_memory,
568+
_NODE_ATTR(has_high_memory, N_HIGH_MEMORY),
598569
#endif
599-
&attr_has_cpu,
600570
};
601571

602572
static int node_states_init(void)
603573
{
604574
int i;
605575
int err = 0;
606576

577+
BUILD_BUG_ON(ARRAY_SIZE(node_state_attr) != NR_NODE_STATES);
607578
for (i = 0; i < NR_NODE_STATES; i++) {
608579
int ret;
609-
ret = sysdev_class_create_file(&node_class, node_state_attr[i]);
580+
ret = sysdev_class_create_file(&node_class, &node_state_attr[i].attr);
610581
if (!err)
611582
err = ret;
612583
}

0 commit comments

Comments
 (0)