most: replace cdev_component->class with a const struct class

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@linuxfoundation.org>
Signed-off-by: Jori Koolstra <jkoolstra@xs4all.nl>
Link: https://patch.msgid.link/20260401170043.3844117-1-jkoolstra@xs4all.nl
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
master
Jori Koolstra 2026-04-01 19:00:43 +02:00 committed by Greg Kroah-Hartman
parent 4dc0c899b1
commit f7a1fec4de
1 changed files with 12 additions and 8 deletions

View File

@ -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 @@ free_cdev:
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);