Commit df22568a authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman Committed by Mark Brown

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 <broonie@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://lore.kernel.org/r/2023100639-celtic-herbs-66be@gregkhSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 881fe6ed
...@@ -695,7 +695,9 @@ static const struct file_operations spidev_fops = { ...@@ -695,7 +695,9 @@ static const struct file_operations spidev_fops = {
* It also simplifies memory management. * It also simplifies memory management.
*/ */
static struct class *spidev_class; static const struct class spidev_class = {
.name = "spidev",
};
static const struct spi_device_id spidev_spi_ids[] = { static const struct spi_device_id spidev_spi_ids[] = {
{ .name = "dh2228fv" }, { .name = "dh2228fv" },
...@@ -798,7 +800,7 @@ static int spidev_probe(struct spi_device *spi) ...@@ -798,7 +800,7 @@ static int spidev_probe(struct spi_device *spi)
struct device *dev; struct device *dev;
spidev->devt = MKDEV(SPIDEV_MAJOR, minor); spidev->devt = MKDEV(SPIDEV_MAJOR, minor);
dev = device_create(spidev_class, &spi->dev, spidev->devt, dev = device_create(&spidev_class, &spi->dev, spidev->devt,
spidev, "spidev%d.%d", spidev, "spidev%d.%d",
spi->master->bus_num, spi_get_chipselect(spi, 0)); spi->master->bus_num, spi_get_chipselect(spi, 0));
status = PTR_ERR_OR_ZERO(dev); status = PTR_ERR_OR_ZERO(dev);
...@@ -834,7 +836,7 @@ static void spidev_remove(struct spi_device *spi) ...@@ -834,7 +836,7 @@ static void spidev_remove(struct spi_device *spi)
mutex_unlock(&spidev->spi_lock); mutex_unlock(&spidev->spi_lock);
list_del(&spidev->device_entry); list_del(&spidev->device_entry);
device_destroy(spidev_class, spidev->devt); device_destroy(&spidev_class, spidev->devt);
clear_bit(MINOR(spidev->devt), minors); clear_bit(MINOR(spidev->devt), minors);
if (spidev->users == 0) if (spidev->users == 0)
kfree(spidev); kfree(spidev);
...@@ -872,15 +874,15 @@ static int __init spidev_init(void) ...@@ -872,15 +874,15 @@ static int __init spidev_init(void)
if (status < 0) if (status < 0)
return status; return status;
spidev_class = class_create("spidev"); status = class_register(&spidev_class);
if (IS_ERR(spidev_class)) { if (status) {
unregister_chrdev(SPIDEV_MAJOR, spidev_spi_driver.driver.name); unregister_chrdev(SPIDEV_MAJOR, spidev_spi_driver.driver.name);
return PTR_ERR(spidev_class); return status;
} }
status = spi_register_driver(&spidev_spi_driver); status = spi_register_driver(&spidev_spi_driver);
if (status < 0) { if (status < 0) {
class_destroy(spidev_class); class_unregister(&spidev_class);
unregister_chrdev(SPIDEV_MAJOR, spidev_spi_driver.driver.name); unregister_chrdev(SPIDEV_MAJOR, spidev_spi_driver.driver.name);
} }
return status; return status;
...@@ -890,7 +892,7 @@ module_init(spidev_init); ...@@ -890,7 +892,7 @@ module_init(spidev_init);
static void __exit spidev_exit(void) static void __exit spidev_exit(void)
{ {
spi_unregister_driver(&spidev_spi_driver); spi_unregister_driver(&spidev_spi_driver);
class_destroy(spidev_class); class_unregister(&spidev_class);
unregister_chrdev(SPIDEV_MAJOR, spidev_spi_driver.driver.name); unregister_chrdev(SPIDEV_MAJOR, spidev_spi_driver.driver.name);
} }
module_exit(spidev_exit); module_exit(spidev_exit);
......
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