]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
crypto: qat - avoid division by zero
authorAdam Guerin <adam.guerin@intel.com>
Fri, 16 Feb 2024 15:19:57 +0000 (15:19 +0000)
committerHerbert Xu <herbert@gondor.apana.org.au>
Sat, 24 Feb 2024 00:41:20 +0000 (08:41 +0800)
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: e2980ba57e79 ("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>
drivers/crypto/intel/qat/qat_common/adf_clock.c

index 01e0a389e462b027cefb1d5d658029297b5104b4..cf89f57de2a7021494faefc006ca4c4eda038e2b 100644 (file)
@@ -83,6 +83,9 @@ static int measure_clock(struct adf_accel_dev *accel_dev, u32 *frequency)
        }
 
        delta_us = timespec_to_us(&ts3) - timespec_to_us(&ts1);
+       if (!delta_us)
+               return -EINVAL;
+
        temp = (timestamp2 - timestamp1) * ME_CLK_DIVIDER * 10;
        temp = DIV_ROUND_CLOSEST_ULL(temp, delta_us);
        /*