Skip to content

Commit e571e84

Browse files
ivanorlov2206gregkh
authored andcommitted
USB: mon: make mon_bin_class a static const structure
Now that the driver core allows for struct class to be in read-only memory, move the mon_bin_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-9-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 8e99143 commit e571e84

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

drivers/usb/mon/mon_bin.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,10 @@ static unsigned char xfer_to_pipe[4] = {
213213
PIPE_CONTROL, PIPE_ISOCHRONOUS, PIPE_BULK, PIPE_INTERRUPT
214214
};
215215

216-
static struct class *mon_bin_class;
216+
static const struct class mon_bin_class = {
217+
.name = "usbmon",
218+
};
219+
217220
static dev_t mon_bin_dev0;
218221
static struct cdev mon_bin_cdev;
219222

@@ -1360,7 +1363,7 @@ int mon_bin_add(struct mon_bus *mbus, const struct usb_bus *ubus)
13601363
if (minor >= MON_BIN_MAX_MINOR)
13611364
return 0;
13621365

1363-
dev = device_create(mon_bin_class, ubus ? ubus->controller : NULL,
1366+
dev = device_create(&mon_bin_class, ubus ? ubus->controller : NULL,
13641367
MKDEV(MAJOR(mon_bin_dev0), minor), NULL,
13651368
"usbmon%d", minor);
13661369
if (IS_ERR(dev))
@@ -1372,18 +1375,16 @@ int mon_bin_add(struct mon_bus *mbus, const struct usb_bus *ubus)
13721375

13731376
void mon_bin_del(struct mon_bus *mbus)
13741377
{
1375-
device_destroy(mon_bin_class, mbus->classdev->devt);
1378+
device_destroy(&mon_bin_class, mbus->classdev->devt);
13761379
}
13771380

13781381
int __init mon_bin_init(void)
13791382
{
13801383
int rc;
13811384

1382-
mon_bin_class = class_create("usbmon");
1383-
if (IS_ERR(mon_bin_class)) {
1384-
rc = PTR_ERR(mon_bin_class);
1385+
rc = class_register(&mon_bin_class);
1386+
if (rc)
13851387
goto err_class;
1386-
}
13871388

13881389
rc = alloc_chrdev_region(&mon_bin_dev0, 0, MON_BIN_MAX_MINOR, "usbmon");
13891390
if (rc < 0)
@@ -1401,7 +1402,7 @@ int __init mon_bin_init(void)
14011402
err_add:
14021403
unregister_chrdev_region(mon_bin_dev0, MON_BIN_MAX_MINOR);
14031404
err_dev:
1404-
class_destroy(mon_bin_class);
1405+
class_unregister(&mon_bin_class);
14051406
err_class:
14061407
return rc;
14071408
}
@@ -1410,5 +1411,5 @@ void mon_bin_exit(void)
14101411
{
14111412
cdev_del(&mon_bin_cdev);
14121413
unregister_chrdev_region(mon_bin_dev0, MON_BIN_MAX_MINOR);
1413-
class_destroy(mon_bin_class);
1414+
class_unregister(&mon_bin_class);
14141415
}

0 commit comments

Comments
 (0)