Skip to content

Commit 6d3b27e

Browse files
rbmarlierealexdeucher
authored andcommitted
drm/amdkfd: make kfd_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 kfd_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> Signed-off-by: Felix Kuehling <felix.kuehling@amd.com> Reviewed-by: Felix Kuehling <felix.kuehling@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 5e59295 commit 6d3b27e

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ static const struct file_operations kfd_fops = {
6363
};
6464

6565
static int kfd_char_dev_major = -1;
66-
static struct class *kfd_class;
6766
struct device *kfd_device;
67+
static const struct class kfd_class = {
68+
.name = kfd_dev_name,
69+
};
6870

6971
static inline struct kfd_process_device *kfd_lock_pdd_by_id(struct kfd_process *p, __u32 gpu_id)
7072
{
@@ -94,22 +96,21 @@ int kfd_chardev_init(void)
9496
if (err < 0)
9597
goto err_register_chrdev;
9698

97-
kfd_class = class_create(kfd_dev_name);
98-
err = PTR_ERR(kfd_class);
99-
if (IS_ERR(kfd_class))
99+
err = class_register(&kfd_class);
100+
if (err)
100101
goto err_class_create;
101102

102-
kfd_device = device_create(kfd_class, NULL,
103-
MKDEV(kfd_char_dev_major, 0),
104-
NULL, kfd_dev_name);
103+
kfd_device = device_create(&kfd_class, NULL,
104+
MKDEV(kfd_char_dev_major, 0),
105+
NULL, kfd_dev_name);
105106
err = PTR_ERR(kfd_device);
106107
if (IS_ERR(kfd_device))
107108
goto err_device_create;
108109

109110
return 0;
110111

111112
err_device_create:
112-
class_destroy(kfd_class);
113+
class_unregister(&kfd_class);
113114
err_class_create:
114115
unregister_chrdev(kfd_char_dev_major, kfd_dev_name);
115116
err_register_chrdev:
@@ -118,8 +119,8 @@ int kfd_chardev_init(void)
118119

119120
void kfd_chardev_exit(void)
120121
{
121-
device_destroy(kfd_class, MKDEV(kfd_char_dev_major, 0));
122-
class_destroy(kfd_class);
122+
device_destroy(&kfd_class, MKDEV(kfd_char_dev_major, 0));
123+
class_unregister(&kfd_class);
123124
unregister_chrdev(kfd_char_dev_major, kfd_dev_name);
124125
kfd_device = NULL;
125126
}

0 commit comments

Comments
 (0)