Commit d2e8071b authored by Ivan Orlov's avatar Ivan Orlov Committed by Greg Kroah-Hartman

tpm: make all 'class' structures const

Now that the driver core allows for struct class to be in read-only
memory, making all 'class' structures to be declared at build time
placing them into read-only memory, instead of having to be dynamically
allocated at load time.

Cc: Peter Huewe <peterhuewe@gmx.de>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: linux-integrity@vger.kernel.org
Suggested-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarIvan Orlov <ivan.orlov0322@gmail.com>
Acked-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
Link: https://lore.kernel.org/r/20230620144642.584926-2-gregkh@linuxfoundation.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent e2dfa1d5
...@@ -28,8 +28,13 @@ ...@@ -28,8 +28,13 @@
DEFINE_IDR(dev_nums_idr); DEFINE_IDR(dev_nums_idr);
static DEFINE_MUTEX(idr_lock); static DEFINE_MUTEX(idr_lock);
struct class *tpm_class; const struct class tpm_class = {
struct class *tpmrm_class; .name = "tpm",
.shutdown_pre = tpm_class_shutdown,
};
const struct class tpmrm_class = {
.name = "tmprm",
};
dev_t tpm_devt; dev_t tpm_devt;
static int tpm_request_locality(struct tpm_chip *chip) static int tpm_request_locality(struct tpm_chip *chip)
...@@ -336,7 +341,7 @@ struct tpm_chip *tpm_chip_alloc(struct device *pdev, ...@@ -336,7 +341,7 @@ struct tpm_chip *tpm_chip_alloc(struct device *pdev,
device_initialize(&chip->dev); device_initialize(&chip->dev);
chip->dev.class = tpm_class; chip->dev.class = &tpm_class;
chip->dev.release = tpm_dev_release; chip->dev.release = tpm_dev_release;
chip->dev.parent = pdev; chip->dev.parent = pdev;
chip->dev.groups = chip->groups; chip->dev.groups = chip->groups;
......
...@@ -476,18 +476,15 @@ static int __init tpm_init(void) ...@@ -476,18 +476,15 @@ static int __init tpm_init(void)
{ {
int rc; int rc;
tpm_class = class_create("tpm"); rc = class_register(&tpm_class);
if (IS_ERR(tpm_class)) { if (rc) {
pr_err("couldn't create tpm class\n"); pr_err("couldn't create tpm class\n");
return PTR_ERR(tpm_class); return rc;
} }
tpm_class->shutdown_pre = tpm_class_shutdown; rc = class_register(&tpmrm_class);
if (rc) {
tpmrm_class = class_create("tpmrm");
if (IS_ERR(tpmrm_class)) {
pr_err("couldn't create tpmrm class\n"); pr_err("couldn't create tpmrm class\n");
rc = PTR_ERR(tpmrm_class);
goto out_destroy_tpm_class; goto out_destroy_tpm_class;
} }
...@@ -508,9 +505,9 @@ static int __init tpm_init(void) ...@@ -508,9 +505,9 @@ static int __init tpm_init(void)
out_unreg_chrdev: out_unreg_chrdev:
unregister_chrdev_region(tpm_devt, 2 * TPM_NUM_DEVICES); unregister_chrdev_region(tpm_devt, 2 * TPM_NUM_DEVICES);
out_destroy_tpmrm_class: out_destroy_tpmrm_class:
class_destroy(tpmrm_class); class_unregister(&tpmrm_class);
out_destroy_tpm_class: out_destroy_tpm_class:
class_destroy(tpm_class); class_unregister(&tpm_class);
return rc; return rc;
} }
...@@ -518,8 +515,8 @@ static int __init tpm_init(void) ...@@ -518,8 +515,8 @@ static int __init tpm_init(void)
static void __exit tpm_exit(void) static void __exit tpm_exit(void)
{ {
idr_destroy(&dev_nums_idr); idr_destroy(&dev_nums_idr);
class_destroy(tpm_class); class_unregister(&tpm_class);
class_destroy(tpmrm_class); class_unregister(&tpmrm_class);
unregister_chrdev_region(tpm_devt, 2*TPM_NUM_DEVICES); unregister_chrdev_region(tpm_devt, 2*TPM_NUM_DEVICES);
tpm_dev_common_exit(); tpm_dev_common_exit();
} }
......
...@@ -230,8 +230,8 @@ enum tpm2_pt_props { ...@@ -230,8 +230,8 @@ enum tpm2_pt_props {
* compiler warnings about stack frame size. */ * compiler warnings about stack frame size. */
#define TPM_MAX_RNG_DATA 128 #define TPM_MAX_RNG_DATA 128
extern struct class *tpm_class; extern const struct class tpm_class;
extern struct class *tpmrm_class; extern const struct class tpmrm_class;
extern dev_t tpm_devt; extern dev_t tpm_devt;
extern const struct file_operations tpm_fops; extern const struct file_operations tpm_fops;
extern const struct file_operations tpmrm_fops; extern const struct file_operations tpmrm_fops;
......
...@@ -606,7 +606,7 @@ int tpm_devs_add(struct tpm_chip *chip) ...@@ -606,7 +606,7 @@ int tpm_devs_add(struct tpm_chip *chip)
device_initialize(&chip->devs); device_initialize(&chip->devs);
chip->devs.parent = chip->dev.parent; chip->devs.parent = chip->dev.parent;
chip->devs.class = tpmrm_class; chip->devs.class = &tpmrm_class;
/* /*
* Get extra reference on main device to hold on behalf of devs. * Get extra reference on main device to hold on behalf of devs.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment