Skip to content

Commit d223192

Browse files
committed
cxl: make cxl_class constant
Now that the driver core allows for struct class to be in read-only memory, we should make all 'class' structures declared at build time placing them into read-only memory, instead of having to be dynamically allocated at runtime. Cc: Andrew Donnellan <ajd@linux.ibm.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: linuxppc-dev@lists.ozlabs.org Acked-by: Frederic Barrat <fbarrat@linux.ibm.com> Link: https://lore.kernel.org/r/2023102434-haiku-uphill-0c11@gregkh Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f6c086e commit d223192

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

drivers/misc/cxl/file.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838

3939
static dev_t cxl_dev;
4040

41-
static struct class *cxl_class;
42-
4341
static int __afu_open(struct inode *inode, struct file *file, bool master)
4442
{
4543
struct cxl *adapter;
@@ -559,7 +557,10 @@ static char *cxl_devnode(const struct device *dev, umode_t *mode)
559557
return kasprintf(GFP_KERNEL, "cxl/%s", dev_name(dev));
560558
}
561559

562-
extern struct class *cxl_class;
560+
static const struct class cxl_class = {
561+
.name = "cxl",
562+
.devnode = cxl_devnode,
563+
};
563564

564565
static int cxl_add_chardev(struct cxl_afu *afu, dev_t devt, struct cdev *cdev,
565566
struct device **chardev, char *postfix, char *desc,
@@ -575,7 +576,7 @@ static int cxl_add_chardev(struct cxl_afu *afu, dev_t devt, struct cdev *cdev,
575576
return rc;
576577
}
577578

578-
dev = device_create(cxl_class, &afu->dev, devt, afu,
579+
dev = device_create(&cxl_class, &afu->dev, devt, afu,
579580
"afu%i.%i%s", afu->adapter->adapter_num, afu->slice, postfix);
580581
if (IS_ERR(dev)) {
581582
rc = PTR_ERR(dev);
@@ -633,14 +634,14 @@ void cxl_chardev_afu_remove(struct cxl_afu *afu)
633634

634635
int cxl_register_afu(struct cxl_afu *afu)
635636
{
636-
afu->dev.class = cxl_class;
637+
afu->dev.class = &cxl_class;
637638

638639
return device_register(&afu->dev);
639640
}
640641

641642
int cxl_register_adapter(struct cxl *adapter)
642643
{
643-
adapter->dev.class = cxl_class;
644+
adapter->dev.class = &cxl_class;
644645

645646
/*
646647
* Future: When we support dynamically reprogramming the PSL & AFU we
@@ -678,13 +679,11 @@ int __init cxl_file_init(void)
678679

679680
pr_devel("CXL device allocated, MAJOR %i\n", MAJOR(cxl_dev));
680681

681-
cxl_class = class_create("cxl");
682-
if (IS_ERR(cxl_class)) {
682+
rc = class_register(&cxl_class);
683+
if (rc) {
683684
pr_err("Unable to create CXL class\n");
684-
rc = PTR_ERR(cxl_class);
685685
goto err;
686686
}
687-
cxl_class->devnode = cxl_devnode;
688687

689688
return 0;
690689

@@ -696,5 +695,5 @@ int __init cxl_file_init(void)
696695
void cxl_file_exit(void)
697696
{
698697
unregister_chrdev_region(cxl_dev, CXL_NUM_MINORS);
699-
class_destroy(cxl_class);
698+
class_unregister(&cxl_class);
700699
}

0 commit comments

Comments
 (0)