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

dca: make dca_class a static const structure

The driver core allows for struct class to be in read-only memory. Move
the dca_class structure to be declared at build time placing it into
read-only memory, instead of having to be dynamically allocated at boot
time.

Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
Link: https://lore.kernel.org/r/20240412151726.189030-1-ivan.orlov0322@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Ivan Orlov and committed by
Greg Kroah-Hartman
d7d3ae44 bd7246a1

+12 -8
+12 -8
drivers/dca/dca-sysfs.c
··· 13 13 #include <linux/gfp.h> 14 14 #include <linux/export.h> 15 15 16 - static struct class *dca_class; 16 + static const struct class dca_class = { 17 + .name = "dca", 18 + }; 17 19 static struct idr dca_idr; 18 20 static spinlock_t dca_idr_lock; 19 21 ··· 24 22 struct device *cd; 25 23 static int req_count; 26 24 27 - cd = device_create(dca_class, dca->cd, MKDEV(0, slot + 1), NULL, 25 + cd = device_create(&dca_class, dca->cd, MKDEV(0, slot + 1), NULL, 28 26 "requester%d", req_count++); 29 27 return PTR_ERR_OR_ZERO(cd); 30 28 } 31 29 32 30 void dca_sysfs_remove_req(struct dca_provider *dca, int slot) 33 31 { 34 - device_destroy(dca_class, MKDEV(0, slot + 1)); 32 + device_destroy(&dca_class, MKDEV(0, slot + 1)); 35 33 } 36 34 37 35 int dca_sysfs_add_provider(struct dca_provider *dca, struct device *dev) ··· 51 49 if (ret < 0) 52 50 return ret; 53 51 54 - cd = device_create(dca_class, dev, MKDEV(0, 0), NULL, "dca%d", dca->id); 52 + cd = device_create(&dca_class, dev, MKDEV(0, 0), NULL, "dca%d", dca->id); 55 53 if (IS_ERR(cd)) { 56 54 spin_lock(&dca_idr_lock); 57 55 idr_remove(&dca_idr, dca->id); ··· 73 71 74 72 int __init dca_sysfs_init(void) 75 73 { 74 + int err; 75 + 76 76 idr_init(&dca_idr); 77 77 spin_lock_init(&dca_idr_lock); 78 78 79 - dca_class = class_create("dca"); 80 - if (IS_ERR(dca_class)) { 79 + err = class_register(&dca_class); 80 + if (err) { 81 81 idr_destroy(&dca_idr); 82 - return PTR_ERR(dca_class); 82 + return err; 83 83 } 84 84 return 0; 85 85 } 86 86 87 87 void __exit dca_sysfs_exit(void) 88 88 { 89 - class_destroy(dca_class); 89 + class_unregister(&dca_class); 90 90 idr_destroy(&dca_idr); 91 91 } 92 92