diff mbox series

[1/4] block/rnbd: make all 'class' structures const

Message ID 20230620180129.645646-5-gregkh@linuxfoundation.org (mailing list archive)
State New, archived
Headers show
Series [1/4] block/rnbd: make all 'class' structures const | expand

Commit Message

Greg Kroah-Hartman June 20, 2023, 6:01 p.m. UTC
From: Ivan Orlov <ivan.orlov0322@gmail.com>

Now that the driver core allows for struct class to be in read-only
memory, making all 'class' structures to be declared at build time
placing them into read-only memory, instead of having to be dynamically
allocated at load time.

Cc: "Md. Haris Iqbal" <haris.iqbal@ionos.com>
Cc: Jack Wang <jinpu.wang@ionos.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org
Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/block/rnbd/rnbd-clt-sysfs.c | 20 +++++++++++---------
 drivers/block/rnbd/rnbd-srv-sysfs.c | 22 ++++++++++++----------
 2 files changed, 23 insertions(+), 19 deletions(-)

Comments

Jinpu Wang June 21, 2023, 10:10 a.m. UTC | #1
On Tue, Jun 20, 2023 at 8:01 PM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> From: Ivan Orlov <ivan.orlov0322@gmail.com>
>
> Now that the driver core allows for struct class to be in read-only
> memory, making all 'class' structures to be declared at build time
> placing them into read-only memory, instead of having to be dynamically
> allocated at load time.
>
> Cc: "Md. Haris Iqbal" <haris.iqbal@ionos.com>
> Cc: Jack Wang <jinpu.wang@ionos.com>
> Cc: Jens Axboe <axboe@kernel.dk>
> Cc: linux-block@vger.kernel.org
> Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
lgtm.
Acked-by: Jack Wang <jinpu.wang@ionos.com>
> ---
>  drivers/block/rnbd/rnbd-clt-sysfs.c | 20 +++++++++++---------
>  drivers/block/rnbd/rnbd-srv-sysfs.c | 22 ++++++++++++----------
>  2 files changed, 23 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/block/rnbd/rnbd-clt-sysfs.c b/drivers/block/rnbd/rnbd-clt-sysfs.c
> index 8c6087949794..e84abac04f4f 100644
> --- a/drivers/block/rnbd/rnbd-clt-sysfs.c
> +++ b/drivers/block/rnbd/rnbd-clt-sysfs.c
> @@ -24,7 +24,9 @@
>  #include "rnbd-clt.h"
>
>  static struct device *rnbd_dev;
> -static struct class *rnbd_dev_class;
> +static const struct class rnbd_dev_class = {
> +       .name = "rnbd_client",
> +};
>  static struct kobject *rnbd_devs_kobj;
>
>  enum {
> @@ -646,11 +648,11 @@ int rnbd_clt_create_sysfs_files(void)
>  {
>         int err;
>
> -       rnbd_dev_class = class_create("rnbd-client");
> -       if (IS_ERR(rnbd_dev_class))
> -               return PTR_ERR(rnbd_dev_class);
> +       err = class_register(&rnbd_dev_class);
> +       if (err)
> +               return err;
>
> -       rnbd_dev = device_create_with_groups(rnbd_dev_class, NULL,
> +       rnbd_dev = device_create_with_groups(&rnbd_dev_class, NULL,
>                                               MKDEV(0, 0), NULL,
>                                               default_attr_groups, "ctl");
>         if (IS_ERR(rnbd_dev)) {
> @@ -666,9 +668,9 @@ int rnbd_clt_create_sysfs_files(void)
>         return 0;
>
>  dev_destroy:
> -       device_destroy(rnbd_dev_class, MKDEV(0, 0));
> +       device_destroy(&rnbd_dev_class, MKDEV(0, 0));
>  cls_destroy:
> -       class_destroy(rnbd_dev_class);
> +       class_unregister(&rnbd_dev_class);
>
>         return err;
>  }
> @@ -678,6 +680,6 @@ void rnbd_clt_destroy_sysfs_files(void)
>         sysfs_remove_group(&rnbd_dev->kobj, &default_attr_group);
>         kobject_del(rnbd_devs_kobj);
>         kobject_put(rnbd_devs_kobj);
> -       device_destroy(rnbd_dev_class, MKDEV(0, 0));
> -       class_destroy(rnbd_dev_class);
> +       device_destroy(&rnbd_dev_class, MKDEV(0, 0));
> +       class_unregister(&rnbd_dev_class);
>  }
> diff --git a/drivers/block/rnbd/rnbd-srv-sysfs.c b/drivers/block/rnbd/rnbd-srv-sysfs.c
> index d5d9267e1fa5..5e69c0112e23 100644
> --- a/drivers/block/rnbd/rnbd-srv-sysfs.c
> +++ b/drivers/block/rnbd/rnbd-srv-sysfs.c
> @@ -20,7 +20,9 @@
>  #include "rnbd-srv.h"
>
>  static struct device *rnbd_dev;
> -static struct class *rnbd_dev_class;
> +static const struct class rnbd_dev_class = {
> +       .name = "rnbd-server",
> +};
>  static struct kobject *rnbd_devs_kobj;
>
>  static void rnbd_srv_dev_release(struct kobject *kobj)
> @@ -215,12 +217,12 @@ int rnbd_srv_create_sysfs_files(void)
>  {
>         int err;
>
> -       rnbd_dev_class = class_create("rnbd-server");
> -       if (IS_ERR(rnbd_dev_class))
> -               return PTR_ERR(rnbd_dev_class);
> +       err = class_register(&rnbd_dev_class);
> +       if (err)
> +               return err;
>
> -       rnbd_dev = device_create(rnbd_dev_class, NULL,
> -                                 MKDEV(0, 0), NULL, "ctl");
> +       rnbd_dev = device_create(&rnbd_dev_class, NULL,
> +                                MKDEV(0, 0), NULL, "ctl");
>         if (IS_ERR(rnbd_dev)) {
>                 err = PTR_ERR(rnbd_dev);
>                 goto cls_destroy;
> @@ -234,9 +236,9 @@ int rnbd_srv_create_sysfs_files(void)
>         return 0;
>
>  dev_destroy:
> -       device_destroy(rnbd_dev_class, MKDEV(0, 0));
> +       device_destroy(&rnbd_dev_class, MKDEV(0, 0));
>  cls_destroy:
> -       class_destroy(rnbd_dev_class);
> +       class_unregister(&rnbd_dev_class);
>
>         return err;
>  }
> @@ -245,6 +247,6 @@ void rnbd_srv_destroy_sysfs_files(void)
>  {
>         kobject_del(rnbd_devs_kobj);
>         kobject_put(rnbd_devs_kobj);
> -       device_destroy(rnbd_dev_class, MKDEV(0, 0));
> -       class_destroy(rnbd_dev_class);
> +       device_destroy(&rnbd_dev_class, MKDEV(0, 0));
> +       class_unregister(&rnbd_dev_class);
>  }
> --
> 2.41.0
>
Jens Axboe June 21, 2023, 1:46 p.m. UTC | #2
On Tue, 20 Jun 2023 20:01:30 +0200, Greg Kroah-Hartman wrote:
> Now that the driver core allows for struct class to be in read-only
> memory, making all 'class' structures to be declared at build time
> placing them into read-only memory, instead of having to be dynamically
> allocated at load time.
> 
> 

Applied, thanks!

[1/4] block/rnbd: make all 'class' structures const
      commit: 137380c0ec40710cbaf57c7878726c41a6da81cd
[2/4] aoe: make aoe_class a static const structure
      commit: 65d7a37d4e3e226bb4a4ddf73a827d0dbc77f530
[3/4] ublk: make ublk_chr_class a static const structure
      commit: 2eefd399d28a52739fdbeebe84775275f016171c
[4/4] bsg: make bsg_class a static const structure
      commit: 72ef02b8dfa009029fa713e8a731a92d27d14e35

Best regards,
diff mbox series

Patch

diff --git a/drivers/block/rnbd/rnbd-clt-sysfs.c b/drivers/block/rnbd/rnbd-clt-sysfs.c
index 8c6087949794..e84abac04f4f 100644
--- a/drivers/block/rnbd/rnbd-clt-sysfs.c
+++ b/drivers/block/rnbd/rnbd-clt-sysfs.c
@@ -24,7 +24,9 @@ 
 #include "rnbd-clt.h"
 
 static struct device *rnbd_dev;
-static struct class *rnbd_dev_class;
+static const struct class rnbd_dev_class = {
+	.name = "rnbd_client",
+};
 static struct kobject *rnbd_devs_kobj;
 
 enum {
@@ -646,11 +648,11 @@  int rnbd_clt_create_sysfs_files(void)
 {
 	int err;
 
-	rnbd_dev_class = class_create("rnbd-client");
-	if (IS_ERR(rnbd_dev_class))
-		return PTR_ERR(rnbd_dev_class);
+	err = class_register(&rnbd_dev_class);
+	if (err)
+		return err;
 
-	rnbd_dev = device_create_with_groups(rnbd_dev_class, NULL,
+	rnbd_dev = device_create_with_groups(&rnbd_dev_class, NULL,
 					      MKDEV(0, 0), NULL,
 					      default_attr_groups, "ctl");
 	if (IS_ERR(rnbd_dev)) {
@@ -666,9 +668,9 @@  int rnbd_clt_create_sysfs_files(void)
 	return 0;
 
 dev_destroy:
-	device_destroy(rnbd_dev_class, MKDEV(0, 0));
+	device_destroy(&rnbd_dev_class, MKDEV(0, 0));
 cls_destroy:
-	class_destroy(rnbd_dev_class);
+	class_unregister(&rnbd_dev_class);
 
 	return err;
 }
@@ -678,6 +680,6 @@  void rnbd_clt_destroy_sysfs_files(void)
 	sysfs_remove_group(&rnbd_dev->kobj, &default_attr_group);
 	kobject_del(rnbd_devs_kobj);
 	kobject_put(rnbd_devs_kobj);
-	device_destroy(rnbd_dev_class, MKDEV(0, 0));
-	class_destroy(rnbd_dev_class);
+	device_destroy(&rnbd_dev_class, MKDEV(0, 0));
+	class_unregister(&rnbd_dev_class);
 }
diff --git a/drivers/block/rnbd/rnbd-srv-sysfs.c b/drivers/block/rnbd/rnbd-srv-sysfs.c
index d5d9267e1fa5..5e69c0112e23 100644
--- a/drivers/block/rnbd/rnbd-srv-sysfs.c
+++ b/drivers/block/rnbd/rnbd-srv-sysfs.c
@@ -20,7 +20,9 @@ 
 #include "rnbd-srv.h"
 
 static struct device *rnbd_dev;
-static struct class *rnbd_dev_class;
+static const struct class rnbd_dev_class = {
+	.name = "rnbd-server",
+};
 static struct kobject *rnbd_devs_kobj;
 
 static void rnbd_srv_dev_release(struct kobject *kobj)
@@ -215,12 +217,12 @@  int rnbd_srv_create_sysfs_files(void)
 {
 	int err;
 
-	rnbd_dev_class = class_create("rnbd-server");
-	if (IS_ERR(rnbd_dev_class))
-		return PTR_ERR(rnbd_dev_class);
+	err = class_register(&rnbd_dev_class);
+	if (err)
+		return err;
 
-	rnbd_dev = device_create(rnbd_dev_class, NULL,
-				  MKDEV(0, 0), NULL, "ctl");
+	rnbd_dev = device_create(&rnbd_dev_class, NULL,
+				 MKDEV(0, 0), NULL, "ctl");
 	if (IS_ERR(rnbd_dev)) {
 		err = PTR_ERR(rnbd_dev);
 		goto cls_destroy;
@@ -234,9 +236,9 @@  int rnbd_srv_create_sysfs_files(void)
 	return 0;
 
 dev_destroy:
-	device_destroy(rnbd_dev_class, MKDEV(0, 0));
+	device_destroy(&rnbd_dev_class, MKDEV(0, 0));
 cls_destroy:
-	class_destroy(rnbd_dev_class);
+	class_unregister(&rnbd_dev_class);
 
 	return err;
 }
@@ -245,6 +247,6 @@  void rnbd_srv_destroy_sysfs_files(void)
 {
 	kobject_del(rnbd_devs_kobj);
 	kobject_put(rnbd_devs_kobj);
-	device_destroy(rnbd_dev_class, MKDEV(0, 0));
-	class_destroy(rnbd_dev_class);
+	device_destroy(&rnbd_dev_class, MKDEV(0, 0));
+	class_unregister(&rnbd_dev_class);
 }