Skip to content

Commit b2cc54a

Browse files
author
Hangbin Liu
committed
ptp: make ptp_class constant
JIRA: https://issues.redhat.com/browse/RHEL-85028 Upstream Status: net.git commit c057edd commit c057edd Author: Ricardo B. Marliere <ricardo@marliere.net> Date: Tue Mar 5 17:11:27 2024 -0300 ptp: make ptp_class constant Since commit 43a7206 ("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 ptp_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> Reviewed-by: Simon Horman <horms@kernel.org> Link: https://lore.kernel.org/r/20240305-ptp-v1-1-ed253eb33c20@marliere.net Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Hangbin Liu <haliu@redhat.com>
1 parent ddd3653 commit b2cc54a

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

drivers/ptp/ptp_clock.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
#define PTP_PPS_EVENT PPS_CAPTUREASSERT
2525
#define PTP_PPS_MODE (PTP_PPS_DEFAULTS | PPS_CANWAIT | PPS_TSFMT_TSPEC)
2626

27-
struct class *ptp_class;
27+
const struct class ptp_class = {
28+
.name = "ptp",
29+
.dev_groups = ptp_groups
30+
};
2831

2932
/* private globals */
3033

@@ -300,7 +303,7 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
300303
/* Initialize a new device of our class in our clock structure. */
301304
device_initialize(&ptp->dev);
302305
ptp->dev.devt = ptp->devid;
303-
ptp->dev.class = ptp_class;
306+
ptp->dev.class = &ptp_class;
304307
ptp->dev.parent = parent;
305308
ptp->dev.groups = ptp->pin_attr_groups;
306309
ptp->dev.release = ptp_clock_release;
@@ -457,7 +460,7 @@ EXPORT_SYMBOL(ptp_cancel_worker_sync);
457460

458461
static void __exit ptp_exit(void)
459462
{
460-
class_destroy(ptp_class);
463+
class_unregister(&ptp_class);
461464
unregister_chrdev_region(ptp_devt, MINORMASK + 1);
462465
ida_destroy(&ptp_clocks_map);
463466
}
@@ -466,10 +469,10 @@ static int __init ptp_init(void)
466469
{
467470
int err;
468471

469-
ptp_class = class_create("ptp");
470-
if (IS_ERR(ptp_class)) {
472+
err = class_register(&ptp_class);
473+
if (err) {
471474
pr_err("ptp: failed to allocate class\n");
472-
return PTR_ERR(ptp_class);
475+
return err;
473476
}
474477

475478
err = alloc_chrdev_region(&ptp_devt, 0, MINORMASK + 1, "ptp");
@@ -478,12 +481,11 @@ static int __init ptp_init(void)
478481
goto no_region;
479482
}
480483

481-
ptp_class->dev_groups = ptp_groups;
482484
pr_info("PTP clock support registered\n");
483485
return 0;
484486

485487
no_region:
486-
class_destroy(ptp_class);
488+
class_unregister(&ptp_class);
487489
return err;
488490
}
489491

drivers/ptp/ptp_private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static inline bool ptp_clock_freerun(struct ptp_clock *ptp)
111111
return ptp_vclock_in_use(ptp);
112112
}
113113

114-
extern struct class *ptp_class;
114+
extern const struct class ptp_class;
115115

116116
/*
117117
* see ptp_chardev.c

drivers/ptp/ptp_vclock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ int ptp_get_vclocks_index(int pclock_index, int **vclock_index)
241241
return num;
242242

243243
snprintf(name, PTP_CLOCK_NAME_LEN, "ptp%d", pclock_index);
244-
dev = class_find_device_by_name(ptp_class, name);
244+
dev = class_find_device_by_name(&ptp_class, name);
245245
if (!dev)
246246
return num;
247247

0 commit comments

Comments
 (0)