Skip to content

Commit cf3c415

Browse files
committed
ocxl: make ocxl_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/2023102403-squirt-defraud-6c0c@gregkh Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d223192 commit cf3c415

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

drivers/misc/ocxl/file.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#define OCXL_NUM_MINORS 256 /* Total to reserve */
1515

1616
static dev_t ocxl_dev;
17-
static struct class *ocxl_class;
1817
static DEFINE_MUTEX(minors_idr_lock);
1918
static struct idr minors_idr;
2019

@@ -509,6 +508,16 @@ static void ocxl_file_make_invisible(struct ocxl_file_info *info)
509508
cdev_del(&info->cdev);
510509
}
511510

511+
static char *ocxl_devnode(const struct device *dev, umode_t *mode)
512+
{
513+
return kasprintf(GFP_KERNEL, "ocxl/%s", dev_name(dev));
514+
}
515+
516+
static const struct class ocxl_class = {
517+
.name = "ocxl",
518+
.devnode = ocxl_devnode,
519+
};
520+
512521
int ocxl_file_register_afu(struct ocxl_afu *afu)
513522
{
514523
int minor;
@@ -529,7 +538,7 @@ int ocxl_file_register_afu(struct ocxl_afu *afu)
529538

530539
info->dev.parent = &fn->dev;
531540
info->dev.devt = MKDEV(MAJOR(ocxl_dev), minor);
532-
info->dev.class = ocxl_class;
541+
info->dev.class = &ocxl_class;
533542
info->dev.release = info_release;
534543

535544
info->afu = afu;
@@ -584,11 +593,6 @@ void ocxl_file_unregister_afu(struct ocxl_afu *afu)
584593
device_unregister(&info->dev);
585594
}
586595

587-
static char *ocxl_devnode(const struct device *dev, umode_t *mode)
588-
{
589-
return kasprintf(GFP_KERNEL, "ocxl/%s", dev_name(dev));
590-
}
591-
592596
int ocxl_file_init(void)
593597
{
594598
int rc;
@@ -601,20 +605,19 @@ int ocxl_file_init(void)
601605
return rc;
602606
}
603607

604-
ocxl_class = class_create("ocxl");
605-
if (IS_ERR(ocxl_class)) {
608+
rc = class_register(&ocxl_class);
609+
if (rc) {
606610
pr_err("Unable to create ocxl class\n");
607611
unregister_chrdev_region(ocxl_dev, OCXL_NUM_MINORS);
608-
return PTR_ERR(ocxl_class);
612+
return rc;
609613
}
610614

611-
ocxl_class->devnode = ocxl_devnode;
612615
return 0;
613616
}
614617

615618
void ocxl_file_exit(void)
616619
{
617-
class_destroy(ocxl_class);
620+
class_unregister(&ocxl_class);
618621
unregister_chrdev_region(ocxl_dev, OCXL_NUM_MINORS);
619622
idr_destroy(&minors_idr);
620623
}

0 commit comments

Comments
 (0)