diff mbox series

[v2,net-next,5/9] net: ethtool: mm: sanitize some UAPI configurations

Message ID 20230418111459.811553-6-vladimir.oltean@nxp.com (mailing list archive)
State Accepted
Commit 35b288d6e3d467f6f7bf466fee6184b275999f14
Delegated to: Netdev Maintainers
Headers show
Series ethtool mm API consolidation | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 20 this patch: 20
netdev/cc_maintainers warning 2 maintainers not CCed: fejes@inf.elte.hu simon.horman@corigine.com
netdev/build_clang success Errors and warnings before: 18 this patch: 18
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 20 this patch: 20
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 16 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Vladimir Oltean April 18, 2023, 11:14 a.m. UTC
The verify-enabled boolean (ETHTOOL_A_MM_VERIFY_ENABLED) was intended to
be a sub-setting of tx-enabled (ETHTOOL_A_MM_TX_ENABLED). IOW, MAC Merge
TX can be enabled with or without verification, but verification with TX
disabled makes no sense.

The pmac-enabled boolean (ETHTOOL_A_MM_PMAC_ENABLED) was intended to be
a global toggle from an API perspective, whereas tx-enabled just handles
the TX direction. IOW, the pMAC can be enabled with or without TX, but
it doesn't make sense to enable TX if the pMAC is not enabled.

Add two checks which sanitize and reject these invalid cases.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
v1->v2: add missing "Verification requires TX enabled" check which was
        only mentioned in the commit message

 net/ethtool/mm.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Simon Horman April 20, 2023, 2:43 p.m. UTC | #1
On Tue, Apr 18, 2023 at 02:14:55PM +0300, Vladimir Oltean wrote:
> The verify-enabled boolean (ETHTOOL_A_MM_VERIFY_ENABLED) was intended to
> be a sub-setting of tx-enabled (ETHTOOL_A_MM_TX_ENABLED). IOW, MAC Merge
> TX can be enabled with or without verification, but verification with TX
> disabled makes no sense.
> 
> The pmac-enabled boolean (ETHTOOL_A_MM_PMAC_ENABLED) was intended to be
> a global toggle from an API perspective, whereas tx-enabled just handles
> the TX direction. IOW, the pMAC can be enabled with or without TX, but
> it doesn't make sense to enable TX if the pMAC is not enabled.
> 
> Add two checks which sanitize and reject these invalid cases.
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Simon Horman <simon.horman@corigine.com>
diff mbox series

Patch

diff --git a/net/ethtool/mm.c b/net/ethtool/mm.c
index e00d7d5cea7e..4058a557b5a4 100644
--- a/net/ethtool/mm.c
+++ b/net/ethtool/mm.c
@@ -214,6 +214,16 @@  static int ethnl_set_mm(struct ethnl_req_info *req_info, struct genl_info *info)
 		return -ERANGE;
 	}
 
+	if (cfg.verify_enabled && !cfg.tx_enabled) {
+		NL_SET_ERR_MSG(extack, "Verification requires TX enabled");
+		return -EINVAL;
+	}
+
+	if (cfg.tx_enabled && !cfg.pmac_enabled) {
+		NL_SET_ERR_MSG(extack, "TX enabled requires pMAC enabled");
+		return -EINVAL;
+	}
+
 	ret = dev->ethtool_ops->set_mm(dev, &cfg, extack);
 	return ret < 0 ? ret : 1;
 }