Patchwork [dpdk-dev,36/38] net/sfc/base: avoid division by 0 if no event queue timers

login
register
mail settings
Submitter Andrew Rybchenko
Date Feb. 7, 2019, 4:29 p.m.
Message ID <1549556983-10896-37-git-send-email-arybchenko@solarflare.com>
Download mbox | patch
Permalink /patch/720883/
State New
Headers show

Comments

Andrew Rybchenko - Feb. 7, 2019, 4:29 p.m.
If event queue timers are not supported, enc_evq_timer_quantum_ns and
enc_evq_timer_max_us should be set to 0. Make sure that division by 0
does not happen in libefx, if public function efx_ev_usecs_to_ticks()
is used in this case.

Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
---
 drivers/net/sfc/base/efx_ev.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Patch

diff --git a/drivers/net/sfc/base/efx_ev.c b/drivers/net/sfc/base/efx_ev.c
index 69224cbc5..7b5130291 100644
--- a/drivers/net/sfc/base/efx_ev.c
+++ b/drivers/net/sfc/base/efx_ev.c
@@ -566,6 +566,12 @@  efx_ev_usecs_to_ticks(
 {
 	efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
 	unsigned int ticks;
+	efx_rc_t rc;
+
+	if (encp->enc_evq_timer_quantum_ns == 0) {
+		rc = ENOTSUP;
+		goto fail1;
+	}
 
 	/* Convert microseconds to a timer tick count */
 	if (us == 0)
@@ -577,6 +583,10 @@  efx_ev_usecs_to_ticks(
 
 	*ticksp = ticks;
 	return (0);
+
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+	return (rc);
 }
 
 	__checkReturn	efx_rc_t