[PATCH 6/6] s390: raw3270: make class3270 constant

From: Ricardo B. Marliere
Date: Tue Mar 05 2024 - 06:29:43 EST


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 class3270 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@xxxxxxxxxxxxxxxxxxx>
Suggested-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
Signed-off-by: Ricardo B. Marliere <ricardo@xxxxxxxxxxxx>
---
drivers/s390/char/fs3270.c | 8 ++++----
drivers/s390/char/raw3270.c | 13 ++++++++-----
drivers/s390/char/raw3270.h | 2 +-
3 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/drivers/s390/char/fs3270.c b/drivers/s390/char/fs3270.c
index 4f26b0a55620..f83ec248e68e 100644
--- a/drivers/s390/char/fs3270.c
+++ b/drivers/s390/char/fs3270.c
@@ -521,13 +521,13 @@ static const struct file_operations fs3270_fops = {
static void fs3270_create_cb(int minor)
{
__register_chrdev(IBM_FS3270_MAJOR, minor, 1, "tub", &fs3270_fops);
- device_create(class3270, NULL, MKDEV(IBM_FS3270_MAJOR, minor),
+ device_create(&class3270, NULL, MKDEV(IBM_FS3270_MAJOR, minor),
NULL, "3270/tub%d", minor);
}

static void fs3270_destroy_cb(int minor)
{
- device_destroy(class3270, MKDEV(IBM_FS3270_MAJOR, minor));
+ device_destroy(&class3270, MKDEV(IBM_FS3270_MAJOR, minor));
__unregister_chrdev(IBM_FS3270_MAJOR, minor, 1, "tub");
}

@@ -546,7 +546,7 @@ static int __init fs3270_init(void)
rc = __register_chrdev(IBM_FS3270_MAJOR, 0, 1, "fs3270", &fs3270_fops);
if (rc)
return rc;
- device_create(class3270, NULL, MKDEV(IBM_FS3270_MAJOR, 0),
+ device_create(&class3270, NULL, MKDEV(IBM_FS3270_MAJOR, 0),
NULL, "3270/tub");
raw3270_register_notifier(&fs3270_notifier);
return 0;
@@ -555,7 +555,7 @@ static int __init fs3270_init(void)
static void __exit fs3270_exit(void)
{
raw3270_unregister_notifier(&fs3270_notifier);
- device_destroy(class3270, MKDEV(IBM_FS3270_MAJOR, 0));
+ device_destroy(&class3270, MKDEV(IBM_FS3270_MAJOR, 0));
__unregister_chrdev(IBM_FS3270_MAJOR, 0, 1, "fs3270");
}

diff --git a/drivers/s390/char/raw3270.c b/drivers/s390/char/raw3270.c
index acc4cb37a9d8..8e9868581e0a 100644
--- a/drivers/s390/char/raw3270.c
+++ b/drivers/s390/char/raw3270.c
@@ -29,7 +29,9 @@
#include <linux/device.h>
#include <linux/mutex.h>

-struct class *class3270;
+const struct class class3270 = {
+ .name = "3270",
+};
EXPORT_SYMBOL(class3270);

/* The main 3270 data structure. */
@@ -1315,13 +1317,14 @@ static int raw3270_init(void)
if (raw3270_registered)
return 0;
raw3270_registered = 1;
+
rc = ccw_driver_register(&raw3270_ccw_driver);
if (rc)
return rc;

- class3270 = class_create("3270");
- if (IS_ERR(class3270))
- return PTR_ERR(class3270);
+ rc = class_register(&class3270);
+ if (rc)
+ return rc;

/* Create attributes for early (= console) device. */
mutex_lock(&raw3270_mutex);
@@ -1337,7 +1340,7 @@ static int raw3270_init(void)
static void raw3270_exit(void)
{
ccw_driver_unregister(&raw3270_ccw_driver);
- class_destroy(class3270);
+ class_unregister(&class3270);
}

MODULE_LICENSE("GPL");
diff --git a/drivers/s390/char/raw3270.h b/drivers/s390/char/raw3270.h
index b1beecc7a0a9..5040c7e0e051 100644
--- a/drivers/s390/char/raw3270.h
+++ b/drivers/s390/char/raw3270.h
@@ -14,7 +14,7 @@

struct raw3270;
struct raw3270_view;
-extern struct class *class3270;
+extern const struct class class3270;

/* 3270 CCW request */
struct raw3270_request {

--
2.43.0