Skip to content

Commit edfef66

Browse files
committed
Merge: ptp: stable backport for 9.7 phase 2
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/6644 JIRA: https://issues.redhat.com/browse/RHEL-85028 Signed-off-by: Hangbin Liu <[email protected]> Approved-by: Jiri Benc <[email protected]> Approved-by: Xin Long <[email protected]> Approved-by: CKI KWF Bot <[email protected]> Merged-by: Augusto Caringi <[email protected]>
2 parents be616bb + 8d48fed commit edfef66

File tree

5 files changed

+25
-12
lines changed

5 files changed

+25
-12
lines changed

drivers/ptp/ptp_chardev.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
* Copyright (C) 2010 OMICRON electronics GmbH
66
*/
7+
#include <linux/compat.h>
78
#include <linux/module.h>
89
#include <linux/posix-clock.h>
910
#include <linux/poll.h>
@@ -124,6 +125,9 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)
124125
struct timespec64 ts;
125126
int enable, err = 0;
126127

128+
if (in_compat_syscall() && cmd != PTP_ENABLE_PPS && cmd != PTP_ENABLE_PPS2)
129+
arg = (unsigned long)compat_ptr(arg);
130+
127131
switch (cmd) {
128132

129133
case PTP_CLOCK_GETCAPS:

drivers/ptp/ptp_clock.c

Lines changed: 18 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

@@ -189,6 +192,11 @@ static int ptp_getcycles64(struct ptp_clock_info *info, struct timespec64 *ts)
189192
return info->gettime64(info, ts);
190193
}
191194

195+
static int ptp_enable(struct ptp_clock_info *ptp, struct ptp_clock_request *request, int on)
196+
{
197+
return -EOPNOTSUPP;
198+
}
199+
192200
static void ptp_aux_kworker(struct kthread_work *work)
193201
{
194202
struct ptp_clock *ptp = container_of(work, struct ptp_clock,
@@ -251,6 +259,9 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
251259
ptp->info->getcrosscycles = ptp->info->getcrosststamp;
252260
}
253261

262+
if (!ptp->info->enable)
263+
ptp->info->enable = ptp_enable;
264+
254265
if (ptp->info->do_aux_work) {
255266
kthread_init_delayed_work(&ptp->aux_work, ptp_aux_kworker);
256267
ptp->kworker = kthread_create_worker(0, "ptp%d", ptp->index);
@@ -300,7 +311,7 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
300311
/* Initialize a new device of our class in our clock structure. */
301312
device_initialize(&ptp->dev);
302313
ptp->dev.devt = ptp->devid;
303-
ptp->dev.class = ptp_class;
314+
ptp->dev.class = &ptp_class;
304315
ptp->dev.parent = parent;
305316
ptp->dev.groups = ptp->pin_attr_groups;
306317
ptp->dev.release = ptp_clock_release;
@@ -457,7 +468,7 @@ EXPORT_SYMBOL(ptp_cancel_worker_sync);
457468

458469
static void __exit ptp_exit(void)
459470
{
460-
class_destroy(ptp_class);
471+
class_unregister(&ptp_class);
461472
unregister_chrdev_region(ptp_devt, MINORMASK + 1);
462473
ida_destroy(&ptp_clocks_map);
463474
}
@@ -466,10 +477,10 @@ static int __init ptp_init(void)
466477
{
467478
int err;
468479

469-
ptp_class = class_create("ptp");
470-
if (IS_ERR(ptp_class)) {
480+
err = class_register(&ptp_class);
481+
if (err) {
471482
pr_err("ptp: failed to allocate class\n");
472-
return PTR_ERR(ptp_class);
483+
return err;
473484
}
474485

475486
err = alloc_chrdev_region(&ptp_devt, 0, MINORMASK + 1, "ptp");
@@ -478,12 +489,11 @@ static int __init ptp_init(void)
478489
goto no_region;
479490
}
480491

481-
ptp_class->dev_groups = ptp_groups;
482492
pr_info("PTP clock support registered\n");
483493
return 0;
484494

485495
no_region:
486-
class_destroy(ptp_class);
496+
class_unregister(&ptp_class);
487497
return err;
488498
}
489499

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_sysfs.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,7 @@ static ssize_t max_vclocks_store(struct device *dev,
294294
if (max < ptp->n_vclocks)
295295
goto out;
296296

297-
size = sizeof(int) * max;
298-
vclock_index = kzalloc(size, GFP_KERNEL);
297+
vclock_index = kcalloc(max, sizeof(int), GFP_KERNEL);
299298
if (!vclock_index) {
300299
err = -ENOMEM;
301300
goto out;

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)