Skip to content

Commit b11cc9e

Browse files
rbmarlierehcahca
authored andcommitted
s390/zcrypt: make zcrypt_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 zcrypt_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 <[email protected]> Suggested-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: "Ricardo B. Marliere" <[email protected]> Acked-by: Harald Freudenberger <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Heiko Carstens <[email protected]>
1 parent 5f58bde commit b11cc9e

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

drivers/s390/crypto/zcrypt_api.c

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ EXPORT_SYMBOL(zcrypt_msgtype);
107107

108108
struct zcdn_device;
109109

110-
static struct class *zcrypt_class;
110+
static void zcdn_device_release(struct device *dev);
111+
static const struct class zcrypt_class = {
112+
.name = ZCRYPT_NAME,
113+
.dev_release = zcdn_device_release,
114+
};
111115
static dev_t zcrypt_devt;
112116
static struct cdev zcrypt_cdev;
113117

@@ -130,7 +134,7 @@ static int zcdn_destroy(const char *name);
130134
*/
131135
static inline struct zcdn_device *find_zcdndev_by_name(const char *name)
132136
{
133-
struct device *dev = class_find_device_by_name(zcrypt_class, name);
137+
struct device *dev = class_find_device_by_name(&zcrypt_class, name);
134138

135139
return dev ? to_zcdn_dev(dev) : NULL;
136140
}
@@ -142,7 +146,7 @@ static inline struct zcdn_device *find_zcdndev_by_name(const char *name)
142146
*/
143147
static inline struct zcdn_device *find_zcdndev_by_devt(dev_t devt)
144148
{
145-
struct device *dev = class_find_device_by_devt(zcrypt_class, devt);
149+
struct device *dev = class_find_device_by_devt(&zcrypt_class, devt);
146150

147151
return dev ? to_zcdn_dev(dev) : NULL;
148152
}
@@ -396,7 +400,7 @@ static int zcdn_create(const char *name)
396400
goto unlockout;
397401
}
398402
zcdndev->device.release = zcdn_device_release;
399-
zcdndev->device.class = zcrypt_class;
403+
zcdndev->device.class = &zcrypt_class;
400404
zcdndev->device.devt = devt;
401405
zcdndev->device.groups = zcdn_dev_attr_groups;
402406
if (name[0])
@@ -2077,12 +2081,9 @@ static int __init zcdn_init(void)
20772081
int rc;
20782082

20792083
/* create a new class 'zcrypt' */
2080-
zcrypt_class = class_create(ZCRYPT_NAME);
2081-
if (IS_ERR(zcrypt_class)) {
2082-
rc = PTR_ERR(zcrypt_class);
2083-
goto out_class_create_failed;
2084-
}
2085-
zcrypt_class->dev_release = zcdn_device_release;
2084+
rc = class_register(&zcrypt_class);
2085+
if (rc)
2086+
goto out_class_register_failed;
20862087

20872088
/* alloc device minor range */
20882089
rc = alloc_chrdev_region(&zcrypt_devt,
@@ -2098,35 +2099,35 @@ static int __init zcdn_init(void)
20982099
goto out_cdev_add_failed;
20992100

21002101
/* need some class specific sysfs attributes */
2101-
rc = class_create_file(zcrypt_class, &class_attr_zcdn_create);
2102+
rc = class_create_file(&zcrypt_class, &class_attr_zcdn_create);
21022103
if (rc)
21032104
goto out_class_create_file_1_failed;
2104-
rc = class_create_file(zcrypt_class, &class_attr_zcdn_destroy);
2105+
rc = class_create_file(&zcrypt_class, &class_attr_zcdn_destroy);
21052106
if (rc)
21062107
goto out_class_create_file_2_failed;
21072108

21082109
return 0;
21092110

21102111
out_class_create_file_2_failed:
2111-
class_remove_file(zcrypt_class, &class_attr_zcdn_create);
2112+
class_remove_file(&zcrypt_class, &class_attr_zcdn_create);
21122113
out_class_create_file_1_failed:
21132114
cdev_del(&zcrypt_cdev);
21142115
out_cdev_add_failed:
21152116
unregister_chrdev_region(zcrypt_devt, ZCRYPT_MAX_MINOR_NODES);
21162117
out_alloc_chrdev_failed:
2117-
class_destroy(zcrypt_class);
2118-
out_class_create_failed:
2118+
class_unregister(&zcrypt_class);
2119+
out_class_register_failed:
21192120
return rc;
21202121
}
21212122

21222123
static void zcdn_exit(void)
21232124
{
2124-
class_remove_file(zcrypt_class, &class_attr_zcdn_create);
2125-
class_remove_file(zcrypt_class, &class_attr_zcdn_destroy);
2125+
class_remove_file(&zcrypt_class, &class_attr_zcdn_create);
2126+
class_remove_file(&zcrypt_class, &class_attr_zcdn_destroy);
21262127
zcdn_destroy_all();
21272128
cdev_del(&zcrypt_cdev);
21282129
unregister_chrdev_region(zcrypt_devt, ZCRYPT_MAX_MINOR_NODES);
2129-
class_destroy(zcrypt_class);
2130+
class_unregister(&zcrypt_class);
21302131
}
21312132

21322133
/*

0 commit comments

Comments
 (0)