Skip to content

Commit dfb073d

Browse files
tdh911kuba-moo
authored andcommitted
ptp: Return -EINVAL on ptp_clock_register if required ops are NULL
ptp_clock should never be registered unless it stubs one of gettimex64() or gettime64() and settime64(). WARN_ON_ONCE and error out if either set of function pointers is null. For consistency, n_alarm validation is also folded into the WARN_ON_ONCE. Suggested-by: Kuniyuki Iwashima <kuniyu@google.com> Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com> Reviewed-by: Harshitha Ramamurthy <hramamurthy@google.com> Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev> Signed-off-by: Tim Hostetler <thostet@google.com> Acked-by: Richard Cochran <richardcochran@gmail.com> Link: https://patch.msgid.link/20251104225915.2040080-1-thostet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 89aec17 commit dfb073d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/ptp/ptp_clock.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,9 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
322322
char debugfsname[16];
323323
size_t size;
324324

325-
if (info->n_alarm > PTP_MAX_ALARMS)
325+
if (WARN_ON_ONCE(info->n_alarm > PTP_MAX_ALARMS ||
326+
(!info->gettimex64 && !info->gettime64) ||
327+
!info->settime64))
326328
return ERR_PTR(-EINVAL);
327329

328330
/* Initialize a clock structure. */

0 commit comments

Comments
 (0)