Skip to content

Commit c057edd

Browse files
rbmarlierekuba-moo
authored andcommitted
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 <[email protected]> Signed-off-by: Ricardo B. Marliere <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 44208f5 commit c057edd

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
@@ -25,7 +25,10 @@
2525
#define PTP_PPS_EVENT PPS_CAPTUREASSERT
2626
#define PTP_PPS_MODE (PTP_PPS_DEFAULTS | PPS_CANWAIT | PPS_TSFMT_TSPEC)
2727

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

3033
/* private globals */
3134

@@ -335,7 +338,7 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
335338
/* Initialize a new device of our class in our clock structure. */
336339
device_initialize(&ptp->dev);
337340
ptp->dev.devt = ptp->devid;
338-
ptp->dev.class = ptp_class;
341+
ptp->dev.class = &ptp_class;
339342
ptp->dev.parent = parent;
340343
ptp->dev.groups = ptp->pin_attr_groups;
341344
ptp->dev.release = ptp_clock_release;
@@ -509,7 +512,7 @@ EXPORT_SYMBOL(ptp_cancel_worker_sync);
509512

510513
static void __exit ptp_exit(void)
511514
{
512-
class_destroy(ptp_class);
515+
class_unregister(&ptp_class);
513516
unregister_chrdev_region(ptp_devt, MINORMASK + 1);
514517
ida_destroy(&ptp_clocks_map);
515518
}
@@ -518,10 +521,10 @@ static int __init ptp_init(void)
518521
{
519522
int err;
520523

521-
ptp_class = class_create("ptp");
522-
if (IS_ERR(ptp_class)) {
524+
err = class_register(&ptp_class);
525+
if (err) {
523526
pr_err("ptp: failed to allocate class\n");
524-
return PTR_ERR(ptp_class);
527+
return err;
525528
}
526529

527530
err = alloc_chrdev_region(&ptp_devt, 0, MINORMASK + 1, "ptp");
@@ -530,12 +533,11 @@ static int __init ptp_init(void)
530533
goto no_region;
531534
}
532535

533-
ptp_class->dev_groups = ptp_groups;
534536
pr_info("PTP clock support registered\n");
535537
return 0;
536538

537539
no_region:
538-
class_destroy(ptp_class);
540+
class_unregister(&ptp_class);
539541
return err;
540542
}
541543

drivers/ptp/ptp_private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ static inline bool ptp_clock_freerun(struct ptp_clock *ptp)
120120
return ptp_vclock_in_use(ptp);
121121
}
122122

123-
extern struct class *ptp_class;
123+
extern const struct class ptp_class;
124124

125125
/*
126126
* 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)