* [PATCH 0/2] vfio: constify struct class usage
@ 2024-03-01 17:51 Ricardo B. Marliere
2024-03-01 17:51 ` [PATCH 1/2] vfio/mdpy: make mdpy_class constant Ricardo B. Marliere
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Ricardo B. Marliere @ 2024-03-01 17:51 UTC (permalink / raw)
To: Kirti Wankhede; +Cc: kvm, linux-kernel, Greg Kroah-Hartman, Ricardo B. Marliere
This is a simple and straight forward cleanup series that aims to make the
class structures in vfio constant. This has been possible since 2023 [1].
---
[1]: https://lore.kernel.org/all/2023040248-customary-release-4aec@gregkh/
To: Kirti Wankhede <kwankhede@nvidia.com>
Cc: kvm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ricardo B. Marliere <ricardo@marliere.net>
---
Ricardo B. Marliere (2):
vfio/mdpy: make mdpy_class constant
vfio/mbochs: make mbochs_class constant
samples/vfio-mdev/mbochs.c | 18 ++++++++----------
samples/vfio-mdev/mdpy.c | 18 ++++++++----------
2 files changed, 16 insertions(+), 20 deletions(-)
---
base-commit: 87adedeba51a822533649b143232418b9e26d08b
change-id: 20240301-class_cleanup-vfio-3c5f72230ba5
Best regards,
--
Ricardo B. Marliere <ricardo@marliere.net>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] vfio/mdpy: make mdpy_class constant
2024-03-01 17:51 [PATCH 0/2] vfio: constify struct class usage Ricardo B. Marliere
@ 2024-03-01 17:51 ` Ricardo B. Marliere
2024-03-01 17:51 ` [PATCH 2/2] vfio/mbochs: make mbochs_class constant Ricardo B. Marliere
2024-03-05 23:12 ` [PATCH 0/2] vfio: constify struct class usage Alex Williamson
2 siblings, 0 replies; 4+ messages in thread
From: Ricardo B. Marliere @ 2024-03-01 17:51 UTC (permalink / raw)
To: Kirti Wankhede; +Cc: kvm, linux-kernel, Greg Kroah-Hartman, Ricardo B. Marliere
Since commit 43a7206b0963 ("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>
---
samples/vfio-mdev/mdpy.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/samples/vfio-mdev/mdpy.c b/samples/vfio-mdev/mdpy.c
index 72ea5832c927..27795501de6e 100644
--- a/samples/vfio-mdev/mdpy.c
+++ b/samples/vfio-mdev/mdpy.c
@@ -84,7 +84,9 @@ static struct mdev_type *mdpy_mdev_types[] = {
};
static dev_t mdpy_devt;
-static struct class *mdpy_class;
+static const struct class mdpy_class = {
+ .name = MDPY_CLASS_NAME,
+};
static struct cdev mdpy_cdev;
static struct device mdpy_dev;
static struct mdev_parent mdpy_parent;
@@ -709,13 +711,10 @@ static int __init mdpy_dev_init(void)
if (ret)
goto err_cdev;
- mdpy_class = class_create(MDPY_CLASS_NAME);
- if (IS_ERR(mdpy_class)) {
- pr_err("Error: failed to register mdpy_dev class\n");
- ret = PTR_ERR(mdpy_class);
+ ret = class_register(&mdpy_class);
+ if (ret)
goto err_driver;
- }
- mdpy_dev.class = mdpy_class;
+ mdpy_dev.class = &mdpy_class;
mdpy_dev.release = mdpy_device_release;
dev_set_name(&mdpy_dev, "%s", MDPY_NAME);
@@ -735,7 +734,7 @@ static int __init mdpy_dev_init(void)
device_del(&mdpy_dev);
err_put:
put_device(&mdpy_dev);
- class_destroy(mdpy_class);
+ class_unregister(&mdpy_class);
err_driver:
mdev_unregister_driver(&mdpy_driver);
err_cdev:
@@ -753,8 +752,7 @@ static void __exit mdpy_dev_exit(void)
mdev_unregister_driver(&mdpy_driver);
cdev_del(&mdpy_cdev);
unregister_chrdev_region(mdpy_devt, MINORMASK + 1);
- class_destroy(mdpy_class);
- mdpy_class = NULL;
+ class_unregister(&mdpy_class);
}
module_param_named(count, mdpy_driver.max_instances, int, 0444);
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] vfio/mbochs: make mbochs_class constant
2024-03-01 17:51 [PATCH 0/2] vfio: constify struct class usage Ricardo B. Marliere
2024-03-01 17:51 ` [PATCH 1/2] vfio/mdpy: make mdpy_class constant Ricardo B. Marliere
@ 2024-03-01 17:51 ` Ricardo B. Marliere
2024-03-05 23:12 ` [PATCH 0/2] vfio: constify struct class usage Alex Williamson
2 siblings, 0 replies; 4+ messages in thread
From: Ricardo B. Marliere @ 2024-03-01 17:51 UTC (permalink / raw)
To: Kirti Wankhede; +Cc: kvm, linux-kernel, Greg Kroah-Hartman, Ricardo B. Marliere
Since commit 43a7206b0963 ("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 mbochs_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>
---
samples/vfio-mdev/mbochs.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c
index 93405264ff23..9062598ea03d 100644
--- a/samples/vfio-mdev/mbochs.c
+++ b/samples/vfio-mdev/mbochs.c
@@ -133,7 +133,9 @@ static struct mdev_type *mbochs_mdev_types[] = {
};
static dev_t mbochs_devt;
-static struct class *mbochs_class;
+static const struct class mbochs_class = {
+ .name = MBOCHS_CLASS_NAME,
+};
static struct cdev mbochs_cdev;
static struct device mbochs_dev;
static struct mdev_parent mbochs_parent;
@@ -1422,13 +1424,10 @@ static int __init mbochs_dev_init(void)
if (ret)
goto err_cdev;
- mbochs_class = class_create(MBOCHS_CLASS_NAME);
- if (IS_ERR(mbochs_class)) {
- pr_err("Error: failed to register mbochs_dev class\n");
- ret = PTR_ERR(mbochs_class);
+ ret = class_register(&mbochs_class);
+ if (ret)
goto err_driver;
- }
- mbochs_dev.class = mbochs_class;
+ mbochs_dev.class = &mbochs_class;
mbochs_dev.release = mbochs_device_release;
dev_set_name(&mbochs_dev, "%s", MBOCHS_NAME);
@@ -1448,7 +1447,7 @@ static int __init mbochs_dev_init(void)
device_del(&mbochs_dev);
err_put:
put_device(&mbochs_dev);
- class_destroy(mbochs_class);
+ class_unregister(&mbochs_class);
err_driver:
mdev_unregister_driver(&mbochs_driver);
err_cdev:
@@ -1466,8 +1465,7 @@ static void __exit mbochs_dev_exit(void)
mdev_unregister_driver(&mbochs_driver);
cdev_del(&mbochs_cdev);
unregister_chrdev_region(mbochs_devt, MINORMASK + 1);
- class_destroy(mbochs_class);
- mbochs_class = NULL;
+ class_unregister(&mbochs_class);
}
MODULE_IMPORT_NS(DMA_BUF);
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] vfio: constify struct class usage
2024-03-01 17:51 [PATCH 0/2] vfio: constify struct class usage Ricardo B. Marliere
2024-03-01 17:51 ` [PATCH 1/2] vfio/mdpy: make mdpy_class constant Ricardo B. Marliere
2024-03-01 17:51 ` [PATCH 2/2] vfio/mbochs: make mbochs_class constant Ricardo B. Marliere
@ 2024-03-05 23:12 ` Alex Williamson
2 siblings, 0 replies; 4+ messages in thread
From: Alex Williamson @ 2024-03-05 23:12 UTC (permalink / raw)
To: Ricardo B. Marliere; +Cc: Kirti Wankhede, kvm, linux-kernel, Greg Kroah-Hartman
On Fri, 01 Mar 2024 14:51:46 -0300
"Ricardo B. Marliere" <ricardo@marliere.net> wrote:
> This is a simple and straight forward cleanup series that aims to make the
> class structures in vfio constant. This has been possible since 2023 [1].
>
> ---
> [1]: https://lore.kernel.org/all/2023040248-customary-release-4aec@gregkh/
>
> To: Kirti Wankhede <kwankhede@nvidia.com>
> Cc: kvm@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Ricardo B. Marliere <ricardo@marliere.net>
>
> ---
> Ricardo B. Marliere (2):
> vfio/mdpy: make mdpy_class constant
> vfio/mbochs: make mbochs_class constant
>
> samples/vfio-mdev/mbochs.c | 18 ++++++++----------
> samples/vfio-mdev/mdpy.c | 18 ++++++++----------
> 2 files changed, 16 insertions(+), 20 deletions(-)
> ---
> base-commit: 87adedeba51a822533649b143232418b9e26d08b
> change-id: 20240301-class_cleanup-vfio-3c5f72230ba5
>
> Best regards,
Applied to vfio next branch for v6.9. Thanks,
Alex
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-03-05 23:13 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-01 17:51 [PATCH 0/2] vfio: constify struct class usage Ricardo B. Marliere
2024-03-01 17:51 ` [PATCH 1/2] vfio/mdpy: make mdpy_class constant Ricardo B. Marliere
2024-03-01 17:51 ` [PATCH 2/2] vfio/mbochs: make mbochs_class constant Ricardo B. Marliere
2024-03-05 23:12 ` [PATCH 0/2] vfio: constify struct class usage Alex Williamson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox