Commit dfb073d3 authored by Tim Hostetler's avatar Tim Hostetler Committed by Jakub Kicinski
Browse files

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: default avatarKuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: default avatarKuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: default avatarHarshitha Ramamurthy <hramamurthy@google.com>
Reviewed-by: default avatarVadim Fedorenko <vadim.fedorenko@linux.dev>
Signed-off-by: default avatarTim Hostetler <thostet@google.com>
Acked-by: default avatarRichard Cochran <richardcochran@gmail.com>
Link: https://patch.msgid.link/20251104225915.2040080-1-thostet@google.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 89aec171
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -322,7 +322,9 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
	char debugfsname[16];
	size_t size;

	if (info->n_alarm > PTP_MAX_ALARMS)
	if (WARN_ON_ONCE(info->n_alarm > PTP_MAX_ALARMS ||
			 (!info->gettimex64 && !info->gettime64) ||
			 !info->settime64))
		return ERR_PTR(-EINVAL);

	/* Initialize a clock structure. */