Skip to content

Commit 73a42f4

Browse files
committed
Merge branch 'net-constify-struct-class-usage'
Ricardo B. Marliere says: ==================== net: constify struct class usage This is a simple and straight forward cleanup series that aims to make the class structures in net constant. This has been possible since 2023 [1]. [1]: https://lore.kernel.org/all/2023040248-customary-release-4aec@gregkh/ ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents e8efd37 + e556001 commit 73a42f4

File tree

7 files changed

+50
-52
lines changed

7 files changed

+50
-52
lines changed

drivers/net/ethernet/hisilicon/hns/hnae.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
#define cls_to_ae_dev(dev) container_of(dev, struct hnae_ae_dev, cls_dev)
1414

15-
static struct class *hnae_class;
15+
static const struct class hnae_class = {
16+
.name = "hnae",
17+
};
1618

1719
static void
1820
hnae_list_add(spinlock_t *lock, struct list_head *node, struct list_head *head)
@@ -111,7 +113,7 @@ static struct hnae_ae_dev *find_ae(const struct fwnode_handle *fwnode)
111113

112114
WARN_ON(!fwnode);
113115

114-
dev = class_find_device(hnae_class, NULL, fwnode, __ae_match);
116+
dev = class_find_device(&hnae_class, NULL, fwnode, __ae_match);
115117

116118
return dev ? cls_to_ae_dev(dev) : NULL;
117119
}
@@ -415,7 +417,7 @@ int hnae_ae_register(struct hnae_ae_dev *hdev, struct module *owner)
415417
hdev->owner = owner;
416418
hdev->id = (int)atomic_inc_return(&id);
417419
hdev->cls_dev.parent = hdev->dev;
418-
hdev->cls_dev.class = hnae_class;
420+
hdev->cls_dev.class = &hnae_class;
419421
hdev->cls_dev.release = hnae_release;
420422
(void)dev_set_name(&hdev->cls_dev, "hnae%d", hdev->id);
421423
ret = device_register(&hdev->cls_dev);
@@ -448,13 +450,12 @@ EXPORT_SYMBOL(hnae_ae_unregister);
448450

449451
static int __init hnae_init(void)
450452
{
451-
hnae_class = class_create("hnae");
452-
return PTR_ERR_OR_ZERO(hnae_class);
453+
return class_register(&hnae_class);
453454
}
454455

455456
static void __exit hnae_exit(void)
456457
{
457-
class_destroy(hnae_class);
458+
class_unregister(&hnae_class);
458459
}
459460

460461
subsys_initcall(hnae_init);

drivers/net/ppp/ppp_generic.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,9 @@ static void ppp_setup(struct net_device *dev);
295295

296296
static const struct net_device_ops ppp_netdev_ops;
297297

298-
static struct class *ppp_class;
298+
static const struct class ppp_class = {
299+
.name = "ppp",
300+
};
299301

300302
/* per net-namespace data */
301303
static inline struct ppp_net *ppp_pernet(struct net *net)
@@ -1394,11 +1396,9 @@ static int __init ppp_init(void)
13941396
goto out_net;
13951397
}
13961398

1397-
ppp_class = class_create("ppp");
1398-
if (IS_ERR(ppp_class)) {
1399-
err = PTR_ERR(ppp_class);
1399+
err = class_register(&ppp_class);
1400+
if (err)
14001401
goto out_chrdev;
1401-
}
14021402

14031403
err = rtnl_link_register(&ppp_link_ops);
14041404
if (err) {
@@ -1407,12 +1407,12 @@ static int __init ppp_init(void)
14071407
}
14081408

14091409
/* not a big deal if we fail here :-) */
1410-
device_create(ppp_class, NULL, MKDEV(PPP_MAJOR, 0), NULL, "ppp");
1410+
device_create(&ppp_class, NULL, MKDEV(PPP_MAJOR, 0), NULL, "ppp");
14111411

14121412
return 0;
14131413

14141414
out_class:
1415-
class_destroy(ppp_class);
1415+
class_unregister(&ppp_class);
14161416
out_chrdev:
14171417
unregister_chrdev(PPP_MAJOR, "ppp");
14181418
out_net:
@@ -3549,8 +3549,8 @@ static void __exit ppp_cleanup(void)
35493549
pr_err("PPP: removing module but units remain!\n");
35503550
rtnl_link_unregister(&ppp_link_ops);
35513551
unregister_chrdev(PPP_MAJOR, "ppp");
3552-
device_destroy(ppp_class, MKDEV(PPP_MAJOR, 0));
3553-
class_destroy(ppp_class);
3552+
device_destroy(&ppp_class, MKDEV(PPP_MAJOR, 0));
3553+
class_unregister(&ppp_class);
35543554
unregister_pernet_device(&ppp_net_ops);
35553555
}
35563556

drivers/net/wan/framer/framer-core.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818
#include <linux/regulator/consumer.h>
1919
#include <linux/slab.h>
2020

21-
static struct class *framer_class;
21+
static void framer_release(struct device *dev);
22+
static const struct class framer_class = {
23+
.name = "framer",
24+
.dev_release = framer_release,
25+
};
26+
2227
static DEFINE_MUTEX(framer_provider_mutex);
2328
static LIST_HEAD(framer_provider_list);
2429
static DEFINE_IDA(framer_ida);
@@ -627,7 +632,7 @@ struct framer *framer_create(struct device *dev, struct device_node *node,
627632
INIT_DELAYED_WORK(&framer->polling_work, framer_polling_work);
628633
BLOCKING_INIT_NOTIFIER_HEAD(&framer->notifier_list);
629634

630-
framer->dev.class = framer_class;
635+
framer->dev.class = &framer_class;
631636
framer->dev.parent = dev;
632637
framer->dev.of_node = node ? node : dev->of_node;
633638
framer->id = id;
@@ -741,7 +746,7 @@ struct framer *framer_provider_simple_of_xlate(struct device *dev,
741746
struct class_dev_iter iter;
742747
struct framer *framer;
743748

744-
class_dev_iter_init(&iter, framer_class, NULL, NULL);
749+
class_dev_iter_init(&iter, &framer_class, NULL, NULL);
745750
while ((dev = class_dev_iter_next(&iter))) {
746751
framer = dev_to_framer(dev);
747752
if (args->np != framer->dev.of_node)
@@ -870,14 +875,6 @@ static void framer_release(struct device *dev)
870875

871876
static int __init framer_core_init(void)
872877
{
873-
framer_class = class_create("framer");
874-
if (IS_ERR(framer_class)) {
875-
pr_err("failed to create framer class (%pe)\n", framer_class);
876-
return PTR_ERR(framer_class);
877-
}
878-
879-
framer_class->dev_release = framer_release;
880-
881-
return 0;
878+
return class_register(&framer_class);
882879
}
883880
device_initcall(framer_core_init);

drivers/net/wwan/wwan_core.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
static DEFINE_MUTEX(wwan_register_lock); /* WWAN device create|remove lock */
2727
static DEFINE_IDA(minors); /* minors for WWAN port chardevs */
2828
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+
};
3032
static int wwan_major;
3133
static struct dentry *wwan_debugfs_dir;
3234

@@ -130,7 +132,7 @@ static struct wwan_device *wwan_dev_get_by_parent(struct device *parent)
130132
{
131133
struct device *dev;
132134

133-
dev = class_find_device(wwan_class, NULL, parent, wwan_dev_parent_match);
135+
dev = class_find_device(&wwan_class, NULL, parent, wwan_dev_parent_match);
134136
if (!dev)
135137
return ERR_PTR(-ENODEV);
136138

@@ -147,7 +149,7 @@ static struct wwan_device *wwan_dev_get_by_name(const char *name)
147149
{
148150
struct device *dev;
149151

150-
dev = class_find_device(wwan_class, NULL, name, wwan_dev_name_match);
152+
dev = class_find_device(&wwan_class, NULL, name, wwan_dev_name_match);
151153
if (!dev)
152154
return ERR_PTR(-ENODEV);
153155

@@ -183,7 +185,7 @@ static struct wwan_device *wwan_dev_get_by_debugfs(struct dentry *dir)
183185
{
184186
struct device *dev;
185187

186-
dev = class_find_device(wwan_class, NULL, dir, wwan_dev_debugfs_match);
188+
dev = class_find_device(&wwan_class, NULL, dir, wwan_dev_debugfs_match);
187189
if (!dev)
188190
return ERR_PTR(-ENODEV);
189191

@@ -239,7 +241,7 @@ static struct wwan_device *wwan_create_dev(struct device *parent)
239241
}
240242

241243
wwandev->dev.parent = parent;
242-
wwandev->dev.class = wwan_class;
244+
wwandev->dev.class = &wwan_class;
243245
wwandev->dev.type = &wwan_dev_type;
244246
wwandev->id = id;
245247
dev_set_name(&wwandev->dev, "wwan%d", wwandev->id);
@@ -265,7 +267,7 @@ static struct wwan_device *wwan_create_dev(struct device *parent)
265267

266268
static int is_wwan_child(struct device *dev, void *data)
267269
{
268-
return dev->class == wwan_class;
270+
return dev->class == &wwan_class;
269271
}
270272

271273
static void wwan_remove_dev(struct wwan_device *wwandev)
@@ -375,7 +377,7 @@ static struct wwan_port *wwan_port_get_by_minor(unsigned int minor)
375377
{
376378
struct device *dev;
377379

378-
dev = class_find_device(wwan_class, NULL, &minor, wwan_port_minor_match);
380+
dev = class_find_device(&wwan_class, NULL, &minor, wwan_port_minor_match);
379381
if (!dev)
380382
return ERR_PTR(-ENODEV);
381383

@@ -405,7 +407,7 @@ static int __wwan_port_dev_assign_name(struct wwan_port *port, const char *fmt)
405407
return -ENOMEM;
406408

407409
/* Collect ids of same name format ports */
408-
class_dev_iter_init(&iter, wwan_class, NULL, &wwan_port_dev_type);
410+
class_dev_iter_init(&iter, &wwan_class, NULL, &wwan_port_dev_type);
409411
while ((dev = class_dev_iter_next(&iter))) {
410412
if (dev->parent != &wwandev->dev)
411413
continue;
@@ -477,7 +479,7 @@ struct wwan_port *wwan_create_port(struct device *parent,
477479
mutex_init(&port->data_lock);
478480

479481
port->dev.parent = &wwandev->dev;
480-
port->dev.class = wwan_class;
482+
port->dev.class = &wwan_class;
481483
port->dev.type = &wwan_port_dev_type;
482484
port->dev.devt = MKDEV(wwan_major, minor);
483485
dev_set_drvdata(&port->dev, drvdata);
@@ -1212,11 +1214,9 @@ static int __init wwan_init(void)
12121214
if (err)
12131215
return err;
12141216

1215-
wwan_class = class_create("wwan");
1216-
if (IS_ERR(wwan_class)) {
1217-
err = PTR_ERR(wwan_class);
1217+
err = class_register(&wwan_class);
1218+
if (err)
12181219
goto unregister;
1219-
}
12201220

12211221
/* chrdev used for wwan ports */
12221222
wwan_major = __register_chrdev(0, 0, WWAN_MAX_MINORS, "wwan_port",
@@ -1233,7 +1233,7 @@ static int __init wwan_init(void)
12331233
return 0;
12341234

12351235
destroy:
1236-
class_destroy(wwan_class);
1236+
class_unregister(&wwan_class);
12371237
unregister:
12381238
rtnl_link_unregister(&wwan_rtnl_link_ops);
12391239
return err;
@@ -1244,7 +1244,7 @@ static void __exit wwan_exit(void)
12441244
debugfs_remove_recursive(wwan_debugfs_dir);
12451245
__unregister_chrdev(wwan_major, 0, WWAN_MAX_MINORS, "wwan_port");
12461246
rtnl_link_unregister(&wwan_rtnl_link_ops);
1247-
class_destroy(wwan_class);
1247+
class_unregister(&wwan_class);
12481248
}
12491249

12501250
module_init(wwan_init);

drivers/net/wwan/wwan_hwsim.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ static int wwan_hwsim_devsnum = 2;
2525
module_param_named(devices, wwan_hwsim_devsnum, int, 0444);
2626
MODULE_PARM_DESC(devices, "Number of simulated devices");
2727

28-
static struct class *wwan_hwsim_class;
28+
static const struct class wwan_hwsim_class = {
29+
.name = "wwan_hwsim",
30+
};
2931

3032
static struct dentry *wwan_hwsim_debugfs_topdir;
3133
static struct dentry *wwan_hwsim_debugfs_devcreate;
@@ -277,7 +279,7 @@ static struct wwan_hwsim_dev *wwan_hwsim_dev_new(void)
277279
spin_unlock(&wwan_hwsim_devs_lock);
278280

279281
dev->dev.release = wwan_hwsim_dev_release;
280-
dev->dev.class = wwan_hwsim_class;
282+
dev->dev.class = &wwan_hwsim_class;
281283
dev_set_name(&dev->dev, "hwsim%u", dev->id);
282284

283285
spin_lock_init(&dev->ports_lock);
@@ -511,11 +513,9 @@ static int __init wwan_hwsim_init(void)
511513
if (!wwan_wq)
512514
return -ENOMEM;
513515

514-
wwan_hwsim_class = class_create("wwan_hwsim");
515-
if (IS_ERR(wwan_hwsim_class)) {
516-
err = PTR_ERR(wwan_hwsim_class);
516+
err = class_register(&wwan_hwsim_class);
517+
if (err)
517518
goto err_wq_destroy;
518-
}
519519

520520
wwan_hwsim_debugfs_topdir = debugfs_create_dir("wwan_hwsim", NULL);
521521
wwan_hwsim_debugfs_devcreate =
@@ -534,7 +534,7 @@ static int __init wwan_hwsim_init(void)
534534
wwan_hwsim_free_devs();
535535
flush_workqueue(wwan_wq); /* Wait deletion works completion */
536536
debugfs_remove(wwan_hwsim_debugfs_topdir);
537-
class_destroy(wwan_hwsim_class);
537+
class_unregister(&wwan_hwsim_class);
538538
err_wq_destroy:
539539
destroy_workqueue(wwan_wq);
540540

@@ -547,7 +547,7 @@ static void __exit wwan_hwsim_exit(void)
547547
wwan_hwsim_free_devs();
548548
flush_workqueue(wwan_wq); /* Wait deletion works completion */
549549
debugfs_remove(wwan_hwsim_debugfs_topdir);
550-
class_destroy(wwan_hwsim_class);
550+
class_unregister(&wwan_hwsim_class);
551551
destroy_workqueue(wwan_wq);
552552
}
553553

include/net/nfc/nfc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ struct nfc_dev {
196196
};
197197
#define to_nfc_dev(_dev) container_of(_dev, struct nfc_dev, dev)
198198

199-
extern struct class nfc_class;
199+
extern const struct class nfc_class;
200200

201201
struct nfc_dev *nfc_allocate_device(const struct nfc_ops *ops,
202202
u32 supported_protocols,

net/nfc/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ static void nfc_check_pres_timeout(struct timer_list *t)
10151015
schedule_work(&dev->check_pres_work);
10161016
}
10171017

1018-
struct class nfc_class = {
1018+
const struct class nfc_class = {
10191019
.name = "nfc",
10201020
.dev_release = nfc_release,
10211021
};

0 commit comments

Comments
 (0)