LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] drivers/base/node: Avoid manual device_create_file() calls
@ 2015-01-29 11:29 Takashi Iwai
  2015-01-29 14:35 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 2+ messages in thread
From: Takashi Iwai @ 2015-01-29 11:29 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-kernel

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>
---
 drivers/base/node.c | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/drivers/base/node.c b/drivers/base/node.c
index a3b82e9c7f20..6ce1d4343cf0 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -200,6 +200,25 @@ static ssize_t node_read_distance(struct device *dev,
 }
 static DEVICE_ATTR(distance, S_IRUGO, node_read_distance, NULL);
 
+static struct attribute *node_dev_attrs[] = {
+	&dev_attr_cpumap.attr,
+	&dev_attr_cpulist.attr,
+	&dev_attr_meminfo.attr,
+	&dev_attr_numastat.attr,
+	&dev_attr_distance.attr,
+	&dev_attr_vmstat.attr,
+	NULL
+};
+
+static struct attribute_group node_dev_attr_group = {
+	.attrs	= node_dev_attrs,
+};
+
+static const struct attribute_group *node_dev_attr_groups[] = {
+	&node_dev_attr_group,
+	NULL
+};
+
 #ifdef CONFIG_HUGETLBFS
 /*
  * hugetlbfs per node attributes registration interface:
@@ -273,16 +292,10 @@ static int register_node(struct node *node, int num, struct node *parent)
 	node->dev.id = num;
 	node->dev.bus = &node_subsys;
 	node->dev.release = node_device_release;
+	node->dev.groups = node_dev_attr_groups;
 	error = device_register(&node->dev);
 
 	if (!error){
-		device_create_file(&node->dev, &dev_attr_cpumap);
-		device_create_file(&node->dev, &dev_attr_cpulist);
-		device_create_file(&node->dev, &dev_attr_meminfo);
-		device_create_file(&node->dev, &dev_attr_numastat);
-		device_create_file(&node->dev, &dev_attr_distance);
-		device_create_file(&node->dev, &dev_attr_vmstat);
-
 		hugetlb_register_node(node);
 
 		compaction_register_node(node);
@@ -299,13 +312,6 @@ static int register_node(struct node *node, int num, struct node *parent)
  */
 void unregister_node(struct node *node)
 {
-	device_remove_file(&node->dev, &dev_attr_cpumap);
-	device_remove_file(&node->dev, &dev_attr_cpulist);
-	device_remove_file(&node->dev, &dev_attr_meminfo);
-	device_remove_file(&node->dev, &dev_attr_numastat);
-	device_remove_file(&node->dev, &dev_attr_distance);
-	device_remove_file(&node->dev, &dev_attr_vmstat);
-
 	hugetlb_unregister_node(node);		/* no-op, if memoryless node */
 
 	device_unregister(&node->dev);
-- 
2.2.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] drivers/base/node: Avoid manual device_create_file() calls
  2015-01-29 11:29 [PATCH] drivers/base/node: Avoid manual device_create_file() calls Takashi Iwai
@ 2015-01-29 14:35 ` Greg Kroah-Hartman
  0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2015-01-29 14:35 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: linux-kernel

On Thu, Jan 29, 2015 at 12:29:22PM +0100, Takashi Iwai wrote:
> 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>
> ---
>  drivers/base/node.c | 34 ++++++++++++++++++++--------------
>  1 file changed, 20 insertions(+), 14 deletions(-)

Looks good, I'll queue this up soon, thanks for doing it.

greg k-h

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-01-29 14:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-29 11:29 [PATCH] drivers/base/node: Avoid manual device_create_file() calls Takashi Iwai
2015-01-29 14:35 ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).