All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] xen: cleanup sysfs management
@ 2015-02-05 20:38 Takashi Iwai
  2015-02-05 20:38 ` [PATCH 1/2] xen: pcpu: Use static attribute groups for sysfs entry Takashi Iwai
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Takashi Iwai @ 2015-02-05 20:38 UTC (permalink / raw)
  To: xen-devel; +Cc: Boris Ostrovsky, David Vrabel

Hi,

this is a couple of patchset to clean up the sysfs entry creation /
removal in xen driver codes.  They are relatively straightforward
conversion patches, where manual function calls are replaced with
static attribute groups.


Takashi

===

Takashi Iwai (2):
  xen: pcpu: Use static attribute groups for sysfs entry
  xen: balloon: Use static attribute groups for sysfs entries

 drivers/xen/pcpu.c        | 44 ++++++++++++++++++++++++++++----------------
 drivers/xen/xen-balloon.c | 45 ++++++++++++++++++++-------------------------
 2 files changed, 48 insertions(+), 41 deletions(-)

-- 
2.2.2

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

* [PATCH 1/2] xen: pcpu: Use static attribute groups for sysfs entry
  2015-02-05 20:38 [PATCH 0/2] xen: cleanup sysfs management Takashi Iwai
@ 2015-02-05 20:38 ` Takashi Iwai
  2015-02-05 20:38 ` [PATCH 2/2] xen: balloon: Use static attribute groups for sysfs entries Takashi Iwai
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Takashi Iwai @ 2015-02-05 20:38 UTC (permalink / raw)
  To: xen-devel; +Cc: Boris Ostrovsky, David Vrabel

Instead of manual calls of device_create_file() and
device_remove_file(), assign the static attribute groups to the device
to register.  The conditional build of sysfs is done in is_visible
callback instead.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 drivers/xen/pcpu.c | 44 ++++++++++++++++++++++++++++----------------
 1 file changed, 28 insertions(+), 16 deletions(-)

diff --git a/drivers/xen/pcpu.c b/drivers/xen/pcpu.c
index 0aac403d53fd..49e88f2ce7a1 100644
--- a/drivers/xen/pcpu.c
+++ b/drivers/xen/pcpu.c
@@ -132,6 +132,33 @@ static ssize_t __ref store_online(struct device *dev,
 }
 static DEVICE_ATTR(online, S_IRUGO | S_IWUSR, show_online, store_online);
 
+static struct attribute *pcpu_dev_attrs[] = {
+	&dev_attr_online.attr,
+	NULL
+};
+
+static umode_t pcpu_dev_is_visible(struct kobject *kobj,
+				   struct attribute *attr, int idx)
+{
+	struct device *dev = kobj_to_dev(kobj);
+	/*
+	 * Xen never offline cpu0 due to several restrictions
+	 * and assumptions. This basically doesn't add a sys control
+	 * to user, one cannot attempt to offline BSP.
+	 */
+	return dev->id ? attr->mode : 0;
+}
+
+static const struct attribute_group pcpu_dev_group = {
+	.attrs = pcpu_dev_attrs,
+	.is_visible = pcpu_dev_is_visible,
+};
+
+static const struct attribute_group *pcpu_dev_groups[] = {
+	&pcpu_dev_group,
+	NULL
+};
+
 static bool xen_pcpu_online(uint32_t flags)
 {
 	return !!(flags & XEN_PCPU_FLAGS_ONLINE);
@@ -181,9 +208,6 @@ static void unregister_and_remove_pcpu(struct pcpu *pcpu)
 		return;
 
 	dev = &pcpu->dev;
-	if (dev->id)
-		device_remove_file(dev, &dev_attr_online);
-
 	/* pcpu remove would be implicitly done */
 	device_unregister(dev);
 }
@@ -200,6 +224,7 @@ static int register_pcpu(struct pcpu *pcpu)
 	dev->bus = &xen_pcpu_subsys;
 	dev->id = pcpu->cpu_id;
 	dev->release = pcpu_release;
+	dev->groups = pcpu_dev_groups;
 
 	err = device_register(dev);
 	if (err) {
@@ -207,19 +232,6 @@ static int register_pcpu(struct pcpu *pcpu)
 		return err;
 	}
 
-	/*
-	 * Xen never offline cpu0 due to several restrictions
-	 * and assumptions. This basically doesn't add a sys control
-	 * to user, one cannot attempt to offline BSP.
-	 */
-	if (dev->id) {
-		err = device_create_file(dev, &dev_attr_online);
-		if (err) {
-			device_unregister(dev);
-			return err;
-		}
-	}
-
 	return 0;
 }
 
-- 
2.2.2

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

* [PATCH 2/2] xen: balloon: Use static attribute groups for sysfs entries
  2015-02-05 20:38 [PATCH 0/2] xen: cleanup sysfs management Takashi Iwai
  2015-02-05 20:38 ` [PATCH 1/2] xen: pcpu: Use static attribute groups for sysfs entry Takashi Iwai
@ 2015-02-05 20:38 ` Takashi Iwai
  2015-02-06 10:43 ` [PATCH 0/2] xen: cleanup sysfs management David Vrabel
  2015-03-02 10:59 ` David Vrabel
  3 siblings, 0 replies; 6+ messages in thread
From: Takashi Iwai @ 2015-02-05 20:38 UTC (permalink / raw)
  To: xen-devel; +Cc: Boris Ostrovsky, David Vrabel

Instead of manual calls of device_create_file(), device_remove_file()
and sysfs_create_group(), assign static attribute groups to the device
to register.  This simplifies the code and avoids possible races.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 drivers/xen/xen-balloon.c | 45 ++++++++++++++++++++-------------------------
 1 file changed, 20 insertions(+), 25 deletions(-)

diff --git a/drivers/xen/xen-balloon.c b/drivers/xen/xen-balloon.c
index e555845d61fa..39e7ef8d3957 100644
--- a/drivers/xen/xen-balloon.c
+++ b/drivers/xen/xen-balloon.c
@@ -193,13 +193,18 @@ static DEVICE_ATTR(target, S_IRUGO | S_IWUSR,
 		   show_target, store_target);
 
 
-static struct device_attribute *balloon_attrs[] = {
-	&dev_attr_target_kb,
-	&dev_attr_target,
-	&dev_attr_schedule_delay.attr,
-	&dev_attr_max_schedule_delay.attr,
-	&dev_attr_retry_count.attr,
-	&dev_attr_max_retry_count.attr
+static struct attribute *balloon_attrs[] = {
+	&dev_attr_target_kb.attr,
+	&dev_attr_target.attr,
+	&dev_attr_schedule_delay.attr.attr,
+	&dev_attr_max_schedule_delay.attr.attr,
+	&dev_attr_retry_count.attr.attr,
+	&dev_attr_max_retry_count.attr.attr,
+	NULL
+};
+
+static const struct attribute_group balloon_group = {
+	.attrs = balloon_attrs
 };
 
 static struct attribute *balloon_info_attrs[] = {
@@ -214,6 +219,12 @@ static const struct attribute_group balloon_info_group = {
 	.attrs = balloon_info_attrs
 };
 
+static const struct attribute_group *balloon_groups[] = {
+	&balloon_group,
+	&balloon_info_group,
+	NULL
+};
+
 static struct bus_type balloon_subsys = {
 	.name = BALLOON_CLASS_NAME,
 	.dev_name = BALLOON_CLASS_NAME,
@@ -221,7 +232,7 @@ static struct bus_type balloon_subsys = {
 
 static int register_balloon(struct device *dev)
 {
-	int i, error;
+	int error;
 
 	error = subsys_system_register(&balloon_subsys, NULL);
 	if (error)
@@ -229,6 +240,7 @@ static int register_balloon(struct device *dev)
 
 	dev->id = 0;
 	dev->bus = &balloon_subsys;
+	dev->groups = balloon_groups;
 
 	error = device_register(dev);
 	if (error) {
@@ -236,24 +248,7 @@ static int register_balloon(struct device *dev)
 		return error;
 	}
 
-	for (i = 0; i < ARRAY_SIZE(balloon_attrs); i++) {
-		error = device_create_file(dev, balloon_attrs[i]);
-		if (error)
-			goto fail;
-	}
-
-	error = sysfs_create_group(&dev->kobj, &balloon_info_group);
-	if (error)
-		goto fail;
-
 	return 0;
-
- fail:
-	while (--i >= 0)
-		device_remove_file(dev, balloon_attrs[i]);
-	device_unregister(dev);
-	bus_unregister(&balloon_subsys);
-	return error;
 }
 
 MODULE_LICENSE("GPL");
-- 
2.2.2

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

* Re: [PATCH 0/2] xen: cleanup sysfs management
  2015-02-05 20:38 [PATCH 0/2] xen: cleanup sysfs management Takashi Iwai
  2015-02-05 20:38 ` [PATCH 1/2] xen: pcpu: Use static attribute groups for sysfs entry Takashi Iwai
  2015-02-05 20:38 ` [PATCH 2/2] xen: balloon: Use static attribute groups for sysfs entries Takashi Iwai
@ 2015-02-06 10:43 ` David Vrabel
  2015-02-06 10:53   ` Takashi Iwai
  2015-03-02 10:59 ` David Vrabel
  3 siblings, 1 reply; 6+ messages in thread
From: David Vrabel @ 2015-02-06 10:43 UTC (permalink / raw)
  To: Takashi Iwai, xen-devel; +Cc: Boris Ostrovsky, David Vrabel

On 05/02/15 20:38, Takashi Iwai wrote:
> Hi,
> 
> this is a couple of patchset to clean up the sysfs entry creation /
> removal in xen driver codes.  They are relatively straightforward
> conversion patches, where manual function calls are replaced with
> static attribute groups.

These look fine but they're a bit late for 3.20.

David

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

* Re: [PATCH 0/2] xen: cleanup sysfs management
  2015-02-06 10:43 ` [PATCH 0/2] xen: cleanup sysfs management David Vrabel
@ 2015-02-06 10:53   ` Takashi Iwai
  0 siblings, 0 replies; 6+ messages in thread
From: Takashi Iwai @ 2015-02-06 10:53 UTC (permalink / raw)
  To: David Vrabel; +Cc: xen-devel, Boris Ostrovsky

At Fri, 6 Feb 2015 10:43:44 +0000,
David Vrabel wrote:
> 
> On 05/02/15 20:38, Takashi Iwai wrote:
> > Hi,
> > 
> > this is a couple of patchset to clean up the sysfs entry creation /
> > removal in xen driver codes.  They are relatively straightforward
> > conversion patches, where manual function calls are replaced with
> > static attribute groups.
> 
> These look fine but they're a bit late for 3.20.

Yeah, feel free to postpone to 3.21 (as long as they aren't lost :)
These are just non-urgent cleanups I happened to find through the
whole tree.


Takashi

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

* Re: [PATCH 0/2] xen: cleanup sysfs management
  2015-02-05 20:38 [PATCH 0/2] xen: cleanup sysfs management Takashi Iwai
                   ` (2 preceding siblings ...)
  2015-02-06 10:43 ` [PATCH 0/2] xen: cleanup sysfs management David Vrabel
@ 2015-03-02 10:59 ` David Vrabel
  3 siblings, 0 replies; 6+ messages in thread
From: David Vrabel @ 2015-03-02 10:59 UTC (permalink / raw)
  To: Takashi Iwai, xen-devel; +Cc: Boris Ostrovsky, David Vrabel

On 05/02/15 20:38, Takashi Iwai wrote:
> Hi,
> 
> this is a couple of patchset to clean up the sysfs entry creation /
> removal in xen driver codes.  They are relatively straightforward
> conversion patches, where manual function calls are replaced with
> static attribute groups.

Applied to devel/for-linus-4.1, thanks.

David

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

end of thread, other threads:[~2015-03-02 10:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-05 20:38 [PATCH 0/2] xen: cleanup sysfs management Takashi Iwai
2015-02-05 20:38 ` [PATCH 1/2] xen: pcpu: Use static attribute groups for sysfs entry Takashi Iwai
2015-02-05 20:38 ` [PATCH 2/2] xen: balloon: Use static attribute groups for sysfs entries Takashi Iwai
2015-02-06 10:43 ` [PATCH 0/2] xen: cleanup sysfs management David Vrabel
2015-02-06 10:53   ` Takashi Iwai
2015-03-02 10:59 ` David Vrabel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.