Skip to content

Commit 1f92d6a

Browse files
rbmarliereawilliam
authored andcommitted
vfio/mdpy: make mdpy_class constant
Since commit 43a7206 ("driver core: class: make class_register() take a const *"), the driver core allows for struct class to be in read-only memory, so move the mdpy_class structure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at boot time. Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Ricardo B. Marliere <ricardo@marliere.net> Link: https://lore.kernel.org/r/20240301-class_cleanup-vfio-v1-1-9236d69083f5@marliere.net Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
1 parent fd94213 commit 1f92d6a

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

samples/vfio-mdev/mdpy.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ static struct mdev_type *mdpy_mdev_types[] = {
8484
};
8585

8686
static dev_t mdpy_devt;
87-
static struct class *mdpy_class;
87+
static const struct class mdpy_class = {
88+
.name = MDPY_CLASS_NAME,
89+
};
8890
static struct cdev mdpy_cdev;
8991
static struct device mdpy_dev;
9092
static struct mdev_parent mdpy_parent;
@@ -709,13 +711,10 @@ static int __init mdpy_dev_init(void)
709711
if (ret)
710712
goto err_cdev;
711713

712-
mdpy_class = class_create(MDPY_CLASS_NAME);
713-
if (IS_ERR(mdpy_class)) {
714-
pr_err("Error: failed to register mdpy_dev class\n");
715-
ret = PTR_ERR(mdpy_class);
714+
ret = class_register(&mdpy_class);
715+
if (ret)
716716
goto err_driver;
717-
}
718-
mdpy_dev.class = mdpy_class;
717+
mdpy_dev.class = &mdpy_class;
719718
mdpy_dev.release = mdpy_device_release;
720719
dev_set_name(&mdpy_dev, "%s", MDPY_NAME);
721720

@@ -735,7 +734,7 @@ static int __init mdpy_dev_init(void)
735734
device_del(&mdpy_dev);
736735
err_put:
737736
put_device(&mdpy_dev);
738-
class_destroy(mdpy_class);
737+
class_unregister(&mdpy_class);
739738
err_driver:
740739
mdev_unregister_driver(&mdpy_driver);
741740
err_cdev:
@@ -753,8 +752,7 @@ static void __exit mdpy_dev_exit(void)
753752
mdev_unregister_driver(&mdpy_driver);
754753
cdev_del(&mdpy_cdev);
755754
unregister_chrdev_region(mdpy_devt, MINORMASK + 1);
756-
class_destroy(mdpy_class);
757-
mdpy_class = NULL;
755+
class_unregister(&mdpy_class);
758756
}
759757

760758
module_param_named(count, mdpy_driver.max_instances, int, 0444);

0 commit comments

Comments
 (0)