From 61fd24c5525f4801b35d240c9d792108e078b935 Mon Sep 17 00:00:00 2001 From: Ahmed Hesham Date: Tue, 19 Aug 2025 16:04:22 +0100 Subject: [PATCH] rusticl: Fix negative CTS device tests `clRetainDevice` and `clReleaseDevice` ignore the device argument, it should be checked for validity and return `CL_INVALID_DEVICE` if it fails. `check_cl_device_type` fails if entrypoint is passed `0` as the device type. Zero as an input for a bitwise and operation will always result in a zero, so the utility function fails to return `CL_INVALID_DEVICE_TYPE`. Signed-off-by: Ahmed Hesham Part-of: --- src/gallium/frontends/rusticl/api/device.rs | 6 ++++-- src/gallium/frontends/rusticl/api/util.rs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/gallium/frontends/rusticl/api/device.rs b/src/gallium/frontends/rusticl/api/device.rs index e603859ff67..d323e9a1357 100644 --- a/src/gallium/frontends/rusticl/api/device.rs +++ b/src/gallium/frontends/rusticl/api/device.rs @@ -393,12 +393,14 @@ fn get_device_ids( } #[cl_entrypoint(clRetainDevice)] -fn retain_device(_device: cl_device_id) -> CLResult<()> { +fn retain_device(device: cl_device_id) -> CLResult<()> { + let _ = Device::ref_from_raw(device)?; Ok(()) } #[cl_entrypoint(clReleaseDevice)] -fn release_device(_device: cl_device_id) -> CLResult<()> { +fn release_device(device: cl_device_id) -> CLResult<()> { + let _ = Device::ref_from_raw(device)?; Ok(()) } diff --git a/src/gallium/frontends/rusticl/api/util.rs b/src/gallium/frontends/rusticl/api/util.rs index 7243d1a6dd4..fe8c2c91e61 100644 --- a/src/gallium/frontends/rusticl/api/util.rs +++ b/src/gallium/frontends/rusticl/api/util.rs @@ -440,7 +440,7 @@ const CL_DEVICE_TYPES: u32 = CL_DEVICE_TYPE_ACCELERATOR pub fn check_cl_device_type(val: cl_device_type) -> CLResult<()> { let v: u32 = val.try_into().or(Err(CL_INVALID_DEVICE_TYPE))?; - if v == CL_DEVICE_TYPE_ALL || v & CL_DEVICE_TYPES == v { + if v != 0 && (v == CL_DEVICE_TYPE_ALL || v & CL_DEVICE_TYPES == v) { return Ok(()); } Err(CL_INVALID_DEVICE_TYPE)