[PATCH net 2/3] net: ethtool: tsconfig: Fix ts filters and types enums size check

Kory Maincent posted 3 patches 1 year ago
[PATCH net 2/3] net: ethtool: tsconfig: Fix ts filters and types enums size check
Posted by Kory Maincent 1 year ago
Fix the size check for the hwtstamp_tx_types and hwtstamp_rx_filters
enumerations. Align this check with the approach used in tsinfo for
consistency and correctness.

Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
Fixes: 6e9e2eed4f39 ("net: ethtool: Add support for tsconfig command to get/set hwtstamp config")
---
 net/ethtool/tsconfig.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/ethtool/tsconfig.c b/net/ethtool/tsconfig.c
index 9188e088fb2f..2dc3a3b76615 100644
--- a/net/ethtool/tsconfig.c
+++ b/net/ethtool/tsconfig.c
@@ -294,8 +294,8 @@ static int ethnl_set_tsconfig(struct ethnl_req_info *req_base,
 	struct nlattr **tb = info->attrs;
 	int ret;
 
-	BUILD_BUG_ON(__HWTSTAMP_TX_CNT >= 32);
-	BUILD_BUG_ON(__HWTSTAMP_FILTER_CNT >= 32);
+	BUILD_BUG_ON(__HWTSTAMP_TX_CNT > 32);
+	BUILD_BUG_ON(__HWTSTAMP_FILTER_CNT > 32);
 
 	if (!netif_device_present(dev))
 		return -ENODEV;

-- 
2.34.1
Re: [PATCH net 2/3] net: ethtool: tsconfig: Fix ts filters and types enums size check
Posted by Jakub Kicinski 1 year ago
On Tue, 28 Jan 2025 16:35:47 +0100 Kory Maincent wrote:
> Fix the size check for the hwtstamp_tx_types and hwtstamp_rx_filters
> enumerations.

This is just a code cleanup, the constants are way smaller than 32
today. The assert being too restrictive makes no functional difference.

> Align this check with the approach used in tsinfo for
> consistency and correctness.

First-principles based explanation of why 32 is the correct value would
be much better than just alignment. Otherwise reviewer has to figure out
whether we should be changing from >= to > or vice versa...

> Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
> Fixes: 6e9e2eed4f39 ("net: ethtool: Add support for tsconfig command to get/set hwtstamp config")
-- 
pw-bot: cr
Re: [PATCH net 2/3] net: ethtool: tsconfig: Fix ts filters and types enums size check
Posted by Kory Maincent 1 year ago
On Wed, 29 Jan 2025 16:45:08 -0800
Jakub Kicinski <kuba@kernel.org> wrote:

> On Tue, 28 Jan 2025 16:35:47 +0100 Kory Maincent wrote:
> > Fix the size check for the hwtstamp_tx_types and hwtstamp_rx_filters
> > enumerations.  
> 
> This is just a code cleanup, the constants are way smaller than 32
> today. The assert being too restrictive makes no functional difference.

That's right, it was mainly for consistency with the other assert. And to avoid
possible future mistake but indeed reaching 32 bit is not expected soon. Should
I remove the patch as it is not a functional issue?

> > Align this check with the approach used in tsinfo for
> > consistency and correctness.  
> 
> First-principles based explanation of why 32 is the correct value would
> be much better than just alignment. Otherwise reviewer has to figure out
> whether we should be changing from >= to > or vice versa...

Ack, I will if I keep the patch.

Regards,
-- 
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
Re: [PATCH net 2/3] net: ethtool: tsconfig: Fix ts filters and types enums size check
Posted by Jakub Kicinski 1 year ago
On Thu, 30 Jan 2025 10:24:51 +0100 Kory Maincent wrote:
> > This is just a code cleanup, the constants are way smaller than 32
> > today. The assert being too restrictive makes no functional difference.  
> 
> That's right, it was mainly for consistency with the other assert. And to avoid
> possible future mistake but indeed reaching 32 bit is not expected soon. Should
> I remove the patch as it is not a functional issue?

Yes, drop it please and repost after net-next re-opens.