2017-06-08 08:12:57

by Greg Kroah-Hartman

[permalink] [raw]
Subject: [PATCH 0/7] Driver core: remove class_attrs from struct class

Some more patches that have long been sitting in a local tree...

The class_attrs field in struct class duplicates the same effort that
class_groups implements, so let's finally get rid of the last few users
of this field, and delete it, and the duplicated logic in the driver
core.

Subsystem maintainers, I'm glad to take this series in my driver core
tree, if you just want to ack your respective patches, that's fine with
me.

This series has passed 0-day test-builds from what I can tell.

Greg Kroah-Hartman (7):
uwb: use class_groups instead of class_attrs
scsi: ibmvscsi_tgt: remove use of class_attrs
mtd: use class_groups instead of class_attrs
zram: use class_groups instead of class_attrs
gpio: use class_groups instead of class_attrs
pktcdvd: use class_groups instead of class_attrs
driver core: remove class_attrs from struct class

drivers/base/class.c | 33 ------------------------------
drivers/block/pktcdvd.c | 35 ++++++++++++++++----------------
drivers/block/zram/zram_drv.c | 26 ++++++++++++++----------
drivers/gpio/gpiolib-sysfs.c | 13 +++++++-----
drivers/mtd/ubi/build.c | 16 ++++++++-------
drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c | 5 -----
drivers/uwb/driver.c | 11 +++++-----
include/linux/device.h | 2 --
8 files changed, 55 insertions(+), 86 deletions(-)

--
2.13.1


2017-06-08 08:12:52

by Greg Kroah-Hartman

[permalink] [raw]
Subject: [PATCH 1/7] uwb: use class_groups instead of class_attrs

The class_attrs pointer is long depreciated, and is about to be finally
removed, so move to use the class_groups pointer instead.

Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/uwb/driver.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/uwb/driver.c b/drivers/uwb/driver.c
index 776bcb3c2140..ff2d4240b24a 100644
--- a/drivers/uwb/driver.c
+++ b/drivers/uwb/driver.c
@@ -94,17 +94,18 @@ ssize_t beacon_timeout_ms_store(struct class *class,
beacon_timeout_ms = bt;
return size;
}
+static CLASS_ATTR_RW(beacon_timeout_ms);

-static struct class_attribute uwb_class_attrs[] = {
- __ATTR(beacon_timeout_ms, S_IWUSR | S_IRUGO,
- beacon_timeout_ms_show, beacon_timeout_ms_store),
- __ATTR_NULL,
+static struct attribute *uwb_class_attrs[] = {
+ &class_attr_beacon_timeout_ms.attr,
+ NULL,
};
+ATTRIBUTE_GROUPS(uwb_class);

/** Device model classes */
struct class uwb_rc_class = {
.name = "uwb_rc",
- .class_attrs = uwb_class_attrs,
+ .class_groups = uwb_class_groups,
};


--
2.13.1

2017-06-08 08:13:08

by Greg Kroah-Hartman

[permalink] [raw]
Subject: [PATCH 2/7] scsi: ibmvscsi_tgt: remove use of class_attrs

The class_attrs pointer is going away and it's not even being used in
this driver, so just remove it entirely.

Cc: "Bryant G. Ly" <[email protected]>
Cc: Michael Cyr <[email protected]>
Cc: "James E.J. Bottomley" <[email protected]>
Cc: "Martin K. Petersen" <[email protected]>
Cc: <[email protected]>
Cc: <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c | 5 -----
1 file changed, 5 deletions(-)

diff --git a/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c b/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c
index d390325c99ec..b480878e3258 100644
--- a/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c
+++ b/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c
@@ -3915,10 +3915,6 @@ static const struct target_core_fabric_ops ibmvscsis_ops = {

static void ibmvscsis_dev_release(struct device *dev) {};

-static struct class_attribute ibmvscsis_class_attrs[] = {
- __ATTR_NULL,
-};
-
static struct device_attribute dev_attr_system_id =
__ATTR(system_id, S_IRUGO, system_id_show, NULL);

@@ -3938,7 +3934,6 @@ ATTRIBUTE_GROUPS(ibmvscsis_dev);
static struct class ibmvscsis_class = {
.name = "ibmvscsis",
.dev_release = ibmvscsis_dev_release,
- .class_attrs = ibmvscsis_class_attrs,
.dev_groups = ibmvscsis_dev_groups,
};

--
2.13.1

2017-06-08 08:13:11

by Greg Kroah-Hartman

[permalink] [raw]
Subject: [PATCH 6/7] pktcdvd: use class_groups instead of class_attrs

The class_attrs pointer is long depreciated, and is about to be finally
removed, so move to use the class_groups pointer instead.

Cc: <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: Hannes Reinecke <[email protected]>
Cc: Jan Kara <[email protected]>
Cc: Mike Christie <[email protected]>
Cc: Bart Van Assche <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/block/pktcdvd.c | 35 +++++++++++++++++------------------
1 file changed, 17 insertions(+), 18 deletions(-)

diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 205b865ebeb9..98939ee97476 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -348,9 +348,9 @@ static void class_pktcdvd_release(struct class *cls)
{
kfree(cls);
}
-static ssize_t class_pktcdvd_show_map(struct class *c,
- struct class_attribute *attr,
- char *data)
+
+static ssize_t device_map_show(struct class *c, struct class_attribute *attr,
+ char *data)
{
int n = 0;
int idx;
@@ -368,11 +368,10 @@ static ssize_t class_pktcdvd_show_map(struct class *c,
mutex_unlock(&ctl_mutex);
return n;
}
+static CLASS_ATTR_RO(device_map);

-static ssize_t class_pktcdvd_store_add(struct class *c,
- struct class_attribute *attr,
- const char *buf,
- size_t count)
+static ssize_t add_store(struct class *c, struct class_attribute *attr,
+ const char *buf, size_t count)
{
unsigned int major, minor;

@@ -390,11 +389,10 @@ static ssize_t class_pktcdvd_store_add(struct class *c,

return -EINVAL;
}
+static CLASS_ATTR_WO(add);

-static ssize_t class_pktcdvd_store_remove(struct class *c,
- struct class_attribute *attr,
- const char *buf,
- size_t count)
+static ssize_t remove_store(struct class *c, struct class_attribute *attr,
+ const char *buf, size_t count)
{
unsigned int major, minor;
if (sscanf(buf, "%u:%u", &major, &minor) == 2) {
@@ -403,14 +401,15 @@ static ssize_t class_pktcdvd_store_remove(struct class *c,
}
return -EINVAL;
}
+static CLASS_ATTR_WO(remove);

-static struct class_attribute class_pktcdvd_attrs[] = {
- __ATTR(add, 0200, NULL, class_pktcdvd_store_add),
- __ATTR(remove, 0200, NULL, class_pktcdvd_store_remove),
- __ATTR(device_map, 0444, class_pktcdvd_show_map, NULL),
- __ATTR_NULL
+static struct attribute *class_pktcdvd_attrs[] = {
+ &class_attr_add.attr,
+ &class_attr_remove.attr,
+ &class_attr_device_map.attr,
+ NULL,
};
-
+ATTRIBUTE_GROUPS(class_pktcdvd);

static int pkt_sysfs_init(void)
{
@@ -426,7 +425,7 @@ static int pkt_sysfs_init(void)
class_pktcdvd->name = DRIVER_NAME;
class_pktcdvd->owner = THIS_MODULE;
class_pktcdvd->class_release = class_pktcdvd_release;
- class_pktcdvd->class_attrs = class_pktcdvd_attrs;
+ class_pktcdvd->class_groups = class_pktcdvd_groups;
ret = class_register(class_pktcdvd);
if (ret) {
kfree(class_pktcdvd);
--
2.13.1

2017-06-08 08:13:19

by Greg Kroah-Hartman

[permalink] [raw]
Subject: [PATCH 7/7] driver core: remove class_attrs from struct class

This field is no longer used or needed (use class_groups instead), so it
can be removed along with the driver core functionality that created and
removed these files.

Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/class.c | 33 ---------------------------------
include/linux/device.h | 2 --
2 files changed, 35 deletions(-)

diff --git a/drivers/base/class.c b/drivers/base/class.c
index a2b2896693d6..52eb8e644acd 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -119,36 +119,6 @@ static void class_put(struct class *cls)
kset_put(&cls->p->subsys);
}

-static int add_class_attrs(struct class *cls)
-{
- int i;
- int error = 0;
-
- if (cls->class_attrs) {
- for (i = 0; cls->class_attrs[i].attr.name; i++) {
- error = class_create_file(cls, &cls->class_attrs[i]);
- if (error)
- goto error;
- }
- }
-done:
- return error;
-error:
- while (--i >= 0)
- class_remove_file(cls, &cls->class_attrs[i]);
- goto done;
-}
-
-static void remove_class_attrs(struct class *cls)
-{
- int i;
-
- if (cls->class_attrs) {
- for (i = 0; cls->class_attrs[i].attr.name; i++)
- class_remove_file(cls, &cls->class_attrs[i]);
- }
-}
-
static void klist_class_dev_get(struct klist_node *n)
{
struct device *dev = container_of(n, struct device, knode_class);
@@ -217,8 +187,6 @@ int __class_register(struct class *cls, struct lock_class_key *key)
}
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;
}
EXPORT_SYMBOL_GPL(__class_register);
@@ -226,7 +194,6 @@ EXPORT_SYMBOL_GPL(__class_register);
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 9ef518af5515..000d94b03964 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -365,7 +365,6 @@ int subsys_virtual_register(struct bus_type *subsys,
* struct class - device classes
* @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.
@@ -394,7 +393,6 @@ struct class {
const char *name;
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.13.1

2017-06-08 08:13:07

by Greg Kroah-Hartman

[permalink] [raw]
Subject: [PATCH 4/7] zram: use class_groups instead of class_attrs

The class_attrs pointer is long depreciated, and is about to be finally
removed, so move to use the class_groups pointer instead.

Cc: Minchan Kim <[email protected]>
Cc: Nitin Gupta <[email protected]>
Cc: Sergey Senozhatsky <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/block/zram/zram_drv.c | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index debee952dcc1..ebf5a45a0277 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1272,6 +1272,13 @@ static int zram_remove(struct zram *zram)
}

/* zram-control sysfs attributes */
+
+/*
+ * NOTE: hot_add attribute is not the usual read-only sysfs attribute. In a
+ * sense that reading from this file does alter the state of your system -- it
+ * creates a new un-initialized zram device and returns back this device's
+ * device_id (or an error code if it fails to create a new device).
+ */
static ssize_t hot_add_show(struct class *class,
struct class_attribute *attr,
char *buf)
@@ -1286,6 +1293,7 @@ static ssize_t hot_add_show(struct class *class,
return ret;
return scnprintf(buf, PAGE_SIZE, "%d\n", ret);
}
+static CLASS_ATTR(hot_add, 0400, hot_add_show, NULL);

static ssize_t hot_remove_store(struct class *class,
struct class_attribute *attr,
@@ -1316,23 +1324,19 @@ static ssize_t hot_remove_store(struct class *class,
mutex_unlock(&zram_index_mutex);
return ret ? ret : count;
}
+static CLASS_ATTR_WO(hot_remove);

-/*
- * NOTE: hot_add attribute is not the usual read-only sysfs attribute. In a
- * sense that reading from this file does alter the state of your system -- it
- * creates a new un-initialized zram device and returns back this device's
- * device_id (or an error code if it fails to create a new device).
- */
-static struct class_attribute zram_control_class_attrs[] = {
- __ATTR(hot_add, 0400, hot_add_show, NULL),
- __ATTR_WO(hot_remove),
- __ATTR_NULL,
+static struct attribute *zram_control_class_attrs[] = {
+ &class_attr_hot_add.attr,
+ &class_attr_hot_remove.attr,
+ NULL,
};
+ATTRIBUTE_GROUPS(zram_control_class);

static struct class zram_control_class = {
.name = "zram-control",
.owner = THIS_MODULE,
- .class_attrs = zram_control_class_attrs,
+ .class_groups = zram_control_class_groups,
};

static int zram_remove_cb(int id, void *ptr, void *data)
--
2.13.1

2017-06-08 08:14:52

by Greg Kroah-Hartman

[permalink] [raw]
Subject: [PATCH 3/7] mtd: use class_groups instead of class_attrs

The class_attrs pointer is long depreciated, and is about to be finally
removed, so move to use the class_groups pointer instead.

Cc: Artem Bityutskiy <[email protected]>
Cc: Richard Weinberger <[email protected]>
Cc: David Woodhouse <[email protected]>
Cc: Brian Norris <[email protected]>
Cc: Boris Brezillon <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Cyrille Pitchen <[email protected]>
Cc: <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/mtd/ubi/build.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 93e5d251a9e4..d854521962ef 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -104,23 +104,25 @@ DEFINE_MUTEX(ubi_devices_mutex);
static DEFINE_SPINLOCK(ubi_devices_lock);

/* "Show" method for files in '/<sysfs>/class/ubi/' */
-static ssize_t ubi_version_show(struct class *class,
- struct class_attribute *attr, char *buf)
+/* UBI version attribute ('/<sysfs>/class/ubi/version') */
+static ssize_t version_show(struct class *class, struct class_attribute *attr,
+ char *buf)
{
return sprintf(buf, "%d\n", UBI_VERSION);
}
+static CLASS_ATTR_RO(version);

-/* UBI version attribute ('/<sysfs>/class/ubi/version') */
-static struct class_attribute ubi_class_attrs[] = {
- __ATTR(version, S_IRUGO, ubi_version_show, NULL),
- __ATTR_NULL
+static struct attribute *ubi_class_attrs[] = {
+ &class_attr_version.attr,
+ NULL,
};
+ATTRIBUTE_GROUPS(ubi_class);

/* Root UBI "class" object (corresponds to '/<sysfs>/class/ubi/') */
struct class ubi_class = {
.name = UBI_NAME_STR,
.owner = THIS_MODULE,
- .class_attrs = ubi_class_attrs,
+ .class_groups = ubi_class_groups,
};

static ssize_t dev_attribute_show(struct device *dev,
--
2.13.1

2017-06-08 08:15:20

by Greg Kroah-Hartman

[permalink] [raw]
Subject: [PATCH 5/7] gpio: use class_groups instead of class_attrs

The class_attrs pointer is long depreciated, and is about to be finally
removed, so move to use the class_groups pointer instead.

Cc: Linus Walleij <[email protected]>
Cc: Alexandre Courbot <[email protected]>
Cc: <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/gpio/gpiolib-sysfs.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index 4b44dd97c07f..16fe9742597b 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -479,6 +479,7 @@ static ssize_t export_store(struct class *class,
pr_debug("%s: status %d\n", __func__, status);
return status ? : len;
}
+static CLASS_ATTR_WO(export);

static ssize_t unexport_store(struct class *class,
struct class_attribute *attr,
@@ -514,18 +515,20 @@ static ssize_t unexport_store(struct class *class,
pr_debug("%s: status %d\n", __func__, status);
return status ? : len;
}
+static CLASS_ATTR_WO(unexport);

-static struct class_attribute gpio_class_attrs[] = {
- __ATTR(export, 0200, NULL, export_store),
- __ATTR(unexport, 0200, NULL, unexport_store),
- __ATTR_NULL,
+static struct attribute *gpio_class_attrs[] = {
+ &class_attr_export.attr,
+ &class_attr_unexport.attr,
+ NULL,
};
+ATTRIBUTE_GROUPS(gpio_class);

static struct class gpio_class = {
.name = "gpio",
.owner = THIS_MODULE,

- .class_attrs = gpio_class_attrs,
+ .class_groups = gpio_class_groups,
};


--
2.13.1

2017-06-08 09:30:44

by Robert P. J. Day

[permalink] [raw]
Subject: Re: [PATCH 5/7] gpio: use class_groups instead of class_attrs

On Thu, 8 Jun 2017, Greg Kroah-Hartman wrote:

> The class_attrs pointer is long depreciated, and is about to be finally
^^^^^^^^^^^ deprecated

rday

--

========================================================================
Robert P. J. Day Ottawa, Ontario, CANADA
http://crashcourse.ca

Twitter: http://twitter.com/rpjday
LinkedIn: http://ca.linkedin.com/in/rpjday
========================================================================

2017-06-08 10:23:48

by Richard Weinberger

[permalink] [raw]
Subject: Re: [PATCH 3/7] mtd: use class_groups instead of class_attrs

Am 08.06.2017 um 10:12 schrieb Greg Kroah-Hartman:
> The class_attrs pointer is long depreciated, and is about to be finally
> removed, so move to use the class_groups pointer instead.
>
> Cc: Artem Bityutskiy <[email protected]>
> Cc: Richard Weinberger <[email protected]>
> Cc: David Woodhouse <[email protected]>
> Cc: Brian Norris <[email protected]>
> Cc: Boris Brezillon <[email protected]>
> Cc: Marek Vasut <[email protected]>
> Cc: Cyrille Pitchen <[email protected]>
> Cc: <[email protected]>
> Signed-off-by: Greg Kroah-Hartman <[email protected]>

Acked-by: Richard Weinberger <[email protected]>

Thanks,
//richard

2017-06-08 12:05:25

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH 5/7] gpio: use class_groups instead of class_attrs

On Thu, Jun 8, 2017 at 10:12 AM, Greg Kroah-Hartman
<[email protected]> wrote:

> The class_attrs pointer is long depreciated, and is about to be finally
> removed, so move to use the class_groups pointer instead.
>
> Cc: Linus Walleij <[email protected]>
> Cc: Alexandre Courbot <[email protected]>
> Cc: <[email protected]>
> Signed-off-by: Greg Kroah-Hartman <[email protected]>

Acked-by: Linus Walleij <[email protected]>

Please take this through the driver core tree.

Yours,
Linus Walleij

2017-06-08 12:31:52

by Bryant G. Ly

[permalink] [raw]
Subject: Re: [PATCH 2/7] scsi: ibmvscsi_tgt: remove use of class_attrs


> The class_attrs pointer is going away and it's not even being used in
> this driver, so just remove it entirely.
>
> Cc: "Bryant G. Ly" <[email protected]>
> Cc: Michael Cyr <[email protected]>
> Cc: "James E.J. Bottomley" <[email protected]>
> Cc: "Martin K. Petersen" <[email protected]>
> Cc: <[email protected]>
> Cc: <[email protected]>
> Signed-off-by: Greg Kroah-Hartman <[email protected]>
> ---
> drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c | 5 -----
> 1 file changed, 5 deletions(-)
>
> diff --git a/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c b/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c
> index d390325c99ec..b480878e3258 100644
> --- a/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c
> +++ b/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c
> @@ -3915,10 +3915,6 @@ static const struct target_core_fabric_ops ibmvscsis_ops = {
>
> static void ibmvscsis_dev_release(struct device *dev) {};
>
> -static struct class_attribute ibmvscsis_class_attrs[] = {
> - __ATTR_NULL,
> -};
> -
> static struct device_attribute dev_attr_system_id =
> __ATTR(system_id, S_IRUGO, system_id_show, NULL);
>
> @@ -3938,7 +3934,6 @@ ATTRIBUTE_GROUPS(ibmvscsis_dev);
> static struct class ibmvscsis_class = {
> .name = "ibmvscsis",
> .dev_release = ibmvscsis_dev_release,
> - .class_attrs = ibmvscsis_class_attrs,
> .dev_groups = ibmvscsis_dev_groups,
> };
>
Thanks Greg, ACK.

-Bryant


2017-06-08 14:07:07

by Jens Axboe

[permalink] [raw]
Subject: Re: [PATCH 6/7] pktcdvd: use class_groups instead of class_attrs

On 06/08/2017 02:12 AM, Greg Kroah-Hartman wrote:
> The class_attrs pointer is long depreciated, and is about to be finally
> removed, so move to use the class_groups pointer instead.

Feel free to add my Acked-by to this.

--
Jens Axboe

2017-06-09 05:39:25

by Sergey Senozhatsky

[permalink] [raw]
Subject: Re: [PATCH 4/7] zram: use class_groups instead of class_attrs

On (06/08/17 10:12), Greg Kroah-Hartman wrote:
> The class_attrs pointer is long depreciated, and is about to be finally
> removed, so move to use the class_groups pointer instead.
>
> Cc: Minchan Kim <[email protected]>
> Cc: Nitin Gupta <[email protected]>
> Cc: Sergey Senozhatsky <[email protected]>
> Signed-off-by: Greg Kroah-Hartman <[email protected]>

FWIW, looks good to me.

Reviewed-by: Sergey Senozhatsky <[email protected]>

-ss