Commit 99f2d956 authored by Ivan Orlov's avatar Ivan Orlov Committed by Greg Kroah-Hartman

USB: gadget: f_hid: make hidg_class a static const structure

Now that the driver core allows for struct class to be in read-only
memory, move the hidg_class structure to be declared at build time
placing it into read-only memory, instead of having to be dynamically
allocated at load time.
Suggested-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarIvan Orlov <ivan.orlov0322@gmail.com>
Link: https://lore.kernel.org/r/20230620094412.508580-11-gregkh@linuxfoundation.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2c10e7a0
...@@ -23,7 +23,11 @@ ...@@ -23,7 +23,11 @@
#define HIDG_MINORS 4 #define HIDG_MINORS 4
static int major, minors; static int major, minors;
static struct class *hidg_class;
static const struct class hidg_class = {
.name = "hidg",
};
static DEFINE_IDA(hidg_ida); static DEFINE_IDA(hidg_ida);
static DEFINE_MUTEX(hidg_ida_lock); /* protects access to hidg_ida */ static DEFINE_MUTEX(hidg_ida_lock); /* protects access to hidg_ida */
...@@ -1272,7 +1276,7 @@ static struct usb_function *hidg_alloc(struct usb_function_instance *fi) ...@@ -1272,7 +1276,7 @@ static struct usb_function *hidg_alloc(struct usb_function_instance *fi)
device_initialize(&hidg->dev); device_initialize(&hidg->dev);
hidg->dev.release = hidg_release; hidg->dev.release = hidg_release;
hidg->dev.class = hidg_class; hidg->dev.class = &hidg_class;
hidg->dev.devt = MKDEV(major, opts->minor); hidg->dev.devt = MKDEV(major, opts->minor);
ret = dev_set_name(&hidg->dev, "hidg%d", opts->minor); ret = dev_set_name(&hidg->dev, "hidg%d", opts->minor);
if (ret) if (ret)
...@@ -1325,17 +1329,13 @@ int ghid_setup(struct usb_gadget *g, int count) ...@@ -1325,17 +1329,13 @@ int ghid_setup(struct usb_gadget *g, int count)
int status; int status;
dev_t dev; dev_t dev;
hidg_class = class_create("hidg"); status = class_register(&hidg_class);
if (IS_ERR(hidg_class)) { if (status)
status = PTR_ERR(hidg_class);
hidg_class = NULL;
return status; return status;
}
status = alloc_chrdev_region(&dev, 0, count, "hidg"); status = alloc_chrdev_region(&dev, 0, count, "hidg");
if (status) { if (status) {
class_destroy(hidg_class); class_unregister(&hidg_class);
hidg_class = NULL;
return status; return status;
} }
...@@ -1352,6 +1352,5 @@ void ghid_cleanup(void) ...@@ -1352,6 +1352,5 @@ void ghid_cleanup(void)
major = minors = 0; major = minors = 0;
} }
class_destroy(hidg_class); class_unregister(&hidg_class);
hidg_class = NULL;
} }
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