ptp: make ptp_class constant
Since commit 43a7206b09
("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>
This commit is contained in:
parent
44208f5936
commit
c057eddcb4
|
@ -25,7 +25,10 @@
|
|||
#define PTP_PPS_EVENT PPS_CAPTUREASSERT
|
||||
#define PTP_PPS_MODE (PTP_PPS_DEFAULTS | PPS_CANWAIT | PPS_TSFMT_TSPEC)
|
||||
|
||||
struct class *ptp_class;
|
||||
const struct class ptp_class = {
|
||||
.name = "ptp",
|
||||
.dev_groups = ptp_groups
|
||||
};
|
||||
|
||||
/* private globals */
|
||||
|
||||
|
@ -335,7 +338,7 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
|
|||
/* Initialize a new device of our class in our clock structure. */
|
||||
device_initialize(&ptp->dev);
|
||||
ptp->dev.devt = ptp->devid;
|
||||
ptp->dev.class = ptp_class;
|
||||
ptp->dev.class = &ptp_class;
|
||||
ptp->dev.parent = parent;
|
||||
ptp->dev.groups = ptp->pin_attr_groups;
|
||||
ptp->dev.release = ptp_clock_release;
|
||||
|
@ -509,7 +512,7 @@ EXPORT_SYMBOL(ptp_cancel_worker_sync);
|
|||
|
||||
static void __exit ptp_exit(void)
|
||||
{
|
||||
class_destroy(ptp_class);
|
||||
class_unregister(&ptp_class);
|
||||
unregister_chrdev_region(ptp_devt, MINORMASK + 1);
|
||||
ida_destroy(&ptp_clocks_map);
|
||||
}
|
||||
|
@ -518,10 +521,10 @@ static int __init ptp_init(void)
|
|||
{
|
||||
int err;
|
||||
|
||||
ptp_class = class_create("ptp");
|
||||
if (IS_ERR(ptp_class)) {
|
||||
err = class_register(&ptp_class);
|
||||
if (err) {
|
||||
pr_err("ptp: failed to allocate class\n");
|
||||
return PTR_ERR(ptp_class);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = alloc_chrdev_region(&ptp_devt, 0, MINORMASK + 1, "ptp");
|
||||
|
@ -530,12 +533,11 @@ static int __init ptp_init(void)
|
|||
goto no_region;
|
||||
}
|
||||
|
||||
ptp_class->dev_groups = ptp_groups;
|
||||
pr_info("PTP clock support registered\n");
|
||||
return 0;
|
||||
|
||||
no_region:
|
||||
class_destroy(ptp_class);
|
||||
class_unregister(&ptp_class);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ static inline bool ptp_clock_freerun(struct ptp_clock *ptp)
|
|||
return ptp_vclock_in_use(ptp);
|
||||
}
|
||||
|
||||
extern struct class *ptp_class;
|
||||
extern const struct class ptp_class;
|
||||
|
||||
/*
|
||||
* see ptp_chardev.c
|
||||
|
|
|
@ -241,7 +241,7 @@ int ptp_get_vclocks_index(int pclock_index, int **vclock_index)
|
|||
return num;
|
||||
|
||||
snprintf(name, PTP_CLOCK_NAME_LEN, "ptp%d", pclock_index);
|
||||
dev = class_find_device_by_name(ptp_class, name);
|
||||
dev = class_find_device_by_name(&ptp_class, name);
|
||||
if (!dev)
|
||||
return num;
|
||||
|
||||
|
|
Loading…
Reference in New Issue