misc: genwqe: make class_genwqe a static const structure

Now that the driver core allows for struct class to be in read-only
memory, move the class_genwqe structure to be declared at build time
placing it into read-only memory, instead of having to be dynamically
allocated at boot time. Update the 'class_genwqe' field of the
'genwqe_dev' struct correspondingly.

Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
Link: https://lore.kernel.org/r/20230810182711.22664-1-ivan.orlov0322@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Ivan Orlov 2023-08-10 22:27:11 +04:00 committed by Greg Kroah-Hartman
parent 60df28ac09
commit b5fa337955
2 changed files with 27 additions and 24 deletions

View File

@ -42,7 +42,7 @@ MODULE_VERSION(DRV_VERSION);
MODULE_LICENSE("GPL");
static char genwqe_driver_name[] = GENWQE_DEVNAME;
static struct class *class_genwqe;
static struct dentry *debugfs_genwqe;
static struct genwqe_dev *genwqe_devices[GENWQE_CARD_NO_MAX];
@ -104,6 +104,26 @@ static const struct pci_device_id genwqe_device_table[] = {
MODULE_DEVICE_TABLE(pci, genwqe_device_table);
/**
* genwqe_devnode() - Set default access mode for genwqe devices.
* @dev: Pointer to device (unused)
* @mode: Carrier to pass-back given mode (permissions)
*
* Default mode should be rw for everybody. Do not change default
* device name.
*/
static char *genwqe_devnode(const struct device *dev, umode_t *mode)
{
if (mode)
*mode = 0666;
return NULL;
}
static const struct class class_genwqe = {
.name = GENWQE_DEVNAME,
.devnode = genwqe_devnode,
};
/**
* genwqe_dev_alloc() - Create and prepare a new card descriptor
*
@ -126,7 +146,7 @@ static struct genwqe_dev *genwqe_dev_alloc(void)
return ERR_PTR(-ENOMEM);
cd->card_idx = i;
cd->class_genwqe = class_genwqe;
cd->class_genwqe = &class_genwqe;
cd->debugfs_genwqe = debugfs_genwqe;
/*
@ -1339,21 +1359,6 @@ static struct pci_driver genwqe_driver = {
.err_handler = &genwqe_err_handler,
};
/**
* genwqe_devnode() - Set default access mode for genwqe devices.
* @dev: Pointer to device (unused)
* @mode: Carrier to pass-back given mode (permissions)
*
* Default mode should be rw for everybody. Do not change default
* device name.
*/
static char *genwqe_devnode(const struct device *dev, umode_t *mode)
{
if (mode)
*mode = 0666;
return NULL;
}
/**
* genwqe_init_module() - Driver registration and initialization
*/
@ -1361,14 +1366,12 @@ static int __init genwqe_init_module(void)
{
int rc;
class_genwqe = class_create(GENWQE_DEVNAME);
if (IS_ERR(class_genwqe)) {
rc = class_register(&class_genwqe);
if (rc) {
pr_err("[%s] create class failed\n", __func__);
return -ENOMEM;
}
class_genwqe->devnode = genwqe_devnode;
debugfs_genwqe = debugfs_create_dir(GENWQE_DEVNAME, NULL);
rc = pci_register_driver(&genwqe_driver);
@ -1381,7 +1384,7 @@ static int __init genwqe_init_module(void)
err_out0:
debugfs_remove(debugfs_genwqe);
class_destroy(class_genwqe);
class_unregister(&class_genwqe);
return rc;
}
@ -1392,7 +1395,7 @@ static void __exit genwqe_exit_module(void)
{
pci_unregister_driver(&genwqe_driver);
debugfs_remove(debugfs_genwqe);
class_destroy(class_genwqe);
class_unregister(&class_genwqe);
}
module_init(genwqe_init_module);

View File

@ -289,7 +289,7 @@ struct genwqe_dev {
/* char device */
dev_t devnum_genwqe; /* major/minor num card */
struct class *class_genwqe; /* reference to class object */
const struct class *class_genwqe; /* reference to class object */
struct device *dev; /* for device creation */
struct cdev cdev_genwqe; /* char device for card */