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: 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>

authored by

Ivan Orlov and committed by
Greg Kroah-Hartman
99f2d956 2c10e7a0

+10 -11
+10 -11
drivers/usb/gadget/function/f_hid.c
··· 23 23 #define HIDG_MINORS 4 24 24 25 25 static int major, minors; 26 - static struct class *hidg_class; 26 + 27 + static const struct class hidg_class = { 28 + .name = "hidg", 29 + }; 30 + 27 31 static DEFINE_IDA(hidg_ida); 28 32 static DEFINE_MUTEX(hidg_ida_lock); /* protects access to hidg_ida */ 29 33 ··· 1276 1272 1277 1273 device_initialize(&hidg->dev); 1278 1274 hidg->dev.release = hidg_release; 1279 - hidg->dev.class = hidg_class; 1275 + hidg->dev.class = &hidg_class; 1280 1276 hidg->dev.devt = MKDEV(major, opts->minor); 1281 1277 ret = dev_set_name(&hidg->dev, "hidg%d", opts->minor); 1282 1278 if (ret) ··· 1329 1325 int status; 1330 1326 dev_t dev; 1331 1327 1332 - hidg_class = class_create("hidg"); 1333 - if (IS_ERR(hidg_class)) { 1334 - status = PTR_ERR(hidg_class); 1335 - hidg_class = NULL; 1328 + status = class_register(&hidg_class); 1329 + if (status) 1336 1330 return status; 1337 - } 1338 1331 1339 1332 status = alloc_chrdev_region(&dev, 0, count, "hidg"); 1340 1333 if (status) { 1341 - class_destroy(hidg_class); 1342 - hidg_class = NULL; 1334 + class_unregister(&hidg_class); 1343 1335 return status; 1344 1336 } 1345 1337 ··· 1352 1352 major = minors = 0; 1353 1353 } 1354 1354 1355 - class_destroy(hidg_class); 1356 - hidg_class = NULL; 1355 + class_unregister(&hidg_class); 1357 1356 }