Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
Acked-by: Jarkko Sakkinen <jarkko@kernel.org>
Link: https://lore.kernel.org/r/20230620144642.584926-2-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Ivan Orlov and committed by
Greg Kroah-Hartman
d2e8071b e2dfa1d5

+20 -18
+8 -3
drivers/char/tpm/tpm-chip.c
··· 28 28 DEFINE_IDR(dev_nums_idr); 29 29 static DEFINE_MUTEX(idr_lock); 30 30 31 - struct class *tpm_class; 32 - struct class *tpmrm_class; 31 + const struct class tpm_class = { 32 + .name = "tpm", 33 + .shutdown_pre = tpm_class_shutdown, 34 + }; 35 + const struct class tpmrm_class = { 36 + .name = "tmprm", 37 + }; 33 38 dev_t tpm_devt; 34 39 35 40 static int tpm_request_locality(struct tpm_chip *chip) ··· 341 336 342 337 device_initialize(&chip->dev); 343 338 344 - chip->dev.class = tpm_class; 339 + chip->dev.class = &tpm_class; 345 340 chip->dev.release = tpm_dev_release; 346 341 chip->dev.parent = pdev; 347 342 chip->dev.groups = chip->groups;
+9 -12
drivers/char/tpm/tpm-interface.c
··· 476 476 { 477 477 int rc; 478 478 479 - tpm_class = class_create("tpm"); 480 - if (IS_ERR(tpm_class)) { 479 + rc = class_register(&tpm_class); 480 + if (rc) { 481 481 pr_err("couldn't create tpm class\n"); 482 - return PTR_ERR(tpm_class); 482 + return rc; 483 483 } 484 484 485 - tpm_class->shutdown_pre = tpm_class_shutdown; 486 - 487 - tpmrm_class = class_create("tpmrm"); 488 - if (IS_ERR(tpmrm_class)) { 485 + rc = class_register(&tpmrm_class); 486 + if (rc) { 489 487 pr_err("couldn't create tpmrm class\n"); 490 - rc = PTR_ERR(tpmrm_class); 491 488 goto out_destroy_tpm_class; 492 489 } 493 490 ··· 505 508 out_unreg_chrdev: 506 509 unregister_chrdev_region(tpm_devt, 2 * TPM_NUM_DEVICES); 507 510 out_destroy_tpmrm_class: 508 - class_destroy(tpmrm_class); 511 + class_unregister(&tpmrm_class); 509 512 out_destroy_tpm_class: 510 - class_destroy(tpm_class); 513 + class_unregister(&tpm_class); 511 514 512 515 return rc; 513 516 } ··· 515 518 static void __exit tpm_exit(void) 516 519 { 517 520 idr_destroy(&dev_nums_idr); 518 - class_destroy(tpm_class); 519 - class_destroy(tpmrm_class); 521 + class_unregister(&tpm_class); 522 + class_unregister(&tpmrm_class); 520 523 unregister_chrdev_region(tpm_devt, 2*TPM_NUM_DEVICES); 521 524 tpm_dev_common_exit(); 522 525 }
+2 -2
drivers/char/tpm/tpm.h
··· 230 230 * compiler warnings about stack frame size. */ 231 231 #define TPM_MAX_RNG_DATA 128 232 232 233 - extern struct class *tpm_class; 234 - extern struct class *tpmrm_class; 233 + extern const struct class tpm_class; 234 + extern const struct class tpmrm_class; 235 235 extern dev_t tpm_devt; 236 236 extern const struct file_operations tpm_fops; 237 237 extern const struct file_operations tpmrm_fops;
+1 -1
drivers/char/tpm/tpm2-space.c
··· 606 606 607 607 device_initialize(&chip->devs); 608 608 chip->devs.parent = chip->dev.parent; 609 - chip->devs.class = tpmrm_class; 609 + chip->devs.class = &tpmrm_class; 610 610 611 611 /* 612 612 * Get extra reference on main device to hold on behalf of devs.