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

misc: phantom: make phantom_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: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Jiri Slaby <jirislaby@kernel.org>
Link: https://lore.kernel.org/r/2023102434-font-feast-98e3@gregkh
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

+13 -11
+13 -11
drivers/misc/phantom.c
··· 35 35 #define PHB_NOT_OH 2 36 36 37 37 static DEFINE_MUTEX(phantom_mutex); 38 - static struct class *phantom_class; 39 38 static int phantom_major; 39 + 40 + static const struct class phantom_class = { 41 + .name = "phantom", 42 + }; 40 43 41 44 struct phantom_device { 42 45 unsigned int opened; ··· 406 403 goto err_irq; 407 404 } 408 405 409 - if (IS_ERR(device_create(phantom_class, &pdev->dev, 406 + if (IS_ERR(device_create(&phantom_class, &pdev->dev, 410 407 MKDEV(phantom_major, minor), NULL, 411 408 "phantom%u", minor))) 412 409 dev_err(&pdev->dev, "can't create device\n"); ··· 439 436 struct phantom_device *pht = pci_get_drvdata(pdev); 440 437 unsigned int minor = MINOR(pht->cdev.dev); 441 438 442 - device_destroy(phantom_class, MKDEV(phantom_major, minor)); 439 + device_destroy(&phantom_class, MKDEV(phantom_major, minor)); 443 440 444 441 cdev_del(&pht->cdev); 445 442 ··· 506 503 int retval; 507 504 dev_t dev; 508 505 509 - phantom_class = class_create("phantom"); 510 - if (IS_ERR(phantom_class)) { 511 - retval = PTR_ERR(phantom_class); 506 + retval = class_register(&phantom_class); 507 + if (retval) { 512 508 printk(KERN_ERR "phantom: can't register phantom class\n"); 513 509 goto err; 514 510 } 515 - retval = class_create_file(phantom_class, &class_attr_version.attr); 511 + retval = class_create_file(&phantom_class, &class_attr_version.attr); 516 512 if (retval) { 517 513 printk(KERN_ERR "phantom: can't create sysfs version file\n"); 518 514 goto err_class; ··· 537 535 err_unchr: 538 536 unregister_chrdev_region(dev, PHANTOM_MAX_MINORS); 539 537 err_attr: 540 - class_remove_file(phantom_class, &class_attr_version.attr); 538 + class_remove_file(&phantom_class, &class_attr_version.attr); 541 539 err_class: 542 - class_destroy(phantom_class); 540 + class_unregister(&phantom_class); 543 541 err: 544 542 return retval; 545 543 } ··· 550 548 551 549 unregister_chrdev_region(MKDEV(phantom_major, 0), PHANTOM_MAX_MINORS); 552 550 553 - class_remove_file(phantom_class, &class_attr_version.attr); 554 - class_destroy(phantom_class); 551 + class_remove_file(&phantom_class, &class_attr_version.attr); 552 + class_unregister(&phantom_class); 555 553 556 554 pr_debug("phantom: module successfully removed\n"); 557 555 }