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

net: wwan: core: make wwan_class constant

Since commit 43a7206b0963 ("driver core: class: make class_register() take
a const *"), the driver core allows for struct class to be in read-only
memory, so move the wwan_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: Ricardo B. Marliere <ricardo@marliere.net>
Acked-by: Sergey Ryazanov <ryazanov.s.a@gmail.com>
Link: https://lore.kernel.org/r/20240302-class_cleanup-net-next-v1-5-8fa378595b93@marliere.net
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Ricardo B. Marliere and committed by
Jakub Kicinski
070bef83 d9567f21

+15 -15
+15 -15
drivers/net/wwan/wwan_core.c
··· 26 26 static DEFINE_MUTEX(wwan_register_lock); /* WWAN device create|remove lock */ 27 27 static DEFINE_IDA(minors); /* minors for WWAN port chardevs */ 28 28 static DEFINE_IDA(wwan_dev_ids); /* for unique WWAN device IDs */ 29 - static struct class *wwan_class; 29 + static const struct class wwan_class = { 30 + .name = "wwan", 31 + }; 30 32 static int wwan_major; 31 33 static struct dentry *wwan_debugfs_dir; 32 34 ··· 132 130 { 133 131 struct device *dev; 134 132 135 - dev = class_find_device(wwan_class, NULL, parent, wwan_dev_parent_match); 133 + dev = class_find_device(&wwan_class, NULL, parent, wwan_dev_parent_match); 136 134 if (!dev) 137 135 return ERR_PTR(-ENODEV); 138 136 ··· 149 147 { 150 148 struct device *dev; 151 149 152 - dev = class_find_device(wwan_class, NULL, name, wwan_dev_name_match); 150 + dev = class_find_device(&wwan_class, NULL, name, wwan_dev_name_match); 153 151 if (!dev) 154 152 return ERR_PTR(-ENODEV); 155 153 ··· 185 183 { 186 184 struct device *dev; 187 185 188 - dev = class_find_device(wwan_class, NULL, dir, wwan_dev_debugfs_match); 186 + dev = class_find_device(&wwan_class, NULL, dir, wwan_dev_debugfs_match); 189 187 if (!dev) 190 188 return ERR_PTR(-ENODEV); 191 189 ··· 241 239 } 242 240 243 241 wwandev->dev.parent = parent; 244 - wwandev->dev.class = wwan_class; 242 + wwandev->dev.class = &wwan_class; 245 243 wwandev->dev.type = &wwan_dev_type; 246 244 wwandev->id = id; 247 245 dev_set_name(&wwandev->dev, "wwan%d", wwandev->id); ··· 267 265 268 266 static int is_wwan_child(struct device *dev, void *data) 269 267 { 270 - return dev->class == wwan_class; 268 + return dev->class == &wwan_class; 271 269 } 272 270 273 271 static void wwan_remove_dev(struct wwan_device *wwandev) ··· 377 375 { 378 376 struct device *dev; 379 377 380 - dev = class_find_device(wwan_class, NULL, &minor, wwan_port_minor_match); 378 + dev = class_find_device(&wwan_class, NULL, &minor, wwan_port_minor_match); 381 379 if (!dev) 382 380 return ERR_PTR(-ENODEV); 383 381 ··· 407 405 return -ENOMEM; 408 406 409 407 /* Collect ids of same name format ports */ 410 - class_dev_iter_init(&iter, wwan_class, NULL, &wwan_port_dev_type); 408 + class_dev_iter_init(&iter, &wwan_class, NULL, &wwan_port_dev_type); 411 409 while ((dev = class_dev_iter_next(&iter))) { 412 410 if (dev->parent != &wwandev->dev) 413 411 continue; ··· 479 477 mutex_init(&port->data_lock); 480 478 481 479 port->dev.parent = &wwandev->dev; 482 - port->dev.class = wwan_class; 480 + port->dev.class = &wwan_class; 483 481 port->dev.type = &wwan_port_dev_type; 484 482 port->dev.devt = MKDEV(wwan_major, minor); 485 483 dev_set_drvdata(&port->dev, drvdata); ··· 1214 1212 if (err) 1215 1213 return err; 1216 1214 1217 - wwan_class = class_create("wwan"); 1218 - if (IS_ERR(wwan_class)) { 1219 - err = PTR_ERR(wwan_class); 1215 + err = class_register(&wwan_class); 1216 + if (err) 1220 1217 goto unregister; 1221 - } 1222 1218 1223 1219 /* chrdev used for wwan ports */ 1224 1220 wwan_major = __register_chrdev(0, 0, WWAN_MAX_MINORS, "wwan_port", ··· 1233 1233 return 0; 1234 1234 1235 1235 destroy: 1236 - class_destroy(wwan_class); 1236 + class_unregister(&wwan_class); 1237 1237 unregister: 1238 1238 rtnl_link_unregister(&wwan_rtnl_link_ops); 1239 1239 return err; ··· 1244 1244 debugfs_remove_recursive(wwan_debugfs_dir); 1245 1245 __unregister_chrdev(wwan_major, 0, WWAN_MAX_MINORS, "wwan_port"); 1246 1246 rtnl_link_unregister(&wwan_rtnl_link_ops); 1247 - class_destroy(wwan_class); 1247 + class_unregister(&wwan_class); 1248 1248 } 1249 1249 1250 1250 module_init(wwan_init);