[PATCH] most: replace cdev_component->class with a const struct class

From: Jori Koolstra

Date: Tue Mar 03 2026 - 13:23:02 EST


The class_create() call has been deprecated in favor of class_register()
as the driver core now allows for a struct class to be in read-only
memory. Replace cdev_component->class with a const struct class and drop
the class_create() call. Compile tested only.

Link: https://lore.kernel.org/all/2023040244-duffel-pushpin-f738@gregkh/

Suggested-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
Signed-off-by: Jori Koolstra <jkoolstra@xxxxxxxxx>
---
drivers/most/most_cdev.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/most/most_cdev.c b/drivers/most/most_cdev.c
index b31dc824466f..5df508d8d60a 100644
--- a/drivers/most/most_cdev.c
+++ b/drivers/most/most_cdev.c
@@ -19,11 +19,14 @@

#define CHRDEV_REGION_SIZE 50

+static const struct class most_cdev_class = {
+ .name = "most_cdev"
+};
+
static struct cdev_component {
dev_t devno;
struct ida minor_id;
unsigned int major;
- struct class *class;
struct most_component cc;
} comp;

@@ -91,7 +94,7 @@ static void destroy_cdev(struct comp_channel *c)
{
unsigned long flags;

- device_destroy(comp.class, c->devno);
+ device_destroy(&most_cdev_class, c->devno);
cdev_del(&c->cdev);
spin_lock_irqsave(&ch_list_lock, flags);
list_del(&c->list);
@@ -455,7 +458,7 @@ static int comp_probe(struct most_interface *iface, int channel_id,
spin_lock_irqsave(&ch_list_lock, cl_flags);
list_add_tail(&c->list, &channel_list);
spin_unlock_irqrestore(&ch_list_lock, cl_flags);
- c->dev = device_create(comp.class, NULL, c->devno, NULL, "%s", name);
+ c->dev = device_create(&most_cdev_class, NULL, c->devno, NULL, "%s", name);

if (IS_ERR(c->dev)) {
retval = PTR_ERR(c->dev);
@@ -487,13 +490,14 @@ static struct cdev_component comp = {
},
};

+
static int __init most_cdev_init(void)
{
int err;

- comp.class = class_create("most_cdev");
- if (IS_ERR(comp.class))
- return PTR_ERR(comp.class);
+ err = class_register(&most_cdev_class);
+ if (err)
+ return err;

ida_init(&comp.minor_id);

@@ -515,7 +519,7 @@ static int __init most_cdev_init(void)
unregister_chrdev_region(comp.devno, CHRDEV_REGION_SIZE);
dest_ida:
ida_destroy(&comp.minor_id);
- class_destroy(comp.class);
+ class_unregister(&most_cdev_class);
return err;
}

@@ -532,7 +536,7 @@ static void __exit most_cdev_exit(void)
}
unregister_chrdev_region(comp.devno, CHRDEV_REGION_SIZE);
ida_destroy(&comp.minor_id);
- class_destroy(comp.class);
+ class_unregister(&most_cdev_class);
}

module_init(most_cdev_init);

base-commit: d466c332e106fe666d1e2f5a24d08e308bebbfa1
--
2.53.0