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

tee: make tee_class constant

Now that the driver core allows for struct class to be in read-only
memory, we should make all 'class' structures declared at build time
placing them into read-only memory, instead of having to be dynamically
allocated at runtime.

Cc: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Sumit Garg <sumit.garg@linaro.org>
Link: https://lore.kernel.org/r/2023100613-lustiness-affiliate-7dcb@gregkh
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

+11 -10
+11 -10
drivers/tee/tee_core.c
··· 40 40 static DECLARE_BITMAP(dev_mask, TEE_NUM_DEVICES); 41 41 static DEFINE_SPINLOCK(driver_lock); 42 42 43 - static struct class *tee_class; 43 + static const struct class tee_class = { 44 + .name = "tee", 45 + }; 46 + 44 47 static dev_t tee_devt; 45 48 46 49 struct tee_context *teedev_open(struct tee_device *teedev) ··· 922 919 teedesc->flags & TEE_DESC_PRIVILEGED ? "priv" : "", 923 920 teedev->id - offs); 924 921 925 - teedev->dev.class = tee_class; 922 + teedev->dev.class = &tee_class; 926 923 teedev->dev.release = tee_release_device; 927 924 teedev->dev.parent = dev; 928 925 ··· 1115 1112 dev = &start->teedev->dev; 1116 1113 1117 1114 do { 1118 - dev = class_find_device(tee_class, dev, &match_data, match_dev); 1115 + dev = class_find_device(&tee_class, dev, &match_data, match_dev); 1119 1116 if (!dev) { 1120 1117 ctx = ERR_PTR(-ENOENT); 1121 1118 break; ··· 1229 1226 { 1230 1227 int rc; 1231 1228 1232 - tee_class = class_create("tee"); 1233 - if (IS_ERR(tee_class)) { 1229 + rc = class_register(&tee_class); 1230 + if (rc) { 1234 1231 pr_err("couldn't create class\n"); 1235 - return PTR_ERR(tee_class); 1232 + return rc; 1236 1233 } 1237 1234 1238 1235 rc = alloc_chrdev_region(&tee_devt, 0, TEE_NUM_DEVICES, "tee"); ··· 1252 1249 out_unreg_chrdev: 1253 1250 unregister_chrdev_region(tee_devt, TEE_NUM_DEVICES); 1254 1251 out_unreg_class: 1255 - class_destroy(tee_class); 1256 - tee_class = NULL; 1252 + class_unregister(&tee_class); 1257 1253 1258 1254 return rc; 1259 1255 } ··· 1261 1259 { 1262 1260 bus_unregister(&tee_bus_type); 1263 1261 unregister_chrdev_region(tee_devt, TEE_NUM_DEVICES); 1264 - class_destroy(tee_class); 1265 - tee_class = NULL; 1262 + class_unregister(&tee_class); 1266 1263 } 1267 1264 1268 1265 subsys_initcall(tee_init);