]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
accel/qaic: Use overflow check function instead of division
authorCarl Vanderlip <quic_carlv@quicinc.com>
Tue, 7 Oct 2025 17:42:18 +0000 (19:42 +0200)
committerJeff Hugo <jeff.hugo@oss.qualcomm.com>
Tue, 14 Oct 2025 15:52:24 +0000 (09:52 -0600)
Division is an expensive operation. Overflow check functions exist
already. Use existing overflow check functions rather than dividing to
check for overflow.

Signed-off-by: Carl Vanderlip <quic_carlv@quicinc.com>
Signed-off-by: Youssef Samir <youssef.abdulrahman@oss.qualcomm.com>
Reviewed-by: Jeff Hugo <jeff.hugo@oss.qualcomm.com>
Reviewed-by: Carl Vanderlip <carl.vanderlip@oss.qualcomm.com>
Signed-off-by: Jeff Hugo <jeff.hugo@oss.qualcomm.com>
Link: https://lore.kernel.org/r/20251007174218.469867-1-youssef.abdulrahman@oss.qualcomm.com
drivers/accel/qaic/qaic_control.c
drivers/accel/qaic/qaic_data.c

index 7566c6efffa293354bf4bb3efe87fdb9052ddb3e..82b38b9b81f723b74eab171a7a2e186605f04cf8 100644 (file)
@@ -656,8 +656,9 @@ static int encode_activate(struct qaic_device *qdev, void *trans, struct wrapper
                return -EINVAL;
 
        nelem = in_trans->queue_size;
-       size = (get_dbc_req_elem_size() + get_dbc_rsp_elem_size()) * nelem;
-       if (size / nelem != get_dbc_req_elem_size() + get_dbc_rsp_elem_size())
+       if (check_mul_overflow((u32)(get_dbc_req_elem_size() + get_dbc_rsp_elem_size()),
+                              nelem,
+                              &size))
                return -EINVAL;
 
        if (size + QAIC_DBC_Q_GAP + QAIC_DBC_Q_BUF_ALIGN < size)
index 42feb7509ca9d76c28f284c90a6bba032d04cdca..45f065488fdb4185333616f1f15fa800175976fd 100644 (file)
@@ -982,8 +982,9 @@ int qaic_attach_slice_bo_ioctl(struct drm_device *dev, void *data, struct drm_fi
        if (args->hdr.count == 0)
                return -EINVAL;
 
-       arg_size = args->hdr.count * sizeof(*slice_ent);
-       if (arg_size / args->hdr.count != sizeof(*slice_ent))
+       if (check_mul_overflow((unsigned long)args->hdr.count,
+                              (unsigned long)sizeof(*slice_ent),
+                              &arg_size))
                return -EINVAL;
 
        if (!(args->hdr.dir == DMA_TO_DEVICE || args->hdr.dir == DMA_FROM_DEVICE))