Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Ivan Orlov and committed by
Greg Kroah-Hartman
e571e843 8e991436

+10 -9
+10 -9
drivers/usb/mon/mon_bin.c
··· 213 213 PIPE_CONTROL, PIPE_ISOCHRONOUS, PIPE_BULK, PIPE_INTERRUPT 214 214 }; 215 215 216 - static struct class *mon_bin_class; 216 + static const struct class mon_bin_class = { 217 + .name = "usbmon", 218 + }; 219 + 217 220 static dev_t mon_bin_dev0; 218 221 static struct cdev mon_bin_cdev; 219 222 ··· 1363 1360 if (minor >= MON_BIN_MAX_MINOR) 1364 1361 return 0; 1365 1362 1366 - dev = device_create(mon_bin_class, ubus ? ubus->controller : NULL, 1363 + dev = device_create(&mon_bin_class, ubus ? ubus->controller : NULL, 1367 1364 MKDEV(MAJOR(mon_bin_dev0), minor), NULL, 1368 1365 "usbmon%d", minor); 1369 1366 if (IS_ERR(dev)) ··· 1375 1372 1376 1373 void mon_bin_del(struct mon_bus *mbus) 1377 1374 { 1378 - device_destroy(mon_bin_class, mbus->classdev->devt); 1375 + device_destroy(&mon_bin_class, mbus->classdev->devt); 1379 1376 } 1380 1377 1381 1378 int __init mon_bin_init(void) 1382 1379 { 1383 1380 int rc; 1384 1381 1385 - mon_bin_class = class_create("usbmon"); 1386 - if (IS_ERR(mon_bin_class)) { 1387 - rc = PTR_ERR(mon_bin_class); 1382 + rc = class_register(&mon_bin_class); 1383 + if (rc) 1388 1384 goto err_class; 1389 - } 1390 1385 1391 1386 rc = alloc_chrdev_region(&mon_bin_dev0, 0, MON_BIN_MAX_MINOR, "usbmon"); 1392 1387 if (rc < 0) ··· 1402 1401 err_add: 1403 1402 unregister_chrdev_region(mon_bin_dev0, MON_BIN_MAX_MINOR); 1404 1403 err_dev: 1405 - class_destroy(mon_bin_class); 1404 + class_unregister(&mon_bin_class); 1406 1405 err_class: 1407 1406 return rc; 1408 1407 } ··· 1411 1410 { 1412 1411 cdev_del(&mon_bin_cdev); 1413 1412 unregister_chrdev_region(mon_bin_dev0, MON_BIN_MAX_MINOR); 1414 - class_destroy(mon_bin_class); 1413 + class_unregister(&mon_bin_class); 1415 1414 }