Skip to contentSkip to conversation

ptp: Return -EINVAL on ptp_clock_register if required ops are NULL

PATCH Superseded Tim Hostetler 3 participants 4 messages Oct 30, 2025 – Nov 4, 2025

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

Fixes d7d38f5bd7be ("ptp: use the 64 bit get/set time methods for the posix clock.")
---
 drivers/ptp/ptp_clock.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/ptp/ptp_clock.c +4 -0
index ef020599b771..0bc79076771b 100644
@@ -325,6 +325,10 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
 	if (info->n_alarm > PTP_MAX_ALARMS)
 		return ERR_PTR(-EINVAL);
 
+	if (WARN_ON_ONCE((!info->gettimex64 && !info->gettime64) ||
+			 !info->settime64))
+		return ERR_PTR(-EINVAL);
+
 	/* Initialize a clock structure. */
 	ptp = kzalloc(sizeof(struct ptp_clock), GFP_KERNEL);
 	if (!ptp) {
Signature · 1 line
2.51.1.851.g4ebd6896fd-goog
maintainer
#1 lore raw
Quoted 6 lines · On Thu, 30 Oct 2025 11:08:32 -0700 Tim Hostetler wrote:

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.

Fixes d7d38f5bd7be ("ptp: use the 64 bit get/set time methods for the posix clock.")

This needs to go to net-next without the tags above. The check can only help with new drivers, old ones _must_ be fixed like gve was. Not registering a driver is a regression.

Quoted 13 lines
---
 drivers/ptp/ptp_clock.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/ptp/ptp_clock.c +0 -0
index ef020599b771..0bc79076771b 100644

drivers/ptp/ptp_clock.c struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info, · line 325

Quoted 1 line
drivers/ptp/ptp_clock.c +0 -0
@@ -325,6 +325,10 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
 	if (info->n_alarm > PTP_MAX_ALARMS)

->n_alarm check is also input validation, you should probably fold it into your new WARN_ON_ONCE(). Either that or remove the WARN_ON_ONCE() annotation below. As is the checks are inconsistent.

Quoted 6 lines
drivers/ptp/ptp_clock.c +4 -0
 		return ERR_PTR(-EINVAL);
 
+	if (WARN_ON_ONCE((!info->gettimex64 && !info->gettime64) ||
+			 !info->settime64))
+		return ERR_PTR(-EINVAL);
+
Reviewed-by on v1 1/1
#2 lore raw
In reply to Tim Hostetler
Quoted 19 lines · Tim Hostetler

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.

Fixes d7d38f5bd7be ("ptp: use the 64 bit get/set time methods for the posix clock.")
---
  drivers/ptp/ptp_clock.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/ptp/ptp_clock.c +0 -0
index ef020599b771..0bc79076771b 100644

drivers/ptp/ptp_clock.c struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info, · line 334

Quoted 10 lines
drivers/ptp/ptp_clock.c +4 -0
@@ -325,6 +325,10 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
  	if (info->n_alarm > PTP_MAX_ALARMS)
  		return ERR_PTR(-EINVAL);
 
+	if (WARN_ON_ONCE((!info->gettimex64 && !info->gettime64) ||
+			 !info->settime64))
+		return ERR_PTR(-EINVAL);
+
  	/* Initialize a clock structure. */
  	ptp = kzalloc(sizeof(struct ptp_clock), GFP_KERNEL);
  	if (!ptp) {

The patch itself LGTM, but I believe it should be targeted to net-next, as it doesn't actually fix any problem with GVE patches landed net tree already.

#3 lore raw
Quoted 6 lines · Vadim Fedorenko

The patch itself LGTM, but I believe it should be targeted to net-next, as it doesn't actually fix any problem with GVE patches landed net tree already.

Thanks Vadim and Jakub, I'll spin a v2 for net-next and fold all the input validation into one WARN_ON_ONCE per Jakub's suggestion.