Thread (10 messages) 10 messages, 3 authors, 2021-12-09

Re: [PATCH net-next 1/2] net_tstamp: add new flag HWTSTAMP_FLAGS_UNSTABLE_PHC

flat view

From: Hangbin Liu <hidden>
Date: 2021-12-08 06:27:59
Subsystem: networking [general], the rest · Maintainers: "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds

On Tue, Dec 07, 2021 at 10:08:14PM -0800, Jakub Kicinski wrote:
On Wed,  8 Dec 2021 12:42:23 +0800 Hangbin Liu wrote:
quoted
-	/* Reserved for future extensions */
-	if (config->flags)
-		return -EINVAL;
Should we do something like:

	if (config->flags & ~PHC_DRIVER_IGNORED_FLAGS)
		return -EINVAL;

Or whatnot? We still want the drivers to reject bits other than the new
flag.
How about just add the check in net_hwtstamp_validate().
I think that should be enough. e.g.
diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
index a81c98cfc3db..256d2e26487f 100644
--- a/net/core/dev_ioctl.c
+++ b/net/core/dev_ioctl.c
@@ -186,15 +186,27 @@ static int net_hwtstamp_validate(struct ifreq *ifr)
 	struct hwtstamp_config cfg;
 	enum hwtstamp_tx_types tx_type;
 	enum hwtstamp_rx_filters rx_filter;
-	int tx_type_valid = 0;
+	enum hwtstamp_flags flags;
 	int rx_filter_valid = 0;
+	int tx_type_valid = 0;
+	int flags_valid = 0;
 
 	if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
 		return -EFAULT;
 
+	flags = cfg.flags;
 	tx_type = cfg.tx_type;
 	rx_filter = cfg.rx_filter;
 
+	switch (flags) {
+	case HWTSTAMP_FLAGS_UNSTABLE_PHC:
+		flags_valid = 1;
+		break;
+	case __HWTSTAMP_FLAGS_CNT:
+		/* not a real value */
+		break;
+	}
+
 	switch (tx_type) {
 	case HWTSTAMP_TX_OFF:
 	case HWTSTAMP_TX_ON:
@@ -231,7 +243,7 @@ static int net_hwtstamp_validate(struct ifreq *ifr)
 		break;
 	}
 
-	if (!tx_type_valid || !rx_filter_valid)
+	if (!flags_valid || !tx_type_valid || !rx_filter_valid)
 		return -ERANGE;
 
 	return 0;
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help