Skip to content

Commit 99f2d95

Browse files
ivanorlov2206gregkh
authored andcommitted
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: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com> Link: https://lore.kernel.org/r/20230620094412.508580-11-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2c10e7a commit 99f2d95

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

drivers/usb/gadget/function/f_hid.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323
#define HIDG_MINORS 4
2424

2525
static int major, minors;
26-
static struct class *hidg_class;
26+
27+
static const struct class hidg_class = {
28+
.name = "hidg",
29+
};
30+
2731
static DEFINE_IDA(hidg_ida);
2832
static DEFINE_MUTEX(hidg_ida_lock); /* protects access to hidg_ida */
2933

@@ -1272,7 +1276,7 @@ static struct usb_function *hidg_alloc(struct usb_function_instance *fi)
12721276

12731277
device_initialize(&hidg->dev);
12741278
hidg->dev.release = hidg_release;
1275-
hidg->dev.class = hidg_class;
1279+
hidg->dev.class = &hidg_class;
12761280
hidg->dev.devt = MKDEV(major, opts->minor);
12771281
ret = dev_set_name(&hidg->dev, "hidg%d", opts->minor);
12781282
if (ret)
@@ -1325,17 +1329,13 @@ int ghid_setup(struct usb_gadget *g, int count)
13251329
int status;
13261330
dev_t dev;
13271331

1328-
hidg_class = class_create("hidg");
1329-
if (IS_ERR(hidg_class)) {
1330-
status = PTR_ERR(hidg_class);
1331-
hidg_class = NULL;
1332+
status = class_register(&hidg_class);
1333+
if (status)
13321334
return status;
1333-
}
13341335

13351336
status = alloc_chrdev_region(&dev, 0, count, "hidg");
13361337
if (status) {
1337-
class_destroy(hidg_class);
1338-
hidg_class = NULL;
1338+
class_unregister(&hidg_class);
13391339
return status;
13401340
}
13411341

@@ -1352,6 +1352,5 @@ void ghid_cleanup(void)
13521352
major = minors = 0;
13531353
}
13541354

1355-
class_destroy(hidg_class);
1356-
hidg_class = NULL;
1355+
class_unregister(&hidg_class);
13571356
}

0 commit comments

Comments
 (0)