Skip to content

Commit df22568

Browse files
gregkhbroonie
authored andcommitted
spi: spidev: make spidev_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: Mark Brown <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Link: https://lore.kernel.org/r/2023100639-celtic-herbs-66be@gregkh Signed-off-by: Mark Brown <[email protected]>
1 parent 881fe6e commit df22568

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

drivers/spi/spidev.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,9 @@ static const struct file_operations spidev_fops = {
695695
* It also simplifies memory management.
696696
*/
697697

698-
static struct class *spidev_class;
698+
static const struct class spidev_class = {
699+
.name = "spidev",
700+
};
699701

700702
static const struct spi_device_id spidev_spi_ids[] = {
701703
{ .name = "dh2228fv" },
@@ -798,7 +800,7 @@ static int spidev_probe(struct spi_device *spi)
798800
struct device *dev;
799801

800802
spidev->devt = MKDEV(SPIDEV_MAJOR, minor);
801-
dev = device_create(spidev_class, &spi->dev, spidev->devt,
803+
dev = device_create(&spidev_class, &spi->dev, spidev->devt,
802804
spidev, "spidev%d.%d",
803805
spi->master->bus_num, spi_get_chipselect(spi, 0));
804806
status = PTR_ERR_OR_ZERO(dev);
@@ -834,7 +836,7 @@ static void spidev_remove(struct spi_device *spi)
834836
mutex_unlock(&spidev->spi_lock);
835837

836838
list_del(&spidev->device_entry);
837-
device_destroy(spidev_class, spidev->devt);
839+
device_destroy(&spidev_class, spidev->devt);
838840
clear_bit(MINOR(spidev->devt), minors);
839841
if (spidev->users == 0)
840842
kfree(spidev);
@@ -872,15 +874,15 @@ static int __init spidev_init(void)
872874
if (status < 0)
873875
return status;
874876

875-
spidev_class = class_create("spidev");
876-
if (IS_ERR(spidev_class)) {
877+
status = class_register(&spidev_class);
878+
if (status) {
877879
unregister_chrdev(SPIDEV_MAJOR, spidev_spi_driver.driver.name);
878-
return PTR_ERR(spidev_class);
880+
return status;
879881
}
880882

881883
status = spi_register_driver(&spidev_spi_driver);
882884
if (status < 0) {
883-
class_destroy(spidev_class);
885+
class_unregister(&spidev_class);
884886
unregister_chrdev(SPIDEV_MAJOR, spidev_spi_driver.driver.name);
885887
}
886888
return status;
@@ -890,7 +892,7 @@ module_init(spidev_init);
890892
static void __exit spidev_exit(void)
891893
{
892894
spi_unregister_driver(&spidev_spi_driver);
893-
class_destroy(spidev_class);
895+
class_unregister(&spidev_class);
894896
unregister_chrdev(SPIDEV_MAJOR, spidev_spi_driver.driver.name);
895897
}
896898
module_exit(spidev_exit);

0 commit comments

Comments
 (0)