Skip to content

Commit f99fb7d

Browse files
aguerinIntelherbertx
authored andcommitted
crypto: qat - avoid division by zero
Check if delta_us is not zero and return -EINVAL if it is. delta_us is unlikely to be zero as there is a sleep between the reads of the two timestamps. This is to fix the following warning when compiling the QAT driver using clang scan-build: drivers/crypto/intel/qat/qat_common/adf_clock.c:87:9: warning: Division by zero [core.DivideZero] 87 | temp = DIV_ROUND_CLOSEST_ULL(temp, delta_us); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Fixes: e2980ba ("crypto: qat - add measure clock frequency") Signed-off-by: Adam Guerin <adam.guerin@intel.com> Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 9a5dcad commit f99fb7d

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

drivers/crypto/intel/qat/qat_common/adf_clock.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ static int measure_clock(struct adf_accel_dev *accel_dev, u32 *frequency)
8383
}
8484

8585
delta_us = timespec_to_us(&ts3) - timespec_to_us(&ts1);
86+
if (!delta_us)
87+
return -EINVAL;
88+
8689
temp = (timestamp2 - timestamp1) * ME_CLK_DIVIDER * 10;
8790
temp = DIV_ROUND_CLOSEST_ULL(temp, delta_us);
8891
/*

0 commit comments

Comments
 (0)