[RFC,v2,2/3] ethdev: check that at least one FEC mode is specified

Message ID 20230508114707.89629-3-denis.pryazhennikov@arknetworks.am (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series improve FEC API usage |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Denis Pryazhennikov May 8, 2023, 11:47 a.m. UTC
  The behaviour is undefined in the rte_eth_fec_set() function
when the fec_capa parameter is equal to zero.
Add a check to handle this case.

Signed-off-by: Denis Pryazhennikov <denis.pryazhennikov@arknetworks.am>
Acked-by: Ivan Malov <ivan.malov@arknetworks.am>
Acked-by: Viacheslav Galaktionov <viacheslav.galaktionov@arknetworks.am>
---
 lib/ethdev/rte_ethdev.c | 5 +++++
 1 file changed, 5 insertions(+)
  

Patch

diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index 4d0325568322..d02ee161cf6d 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -4751,6 +4751,11 @@  rte_eth_fec_set(uint16_t port_id, uint32_t fec_capa)
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
 
+	if (fec_capa == 0) {
+		RTE_ETHDEV_LOG(ERR, "At least one FEC mode should be specified\n");
+		return -EINVAL;
+	}
+
 	if (*dev->dev_ops->fec_set == NULL)
 		return -ENOTSUP;
 	ret = eth_err(port_id, (*dev->dev_ops->fec_set)(dev, fec_capa));