public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] driver core: class: add class_groups support
@ 2016-11-28 15:41 Greg Kroah-Hartman
  2016-11-28 15:41 ` [PATCH 2/3] driver core: devcoredump: convert to use class_groups Greg Kroah-Hartman
  0 siblings, 1 reply; 5+ messages in thread
From: Greg Kroah-Hartman @ 2016-11-28 15:41 UTC (permalink / raw)
  To: linux-kernel; +Cc: Johannes Berg, Ming Lei, Luis R. Rodriguez

struct class needs to have a set of default groups that are added, as
adding individual attributes does not work well in the long run.  So add
support for that.

Future patches will convert the existing usages of class_attrs to use
class_groups and then class_attrs will go away.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/base/class.c   | 15 +++++++++++++++
 include/linux/device.h |  2 ++
 2 files changed, 17 insertions(+)

diff --git a/drivers/base/class.c b/drivers/base/class.c
index 71059e32bebc..a2b2896693d6 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -163,6 +163,18 @@ static void klist_class_dev_put(struct klist_node *n)
 	put_device(dev);
 }
 
+static int class_add_groups(struct class *cls,
+			    const struct attribute_group **groups)
+{
+	return sysfs_create_groups(&cls->p->subsys.kobj, groups);
+}
+
+static void class_remove_groups(struct class *cls,
+				const struct attribute_group **groups)
+{
+	return sysfs_remove_groups(&cls->p->subsys.kobj, groups);
+}
+
 int __class_register(struct class *cls, struct lock_class_key *key)
 {
 	struct subsys_private *cp;
@@ -203,6 +215,8 @@ int __class_register(struct class *cls, struct lock_class_key *key)
 		kfree(cp);
 		return error;
 	}
+	error = class_add_groups(class_get(cls), cls->class_groups);
+	class_put(cls);
 	error = add_class_attrs(class_get(cls));
 	class_put(cls);
 	return error;
@@ -213,6 +227,7 @@ void class_unregister(struct class *cls)
 {
 	pr_debug("device class '%s': unregistering\n", cls->name);
 	remove_class_attrs(cls);
+	class_remove_groups(cls, cls->class_groups);
 	kset_unregister(&cls->p->subsys);
 }
 
diff --git a/include/linux/device.h b/include/linux/device.h
index bc41e87a969b..39d71c8a59f4 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -362,6 +362,7 @@ int subsys_virtual_register(struct bus_type *subsys,
  * @name:	Name of the class.
  * @owner:	The module owner.
  * @class_attrs: Default attributes of this class.
+ * @class_groups: Default attributes of this class.
  * @dev_groups:	Default attributes of the devices that belong to the class.
  * @dev_kobj:	The kobject that represents this class and links it into the hierarchy.
  * @dev_uevent:	Called when a device is added, removed from this class, or a
@@ -390,6 +391,7 @@ struct class {
 	struct module		*owner;
 
 	struct class_attribute		*class_attrs;
+	const struct attribute_group	**class_groups;
 	const struct attribute_group	**dev_groups;
 	struct kobject			*dev_kobj;
 
-- 
2.10.2

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

* [PATCH 2/3] driver core: devcoredump: convert to use class_groups
  2016-11-28 15:41 [PATCH 1/3] driver core: class: add class_groups support Greg Kroah-Hartman
@ 2016-11-28 15:41 ` Greg Kroah-Hartman
  2016-11-28 15:42   ` [PATCH 3/3] driver core: firmware_class: " Greg Kroah-Hartman
  2016-11-28 15:48   ` [PATCH 2/3] driver core: devcoredump: " Johannes Berg
  0 siblings, 2 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2016-11-28 15:41 UTC (permalink / raw)
  To: linux-kernel; +Cc: Johannes Berg, Ming Lei, Luis R. Rodriguez

Convert devcoredump to use class_groups instead of class_attrs as that's
the correct way to handle lists of class attribute files.

Cc: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/base/devcoredump.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/base/devcoredump.c b/drivers/base/devcoredump.c
index 240374fd1838..7be310f7db73 100644
--- a/drivers/base/devcoredump.c
+++ b/drivers/base/devcoredump.c
@@ -160,18 +160,20 @@ static ssize_t disabled_store(struct class *class, struct class_attribute *attr,
 
 	return count;
 }
+static CLASS_ATTR_RW(disabled);
 
-static struct class_attribute devcd_class_attrs[] = {
-	__ATTR_RW(disabled),
-	__ATTR_NULL
+static struct attribute *devcd_class_attrs[] = {
+	&class_attr_disabled.attr,
+	NULL,
 };
+ATTRIBUTE_GROUPS(devcd_class);
 
 static struct class devcd_class = {
 	.name		= "devcoredump",
 	.owner		= THIS_MODULE,
 	.dev_release	= devcd_dev_release,
 	.dev_groups	= devcd_dev_groups,
-	.class_attrs	= devcd_class_attrs,
+	.class_groups	= devcd_class_groups,
 };
 
 static ssize_t devcd_readv(char *buffer, loff_t offset, size_t count,
-- 
2.10.2

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

* [PATCH 3/3] driver core: firmware_class: convert to use class_groups
  2016-11-28 15:41 ` [PATCH 2/3] driver core: devcoredump: convert to use class_groups Greg Kroah-Hartman
@ 2016-11-28 15:42   ` Greg Kroah-Hartman
  2016-11-29 18:01     ` Luis R. Rodriguez
  2016-11-28 15:48   ` [PATCH 2/3] driver core: devcoredump: " Johannes Berg
  1 sibling, 1 reply; 5+ messages in thread
From: Greg Kroah-Hartman @ 2016-11-28 15:42 UTC (permalink / raw)
  To: linux-kernel; +Cc: Johannes Berg, Ming Lei, Luis R. Rodriguez

Convert the firmware core to use class_groups instead of class_attrs as
that's the correct way to handle lists of class attribute files.

Cc: Ming Lei <ming.lei@canonical.com>
Cc: "Luis R. Rodriguez" <mcgrof@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/base/firmware_class.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 22d1760a4278..98c4f28ad2a1 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -546,11 +546,13 @@ static ssize_t timeout_store(struct class *class, struct class_attribute *attr,
 
 	return count;
 }
+static CLASS_ATTR_RW(timeout);
 
-static struct class_attribute firmware_class_attrs[] = {
-	__ATTR_RW(timeout),
-	__ATTR_NULL
+static struct attribute *firmware_class_attrs[] = {
+	&class_attr_timeout.attr,
+	NULL,
 };
+ATTRIBUTE_GROUPS(firmware_class);
 
 static void fw_dev_release(struct device *dev)
 {
@@ -585,7 +587,7 @@ static int firmware_uevent(struct device *dev, struct kobj_uevent_env *env)
 
 static struct class firmware_class = {
 	.name		= "firmware",
-	.class_attrs	= firmware_class_attrs,
+	.class_groups	= firmware_class_groups,
 	.dev_uevent	= firmware_uevent,
 	.dev_release	= fw_dev_release,
 };
-- 
2.10.2

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

* Re: [PATCH 2/3] driver core: devcoredump: convert to use class_groups
  2016-11-28 15:41 ` [PATCH 2/3] driver core: devcoredump: convert to use class_groups Greg Kroah-Hartman
  2016-11-28 15:42   ` [PATCH 3/3] driver core: firmware_class: " Greg Kroah-Hartman
@ 2016-11-28 15:48   ` Johannes Berg
  1 sibling, 0 replies; 5+ messages in thread
From: Johannes Berg @ 2016-11-28 15:48 UTC (permalink / raw)
  To: Greg Kroah-Hartman, linux-kernel; +Cc: Ming Lei, Luis R. Rodriguez

On Mon, 2016-11-28 at 16:41 +0100, Greg Kroah-Hartman wrote:
> Convert devcoredump to use class_groups instead of class_attrs as
> that's
> the correct way to handle lists of class attribute files.

Fine with me, of course

Acked-by: Johannes Berg <johannes@sipsolutions.net>

johannes

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

* Re: [PATCH 3/3] driver core: firmware_class: convert to use class_groups
  2016-11-28 15:42   ` [PATCH 3/3] driver core: firmware_class: " Greg Kroah-Hartman
@ 2016-11-29 18:01     ` Luis R. Rodriguez
  0 siblings, 0 replies; 5+ messages in thread
From: Luis R. Rodriguez @ 2016-11-29 18:01 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, Johannes Berg, Ming Lei, Luis R. Rodriguez

On Mon, Nov 28, 2016 at 04:42:30PM +0100, Greg Kroah-Hartman wrote:
> Convert the firmware core to use class_groups instead of class_attrs as
> that's the correct way to handle lists of class attribute files.
> 
> Cc: Ming Lei <ming.lei@canonical.com>
> Cc: "Luis R. Rodriguez" <mcgrof@kernel.org>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Acked-by: Luis R. Rodriguez <mcgrof@kernel.org>

  Luis

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

end of thread, other threads:[~2016-11-29 18:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-28 15:41 [PATCH 1/3] driver core: class: add class_groups support Greg Kroah-Hartman
2016-11-28 15:41 ` [PATCH 2/3] driver core: devcoredump: convert to use class_groups Greg Kroah-Hartman
2016-11-28 15:42   ` [PATCH 3/3] driver core: firmware_class: " Greg Kroah-Hartman
2016-11-29 18:01     ` Luis R. Rodriguez
2016-11-28 15:48   ` [PATCH 2/3] driver core: devcoredump: " Johannes Berg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox